Repository navigation
perf(three): update retained meshes faster than React Three Fiber again - #1665
Merged
Merged
Conversation
Fixing the commits leak (#1653) took update_1k from 0.77x to parity with React Three Fiber. The leak had been keeping old host batches alive, and with them the hidden classes Object.freeze gives batches and commands. V8 reaches those classes only through weak transitions. Once no batch survived the runner's forced gc(), they were collected, and every optimized reader of a command deoptimized ("embedded weak objects cleared") and re-warmed inside the timed run. - Pin one frozen exemplar of the batch and of each common command on the universal root class, so their classes survive a full collection. - Move the per-leaf bodies of the compact-leaf update path and the Three update-only driver into functions called per item. Their loops run once per commit and stay in Maglev; the per-item functions reach TurboFan. - Derive, compare, and freeze each compact leaf in one pass, and freeze each command as it is emitted. - Add tests that break exactly one update-only or compact-pairing guard each. - Restore the update_1k guard to 1.0. Co-Authored-By: Claude Opus 5.5 <[email protected]>
trueadm
marked this pull request as ready for review
October 3, 2026 11:12
Contributor
Benchmark report🟢 No budget breaches, no added work, and no timing changes beyond ±3%. Compares js-framework: 1k/10k row operations
All 20 timed operations (19 without a verdict)
All 64 work counters are unchanged. Application bundle size (bytes)
50 other measured values are unchanged. Public-import reachability bundles (bytes)No changes across 105 measured values. |
|
The latest updates on your projects. Learn more about Vercel for GitHub. 2 Skipped Deployments
|
7 of 8 tasks
Co-Authored-By: Claude Opus 5.5 <[email protected]>
Merged
5 of 6 tasks
trueadm
added a commit
that referenced
this pull request
Oct 3, 2026
Main gained #1685, which raised 51 budgets for the useLayoutSnapshot commit-phase priority fix (#1686), and #1681/#1665. Re-measured on main 425a32a: each of #1663, #1664 and #1666 merged alone, and all three plus #1686 merged together. Each budget is the larger of main's value and the largest measured value plus 32 (raw/gzip) or 256 (brotli), so the three perf PRs and #1686 can land in any order. Co-Authored-By: Claude Opus 5.5 <[email protected]>
trueadm
added a commit
that referenced
this pull request
Oct 3, 2026
…nd warm-plan perf PRs (#1687) Three open runtime perf pull requests fail the PR bench byte gate on main 12c32ec, and landing any two of them stacks past the 32-byte headroom: - #1664 (de-opt survivor fast path): +809 raw / +290 gzip in the bindings app framework chunk, which #1676 did not raise because #1639 added that budget key first; +20 raw in every compiled-only app. - #1666 (warm-plan length guard): +17 raw in every client bundle, two `!==` guards. - #1663 (scoped-value read-once): +2 raw / +30-70 gzip in descriptor-renderer bundles, a compression shift from the restructured childSlot reads. Main had already spent part of the headroom: bindings framework gzip measured exactly its budget and deferred-hydration raw had 8 bytes left. Each budget is set to the largest value measured across each PR merged alone with main and all of them merged together (plus #1665, which moves none of these values), plus 32 for raw and gzip and 256 for brotli. Only values one of those trees exceeds change. Co-authored-by: Claude Opus 5.5 <[email protected]>
This was referenced Oct 4, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Three's
update_1k(1,000 in-place mesh position updates) is faster than React Three Fiber again: 0.72×–0.81× R3F across threebench.mjs --ratios three-rendererruns, up from about parity. The guard goes back from 1.05 to 1.0.Why #1653's leak made updates 25% faster. It wasn't heap layout.
Object.freezegives each frozen batch and command its own hidden class. V8 reaches that class from the unfrozen one only through a weak transition.gc(), those classes are collected.--trace-deopt"bailout" lines. They show as "marking dependent code … for deoptimization".Changes
universal-core.ts). One frozen exemplar of the batch and of each common command (update, create/recreate, insert/move, remove, destroy) is held by a static field on the universal root class, so the classes survive a full collection. Each literal must keep the property order the commit paths emit; a comment says so. The minified bundle keeps the static.compactLeafCommandandisCompactLeafRecordin core;isDirectMeshUpdateandapplyDirectMeshUpdatein the Three driver). Each update runs these loops once, so they stay in Maglev. Their per-item bodies, called 1,000 times, reach TurboFan.scene.children[index]is still read per command), andupdates.classifystill runs only after pairing succeeds.Measurements (local, Chromium 149)
bench.mjs --ratios three-renderer, beforerun.mjs's op order and warmups: base / restructure only / restructure + pinningAll eight
three-rendererguards pass on current main. The other runtime ops are unchanged within noise.Validation
pnpm format:check: not run repo-wide;pnpm format:files:checkon every changed file passespnpm typecheck: not run repo-wide;pnpm typecheck:fileson the changed sources and the driver test passespnpm test: not run in full; CI runs itthreeproject:driver,root,testing,hooks(58 passed)octaneproject:universal-renderer,universal-host-sdk,universal-event-scope,universal-host-bindings,universal-native,universal-activity(241 passed)node benchmarks/bench.mjs --ratios three-renderer three-bundle-size: PASSpnpm syncis clean;pnpm react-parity:validateis currentNew tests. The existing tests broke two update-only guards at once, so removing any single guard went unnoticed.
fromArray, props-shape, id, name-write, key, type or children check, or any of the freezes, fails a test.parent, name-writability or record-owner checks with a different outcome. They are kept verbatim.Risk / follow-ups
update_1kguard is what catches it.Provenance
agent-authored)🤖 Generated with Claude Code
Need help on this PR? Tag
@codesmith-botwith what you need. Autofix is disabled.Note
Medium Risk
Touches the universal commit fast path and Three driver batch application; behavior is intended to be identical but regressions would affect all renderers using frozen host batches, not only the benchmark.
Overview
Restores Three
update_1kperformance to roughly 0.72–0.81× React Three Fiber (from ~parity) by tuning the universal compact-list commit path and the Three driver’s update-only batch, without changing observable behavior. The benchmark guardmaxRatiodrops from 1.05 to 1.0.Universal core pins frozen exemplars of host batches and common commands on
UniversalRootImplso V8 hidden classes and optimized readers survive a full GC after transient batches are collected. Compact keyed leaf updates move per-leaf derive/compare/classify/freeze intocompactLeafCommandandisCompactLeafRecord, merging the old two-pass walk into one and freezing each command as it’s emitted viafreezeUniversalHostBatchShell.Three driver splits the update-only fast path into
isDirectMeshUpdateandapplyDirectMeshUpdateso per-command validation and mesh position/name writes stay in engine-hot functions.Adds compact-list tests in
universal-renderer.test.tsand retained root mesh driver tests that each guard a single check on the fast path. Changeset documents the patch foroctaneand@octanejs/three.Reviewed by Cursor Bugbot for commit baa407f. Bugbot is set up for automated code reviews on this repo. Configure here.