Skip to content

perf(compiler): transitive @if-arm single-root proof elides static multi-hole host markers - #676

Merged
trueadm merged 5 commits into
mainfrom
perf/multihole-singleroot-elision
Aug 10, 2026
Merged

trueadm merged 5 commits into
mainfrom
perf/multihole-singleroot-elision

Conversation

@trueadm

@trueadm trueadm commented Aug 9, 2026 •

Copy link
Copy Markdown
Collaborator

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 all insertBefore calls (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 componentSlot singleRoot 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, so Node (an @if whose @else arm 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/@else tree, 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.
  • A pessimistic fixed point (the same idiom as the autoMemo purity fixpoints directly above it) flips info.singleRoot false → 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.
  • Zero runtime changes. Call sites, the module-tail $$singleRoot stamps (which extend the win to cross-module 2-sentinel call sites), and the @for item 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.mjs call-count gates unchanged. The census is now emitted as deterministic *_deep ops with five new ratio guards in baselines/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):

op octane-tsrx before → after vs solid vs react
nav_mount 1.80 → 1.00 ms 0.78x → 0.67x 1.20x → 0.91x
nav_deep 3.10 → 1.70 ms 1.02x → 0.80x 1.48x → 1.06x
nav_teardown 1.60 → 0.80 ms 1.84x → 1.33x 1.60x → 1.00x
nav_deep_6x 19.20 → 12.20 ms 0.83x → 0.89x 1.32x → 1.09x

Teardown 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_teardown 0.90 ms tying Solid's 0.90, nav_deep 2.20 vs Solid 2.80 (0.79x), nav_mount 1.50 vs Solid 2.00 (0.75x), and nav_deep_6x 14.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 (scoped format:files:check on every touched file; repo-wide check in CI)
  • pnpm typecheck
  • pnpm 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)
  • targeted tests: new 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) and hydration/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-navigation before/after with deterministic work gates + the five new census ratio guards (all pass)
  • js-framework and hydration-stress before/after as controls: every deterministic counter byte-identical (production_calls_1k 24,048, live_inserts_* exact), run vs solid 0.97x before and after (a 1.42x reading in one interim run did not reproduce), hydration UX gates PASS 5/5 with hydration_work flat; --ratios re-runs report no guard breaches

Reachability 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

  • First in-place arm flip under a shared self-marked boundary promotes the slot to one durable minted pair (pre-existing renderBranchSlot behavior) — navigations pay zero markers; flip-heavy trees converge to the old steady-state count.
  • Discovered pre-existing, dev-only bug (not introduced or worsened here; spawned as a follow-up task): a hookless lite child that mounts EMPTY inside an anchorless all-component host loses its position when it later renders content (lands after its siblings). Prod is unaffected (autoMemo forces the slot path, which mints the pair). The new negative-shape test documents the boundary and starts those children with content.
  • Natural extensions deliberately left out: @switch-root bodies, optimistic self-recursive arms, and definition-site stamps conditioned on imported callees' $$singleRoot.
  • docs/comment-marker-elision-plan.md gained an M7 section recording the proof, measurements, and declines.

Provenance

  • An agent produced this diff (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/@else tree can qualify when every arm renders one plain host or one qualifying same-module component call. collectSingleRootIfDeps records callee dependencies; a fixed-point pass (same pattern as autoMemo) sets info.singleRoot once 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 *_deep DOM 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 in comment-marker-elision-plan.md.

Reviewed by Cursor Bugbot for commit 765e52e. Bugbot is set up for automated code reviews on this repo. Configure here.

trueadm and others added 2 commits August 10, 2026 00:06
…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]>
@github-actions github-actions Bot added agent-authored Diff or issue body substantially produced by an AI agent perf PR: performance work labels Aug 9, 2026

@cursor cursor Bot left a comment •

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cursor Bugbot has reviewed your changes using default effort and found 1 potential issue.

Fix All in Cursor

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.

Create PR

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.

Comment thread packages/octane/src/compiler/compile.js Resolved
@vercel

vercel Bot commented Aug 9, 2026 •

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

2 Skipped Deployments
Project Deployment Actions Updated (UTC)
octane-website Skipped Skipped Aug 9, 2026 11:21pm
octane-website-mcp Skipped Skipped Aug 9, 2026 11:21pm

Request Review

@vercel
vercel Bot temporarily deployed to Preview – octane-website August 9, 2026 23:21 Inactive
@vercel
vercel Bot temporarily deployed to Preview – octane-website-mcp August 9, 2026 23:21 Inactive
@trueadm
trueadm marked this pull request as ready for review August 9, 2026 23:27
…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
@trueadm
trueadm merged commit 8cb40df into main Aug 10, 2026
10 of 29 checks passed
@trueadm
trueadm deleted the perf/multihole-singleroot-elision branch August 10, 2026 00:25
@trueadm
trueadm restored the perf/multihole-singleroot-elision branch August 10, 2026 00:26
@trueadm
trueadm deleted the perf/multihole-singleroot-elision branch August 26, 2026 20:41
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

agent-authored Diff or issue body substantially produced by an AI agent perf PR: performance work

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant