Repository navigation
perf(compiler): transitive @if-arm single-root proof elides static multi-hole host markers - #676
Merged
Merged
Conversation
…e host markers
A component whose @{} body is an @if/@else tree where every reachable arm
renders exactly one plain host or one qualifying same-module component call
is now proven single-root through a fixed point, so its call sites take the
existing anchorless componentSlot singleRoot regime instead of minting a
comp//comp pair per slot. Client-mount elision only: SSR emission and
hydration adoption are unchanged.
spa-navigation 1024-leaf route census: 4,093 -> 1 comment (elements/text
exactly equal to React); nav_mount 1.80 -> 1.00 ms, nav_deep 3.10 -> 1.70 ms
same-session. Census now emitted as deterministic *_deep ops with five ratio
guards; behavioral coverage in component-children-host.test.ts and
hydration/component-children-hydrate.test.ts.
Co-Authored-By: Claude Fable 5 <[email protected]>
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes using default effort and found 1 potential issue.
Bugbot Autofix prepared a fix for the issue found in the latest run.
- ✅ Fixed: Arm-local shadows break single-root proof
- Extended armOk in collectSingleRootIfDeps to collect VariableDeclaration and FunctionDeclaration bindings from each arm's statements into an extended locals set, so arm-level shadows of module-level components are properly rejected by the existing locals.has(name) guard in singleRootComponentArmName.
Or push these changes by commenting:
@cursor push 0643242216
Preview (0643242216)
diff --git a/packages/octane/src/compiler/compile.js b/packages/octane/src/compiler/compile.js
--- a/packages/octane/src/compiler/compile.js
+++ b/packages/octane/src/compiler/compile.js
@@ -5005,12 +5005,25 @@
const deps = new Set();
const armOk = (arm) => {
if (isIfDirective(arm)) return ifOk(arm);
- const out = statementsOf(arm).filter((s) => isJsxNode(s) || isIfDirective(s));
+ const all = statementsOf(arm);
+ const out = all.filter((s) => isJsxNode(s) || isIfDirective(s));
if (out.length !== 1) return false;
const sole = out[0];
if (isIfDirective(sole)) return ifOk(sole);
if (isPlainHostRoot(sole)) return true;
- const name = singleRootComponentArmName(sole, locals, ctx);
+ let armLocals = locals;
+ for (const s of all) {
+ if (s.type === 'VariableDeclaration') {
+ for (const d of s.declarations || []) {
+ if (armLocals === locals) armLocals = new Set(locals);
+ collectBindings(d.id, armLocals);
+ }
+ } else if (s.type === 'FunctionDeclaration' && s.id) {
+ if (armLocals === locals) armLocals = new Set(locals);
+ armLocals.add(s.id.name);
+ }
+ }
+ const name = singleRootComponentArmName(sole, armLocals, ctx);
if (name === null) return false;
deps.add(name);
return true;You can send follow-ups to the cloud agent here.
Reviewed by Cursor Bugbot for commit 16c62f2. Configure here.
…m/octanejs/octane into perf/multihole-singleroot-elision
|
The latest updates on your projects. Learn more about Vercel for GitHub. 2 Skipped Deployments
|
…root-elision # Conflicts: # benchmarks/baselines/ratios.json # packages/octane/src/compiler/compile.js # packages/octane/tests/_fixtures/component-children-host.tsrx # packages/octane/tests/component-children-host.test.ts
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
Finding 3 from the 2026-08-09 spa-navigation performance audit: static multi-hole hosts —
<div class="n"><Node/><Node/></div>, two static component children of one host — minted a<!--comp-->/<!--/comp-->pair per child slot. On the bench's 1024-leaf route mount that was 4,092 comment nodes against 3,071 content nodes and ~2/3 of allinsertBeforecalls (React and Solid insert zero and 2,046 comments respectively).The compiler already emits anchorless slots for a host whose children are all components, and the runtime's
componentSlotsingleRoot regime already self-marks on the rendered element — the only reason the bench shape missed both is that the definition-site single-root proof (singleHostComponentRoot) required a plain host root, soNode(an@ifwhose@elsearm is<Leaf/>) never qualified. This PR widens that proof transitively and changes nothing else:collectSingleRootIfDeps(compile.js): a void@{}body whose sole root is an@if/@elsetree, where every reachable arm renders exactly one plain host or one qualifying same-module component call (bare identifier tag, no key/spread/children, no local shadow), contributes its arm callees as proof dependencies.info.singleRootfalse → true until stable, so declaration order and recursion through a proven base case don't matter; unproven cycles and every decline case (fragment/member/dynamic tags, keyed/spread/children arms, missing@else, imported callees) keep the marker pair.$$singleRootstamps (which extend the win to cross-module2-sentinel call sites), and the@foritem proof consume the widened result through their existing channels. SSR emission and hydration adoption are byte-identical — this is a client-mount elision in the M1/M2/M4 tradition, so server/client symmetry holds by construction.Measured effect (same-session before/after,
node benchmarks/bench.mjs spa-navigation)Deterministic census of the 1024-leaf route: octane-tsrx 4,093 → 1 comment node (react 0 / solid 2,046), with the semantic control exact — 2,052 elements and 1,025 text nodes, identical to React, and all
work.mjscall-count gates unchanged. The census is now emitted as deterministic*_deepops with five new ratio guards inbaselines/ratios.json(semantic controls pinned 1:1; octane-tsrx comments capped at 0.01× solid; total nodes at 1.005× react; the JSX dialect's de-opt line held at 4.05× solid).Timings moved with the node count (medians; competitors re-measured in the same runs, so the ratios are the honest signal; both runs predate merging #670):
nav_mountnav_deepnav_teardownnav_deep_6xTeardown improves because 4,092 fewer nodes exist to detach. The branch has since merged
origin/main(bringing in #670's wholesale unmount detach and #672); the full-precision post-merge run holds up — census still 1 comment with all guards passing,nav_teardown0.90 ms tying Solid's 0.90,nav_deep2.20 vs Solid 2.80 (0.79x),nav_mount1.50 vs Solid 2.00 (0.75x), andnav_deep_6x14.70 now ahead of React's 16.50. js-framework and hydration-stress re-ran before/after as controls (results in the Validation section).Validation
pnpm format:check(scopedformat:files:checkon every touched file; repo-wide check in CI)pnpm typecheckpnpm test— 17,354 tests / 1,612 files pre-merge, and again on the merged tree (now including perf(runtime): wholesale unmount DOM detach + gated de-opt ref walk #670, feat: add behavior-only roots and external DOM ownership #671, fix: direct plain-function component calls crashing in dev compile #672): 17,486 tests, all passing (octane + octane-prod projects, incoming regression tests included)component-children-host.test.ts(11 cases × dev/prod: source order, sibling identity across arm flips, state survival, keyed remount control, transition flip, Suspense fall-back/resolve, teardown-empty, and negative shapes that must keep their pairs) andhydration/component-children-hydrate.test.ts(3 cases × dev/prod: adoption identity, live handlers, post-hydration flips and client-side tree growth inside adopted DOM)spa-navigationbefore/after with deterministic work gates + the five new census ratio guards (all pass)js-frameworkandhydration-stressbefore/after as controls: every deterministic counter byte-identical (production_calls_1k24,048,live_inserts_*exact),runvs solid 0.97x before and after (a 1.42x reading in one interim run did not reproduce), hydration UX gates PASS 5/5 withhydration_workflat;--ratiosre-runs report no guard breachesReachability of the new regime was probe-verified (a temporary throw in the markerless branch-mount path failed 8/9 new tests, then was removed); the order/identity oracles demonstrably bite — they caught a real pre-existing bug on first contact (below).
Risk / follow-ups
renderBranchSlotbehavior) — navigations pay zero markers; flip-heavy trees converge to the old steady-state count.@switch-root bodies, optimistic self-recursive arms, and definition-site stamps conditioned on imported callees'$$singleRoot.docs/comment-marker-elision-plan.mdgained an M7 section recording the proof, measurements, and declines.Provenance
agent-authored)Note
Medium Risk
Touches core compile-time output-shape proof that drives client DOM boundaries; incorrect widening could break sibling order, but declines stay conservative and coverage is broad with no runtime changes.
Overview
Extends the compiler’s single-root proof so components whose sole body root is an
@if/@elsetree can qualify when every arm renders one plain host or one qualifying same-module component call.collectSingleRootIfDepsrecords callee dependencies; a fixed-point pass (same pattern as autoMemo) setsinfo.singleRootonce dependencies are proven, so shapes like<div><Node/><Node/></div>reuse the existing anchorless componentSlot path instead of minting<!--comp-->/<!--/comp-->per child. Compiler-only — SSR and hydration are unchanged; client-mount marker elision only.The spa-navigation harness now emits deterministic
*_deepDOM census ops with new ratio guards (elements/text pinned to React; comment count capped vs Solid). Tests cover sibling order, identity across arm flips, keyed remount, transitions, Suspense, fragment/empty negative shapes, and SSR hydration adoption plus post-hydrate growth. M7 is documented incomment-marker-elision-plan.md.Reviewed by Cursor Bugbot for commit 765e52e. Bugbot is set up for automated code reviews on this repo. Configure here.