Repository navigation
perf(runtime): wholesale unmount DOM detach + gated de-opt ref walk - #670
Merged
Merged
Conversation
A deleted subtree's DOM is now removed once at the outermost detached block instead of per-descendant marker range (6,140 removeChild -> ~3 on a 1024-leaf route teardown), and detachDeoptTreeRefs is skipped for subtrees that never stamped a descriptor ref. Deletion cleanups now observe the whole deleted subtree still attached, matching React's commitDeletionEffects order. spa-navigation nav_teardown 1.20 -> 0.60ms (ties solid), nav_deep_6x 14.80 -> 11.20ms; work counters unchanged. Co-Authored-By: Claude Fable 5 <[email protected]>
trueadm
marked this pull request as ready for review
August 9, 2026 21:28
This was referenced Aug 9, 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
detachDeoptTreeRefs) is now gated on refs actually existing: stamping a descriptorrefsets a monotone flag on the owner block and itsparentBlockchain (plus a module-level "ever stamped" flag), and teardown/hide walks skip the per-DOM-node descriptor scan when clear.Why
The new spa-navigation suite (#614) showed teardown is where Octane loses on full-page navigations. Profiling the production fixtures:
removeChildcalls (tsrx) / 8,186 (jsx); React does 1, Solid does 1replaceChild. RawremoveChildalone was 21% of the tsrx navigation profile.detachDeoptTreeRefswas 20.4% of the octane-jsx profile (~1ms per teardown) in a tree containing zero refs — it walks every DOM node of each block'sdeoptNodesubtree (nested blocks re-walk the same DOM, so it is O(nodes x depth)).Both fixes also move deletion semantics closer to React: every deletion cleanup now observes the entire deleted subtree still attached (React's
commitDeletionEffectsruns all destroys before detaching the single host). Previously a later sibling's cleanup saw an earlier sibling's DOM already removed.Changes
unmountBlockInner: computeremovesOwnDom(this call will remove the block's own range or clear the root container) and recurse withdetachDom=falsein that case, so only the outermost detaching block touches the DOM. The existingdetachDom=falsecontract (batchClearItems,clearChildContent, parked blocks) is unchanged, as is the forced self-detach forportalSlotSlotand hidden-try content.Block.deoptRefs(new monomorphic boolean field) +noteDeoptRefcalled fromapplyDeoptProp's ref branch (covers fresh apply, reuse/diff re-attach, and hydration adoption). Gates thedeoptNodewalks inunmountBlockInnerandbatchClearItems; a module-levelDEOPT_REFS_STAMPEDflag short-circuitsdetachDeoptTreeRefsitself for every other call site (clearChildContent sweeps, suspense hide/reveal collection, hydration recovery).Benchmarks (same machine, same day, 20 iterations, medians in ms)
node benchmarks/bench.mjs spa-navigation— baseline was main earlier the same day; candidate ran twice (a concurrent-load run and a clean run; clean run shown, sd 0.05–0.10 on the sub-ms ops):nav_teardownhalves and now ties Solid (was 2.24x);nav_deepedges past Solid andnav_deep_6x(the mobile signal) is now clearly ahead of it.nav_mountis unchanged — expected, the mount path is untouched, which is itself evidence the deltas are the teardown mechanism and not noise. The deterministic work counters (work.mjs) are byte-identical to baseline — renderBlock/unmountBlock/unmountScope counts unchanged — so the semantic work is proven equal; only DOM calls and the ref walk were removed. All semantic gates (shell/layout survival by node identity) and work gates pass. list-clear and effectful-list (the other teardown-heavy suites) ran without anomaly; their clear paths already used the batched contract this change extends.Validation
pnpm test— 1,610 files / 17,249 tests pass (includes the octane-prod project)pnpm typecheckpnpm format:files:checkon changed filesunmount-detach.test.ts(deletion cleanups observe the whole subtree attached — failed before the fix:second cleanup sees first=false), newdeopt-suspense-ref.test.ts(hide/reveal detach/re-attach across the gated walk),deopt-host-ref.test.tsextended with an update-added-ref case — 32/36 of these fail if the gate is deliberately broken (verified), plus portal, ref-cleanup/dispose, suspense-ref-regressions, effect-ordering-deletion suites.Risk / follow-ups
deoptRefsis monotone; a region that once had a ref keeps paying the (previous) walk cost. Finer invalidation was not worth the bookkeeping..tsxdialect lowering gaps (multi-return bodies de-opt; single-return components keep the generic descriptor ABI).Provenance
agent-authored)🤖 Generated with Claude Code
Note
Medium Risk
Changes core unmount/teardown in the runtime: DOM removal order and what deletion cleanups can observe now match React, which can affect MutationObserver users and any code that assumed per-block incremental detach.
Overview
Teardown now strips a deleted subtree's DOM in one pass at the outermost block that owns the marker range (
removesOwnDominunmountBlockInner), instead of every descendant block callingremoveChildon its own slice. Descendant unmounts run withdetachDom=falsein that case so layout/deletion cleanups still see sibling DOM connected until the parent removes the range — matching React'scommitDeletionEffects(destroys before a single host detach). Portals keep self-detaching from foreign targets.De-opt ref teardown is gated: stamping a descriptor
refsets monotoneBlock.deoptRefsup theparentBlockchain and a moduleDEOPT_REFS_STAMPEDflag;detachDeoptTreeRefsand related walks inunmountBlockInner/batchClearItemsskip the per-DOM-node scan when a subtree never had refs.Adds regression tests for deletion cleanup observation (
unmount-detach), suspense hide/reveal on de-opt refs (deopt-suspense-ref), and refs added on a later update (deopt-host-ref).Reviewed by Cursor Bugbot for commit 3197f02. Bugbot is set up for automated code reviews on this repo. Configure here.