Repository navigation
fix(three): stop retaining every committed host batch on application roots - #1653
Merged
Merged
Conversation
…roots Every root created by createRoot, Canvas, or the testing harness appended each accepted host batch to container.commits and never released it, because recordCommits defaulted on and root.ts never turned it off. A long-lived scene kept every replaced props object, listener value, and destroy record. The Three bench retained about 170 KB per 1,000-node remount. Application roots now set recordCommits: false; a container created directly keeps the documented default. The update_1k guard ratchets to 1.05. The leak flattered it: keeping the previous mount batch alive across the runner's forced gc() made the next update about 25% faster (0.77x R3F). Without that history it measures 0.989x-1.000x. Co-Authored-By: Claude Opus 5.5 <[email protected]>
trueadm
marked this pull request as ready for review
October 3, 2026 09:24
Contributor
Benchmark report🟢 No size increases and no timing regressions outside noise. Compares js-framework: 1k/10k row operations (ms, lower is better)All 20 timed operations (20 within noise)
Application bundle size (bytes)No changes across 45 measured values. Public-import reachability bundles (bytes)No changes across 105 measured values. |
4 of 7 tasks
trueadm
added a commit
that referenced
this pull request
Oct 3, 2026
…in (#1665) 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]>
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
Every
@octanejs/threeroot created bycreateRoot,Canvas, or the@octanejs/three/testingharness leaked its commit history.container.commitsand never released.ThreeHostEnvironment.recordCommitsdefaults on, androot.tsnever turned it off.driverState.commits.Application roots now set
recordCommits: false. A container created directly withcreateThreeContainerkeeps the documented recording default, which the low-level driver tests use.The
update_1kguard ratchets to 1.05. The leak had been flattering it.gc()made the next 1,000-mesh update about 25% faster: 0.77× R3F with the leak, 0.989–1.000× without.--no-allocation-site-pretenuringleaves the gap), and heap size (a 300k-object ballast makes it slower, not faster).Validation
pnpm format:files:check,pnpm syncclean,pnpm react-parity:validate(hooks.test.ts hash refreshed)pnpm typecheck:fileson the changed sourcespnpm test(not run in full locally; CI runs it)threeprojecttesting.test.tsandhooks.test.ts.hooks.test.tsassertedcommits.length > 0as a proxy for a live root; it now asserts the instance's root scene.Risk / follow-ups
instance.root.commitsis now empty on application roots. Only tests read it, and R3F'sinstance.roothas no equivalent history.update_1kto 1.0.Provenance
agent-authored)🤖 Generated with Claude Code
Need help on this PR? Tag
@codesmith-botwith what you need. Autofix is disabled.Note
Medium Risk
Changes core Three root host behavior and public diagnostic
commitson application roots; benchmark guard is temporarily relaxed until update allocations are reduced.Overview
Fixes a memory leak on long-lived
@octanejs/threescenes: roots fromcreateRoot,Canvas, and the testing harness now setrecordCommits: false, so accepted host batches are no longer appended tocontainer.commitsfor the root’s lifetime. That stops retaining every replaced props object, listener value, and destroy record.createThreeContainerstill records batches by default unless the environment disables it; docs onThreeHostEnvironment.recordCommitsspell out the split.Tests no longer treat non-empty
commitsas proof of a live root (e.g. hooks assertinstance.root.sceneinstead). A new testing regression assertscommitsstays empty after several updates. Theupdate_1kbenchmark ceiling moves 1.0 → 1.05 with a note that the old leak made updates look faster under forcedgc(); follow-up is to trim update-path allocations and restore 1.0.Reviewed by Cursor Bugbot for commit 637d5d0. Bugbot is set up for automated code reviews on this repo. Configure here.