Repository navigation
perf(octane): render hookless control-flow arms without a Block - #1903
Conversation
The compiler marks an @if/@switch arm lite when it calls no hook, use() or context read, holds no @Try, and makes no bare-identifier call while it renders. ifBlock and switchBlock take the mask. On a client mount under a root render that created the arm's owner, a lite arm renders in a ScopeImpl with a LiteBlockImpl stand-in that carries its bound the way an arm Block would, so boundary sharing, journaling and staged swaps read one shape. Teardown runs through the slot in tree order. A committed lite arm swaps out through the staged root-render path, and its release waits for the commit. Hydration, signal ownership, native reads and shared bodies keep Block arms. Paired: recursive-context cold mount 0.970, partial remount cycle 0.900; spa-navigation nav_mount 0.829, nav_deep 0.828. Co-Authored-By: Claude Opus 5.5 <[email protected]>
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes using default effort and found 3 potential issues.
Autofix Details
Bugbot Autofix prepared fixes for all 3 issues found in the latest run.
- ✅ Fixed: Ref attrs hide render-time hook calls
- Changed the ref/event attribute handler to walk the value expression (detecting render-time hooks like useRef/useCallback) instead of returning false early, while still skipping direct function expression callback bodies.
- ✅ Fixed: Lite proof misses wrapped callees
- Added OptionalCallExpression to the call-type check and applied unwrapTsExpr to the callee before testing for Identifier, and added OptionalMemberExpression to the member-expression hook-name check.
- ✅ Fixed: Nested arms lose real Block identity
- Added parentOwner = owningBlock(parentBlock) in renderBranchSlot and used it for all disposed checks, currentRenderMode reads, and preservesCommittedSuspense calls so a LiteBlockImpl stand-in delegates to the nearest real Block.
Or push these changes by commenting:
@cursor push a1c56e5e56
Preview (a1c56e5e56)
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
@@ -32908,11 +32908,11 @@
n.name === 'createPortal')
)
return true;
- if (t === 'CallExpression') {
- const callee = n.callee;
+ if (t === 'CallExpression' || t === 'OptionalCallExpression') {
+ const callee = unwrapTsExpr(n.callee);
if (callee?.type === 'Identifier') return true;
if (
- callee?.type === 'MemberExpression' &&
+ (callee?.type === 'MemberExpression' || callee?.type === 'OptionalMemberExpression') &&
!callee.computed &&
callee.property?.type === 'Identifier' &&
/^use[A-Z]/.test(callee.property.name)
@@ -32921,7 +32921,15 @@
}
if (t === 'Attribute' || t === 'JSXAttribute') {
const name = n.name?.name ?? n.name;
- if (typeof name === 'string' && (name === 'ref' || isEventAttrName(name))) return false;
+ if (typeof name === 'string' && (name === 'ref' || isEventAttrName(name))) {
+ // The callback body runs after render, but the value expression
+ // executes at render time: ref={useRef(null)} must be caught.
+ const val = n.value;
+ const expr = val?.type === 'JSXExpressionContainer' ? val.expression : val;
+ if (!expr || expr.type === 'ArrowFunctionExpression' || expr.type === 'FunctionExpression')
+ return false;
+ return reject(expr);
+ }
}
for (const k in n) {
if (AST_WALK_SKIP_KEYS.has(k)) continue;
diff --git a/packages/octane/src/runtime.ts b/packages/octane/src/runtime.ts
--- a/packages/octane/src/runtime.ts
+++ b/packages/octane/src/runtime.ts
@@ -45305,6 +45305,9 @@
lite?: boolean,
): void {
const parentBlock = parentScope.block;
+ // A lite arm's stand-in is not a Block: disposal and render-mode state live
+ // on the nearest real Block above it (owningBlock traversal).
+ const parentOwner = owningBlock(parentBlock);
const hydration = hydrating ? activeHydration() : null;
if (next !== state.branch) {
if (
@@ -45365,7 +45368,7 @@
}
}
const swapDriver = TRANSITION_SWAP_DRIVER;
- const transitionMode = parentBlock.currentRenderMode === 'transition';
+ const transitionMode = parentOwner.currentRenderMode === 'transition';
const committedSuspense =
swapDriver !== null &&
state.block !== null &&
@@ -45373,7 +45376,7 @@
!state.unfinalized &&
body !== null &&
hydration === null &&
- preservesCommittedSuspense(parentBlock);
+ preservesCommittedSuspense(parentOwner);
const transitionSwap =
ROOT_RENDER_TRANSACTION === null || committedSuspense ? swapDriver : null;
const suspenseSwap = !transitionMode && committedSuspense;
@@ -45393,7 +45396,7 @@
state.block = null;
state.unfinalized = false;
unmountBlock(pending, false);
- if (parentBlock.disposed) return;
+ if (parentOwner.disposed) return;
while (node !== null && node !== provisionalAfter) {
const nextNode = getNextSibling(node);
if ((STAGED_DOM?.view(node) ?? node).parentNode === domParent)
@@ -45405,7 +45408,7 @@
provisionalAfter = state.lite.block.endMarker;
state.unfinalized = false;
unmountLiteArm(state, false);
- if (parentBlock.disposed) return;
+ if (parentOwner.disposed) return;
}
// A markerless branch may share its host boundary with a nested sole-root
// branch. The nested branch updates Block markers when it replaces that
@@ -45631,7 +45634,7 @@
STAGED_DOM?.view(oldEnd as ChildNode | null) ?? (oldEnd as ChildNode | null)
)?.remove();
}
- if (parentBlock.disposed || state.block !== r.wip.block || r.wip.block.disposed) return;
+ if (parentOwner.disposed || state.block !== r.wip.block || r.wip.block.disposed) return;
return;
}
}
@@ -45646,11 +45649,11 @@
const oldBoundaryShared = sharesBlockBoundary(parentBlock, oldBlockStart, oldBlockEnd);
if (state.block) {
unmountBlock(state.block);
- if (parentBlock.disposed) return;
+ if (parentOwner.disposed) return;
state.block = null;
} else if (state.lite !== null) {
unmountLiteArm(state, true);
- if (parentBlock.disposed) return;
+ if (parentOwner.disposed) return;
}
state.branch = next;
if (state.start === null && body !== null && oldBoundaryShared) {You can send follow-ups to the cloud agent here.
Benchmark report
Compares js-framework: 1k/10k row operationsAll 20 timed operations (20 without a verdict)
All 64 work counters are unchanged. Application bundle size (bytes)
4 other measured values are unchanged. Public-import reachability bundles (bytes)
36 other measured values are unchanged. |
The same-arm path for a lite arm skipped the arm.keep probe. The profile docs and test now say a hookless arm mounted with its owner is not a Block, so a swap tears one down only once an update has mounted a Block arm. Co-Authored-By: Claude Opus 5.5 <[email protected]>
…-arms # Conflicts: # packages/octane/src/runtime.ts
… off lite arms
The lite-arm proof skipped every ref and on* attribute value, so
ref={useRef(null)} or onClick={useCallback(...)} marked an arm hookless.
It now skips only an inline callback. A callee behind a TS cast, !, ?.
or a comma, a bare tag, and helper.call/apply also keep an arm on a Block.
Core slot teardown reaches unmountLiteArm through a hook that the lite
mount installs, so a root without control flow carries none of the lite
teardown.
Co-Authored-By: Claude Opus 5.5 <[email protected]>
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes using default effort and found 2 potential issues.
Bugbot Autofix prepared fixes for both issues found in the latest run.
- ✅ Fixed: Disposed check misses lite parents
- Computed owningBlock(parentBlock) once per swap in renderBranchSlot and replaced all 5 parentBlock.disposed checks with disposeTarget.disposed, so the guard correctly reads the real Block's disposed flag when the parent is a LiteBlockImpl stand-in.
- ✅ Fixed: Return slot skips lite retirement
- Added state.lite?.block to the retiredBlock chain in disposeReturnSlot so a return-owned lite arm's stand-in is retired via retireRootBlock before the deferred unmountSlot cleanup, matching the swap path's deferRootArmReplacement behavior.
Or push these changes by commenting:
@cursor push 6df886d59a
Preview (6df886d59a)
diff --git a/packages/octane/src/runtime.ts b/packages/octane/src/runtime.ts
--- a/packages/octane/src/runtime.ts
+++ b/packages/octane/src/runtime.ts
@@ -12829,7 +12829,7 @@
: (STAGED_DOM?.view(parent) ?? parent).lastChild,
borrowed ? end : ((STAGED_DOM?.view(last) ?? last)?.nextSibling ?? null),
);
- const retiredBlock = state.block ?? state.portal?.block;
+ const retiredBlock = state.block ?? state.lite?.block ?? state.portal?.block;
if (retiredBlock != null) retireRootBlock(retiredBlock);
if (state.forSlot != null) {
for (let item = state.forSlot.head; item !== null; item = item.nextSibling) {
@@ -45524,6 +45524,7 @@
}
}
const swapDriver = TRANSITION_SWAP_DRIVER;
+ const disposeTarget = owningBlock(parentBlock);
const transitionMode = parentBlock.currentRenderMode === 'transition';
const committedSuspense =
swapDriver !== null &&
@@ -45552,7 +45553,7 @@
state.block = null;
state.unfinalized = false;
unmountBlock(pending, false);
- if (parentBlock.disposed) return;
+ if (disposeTarget.disposed) return;
while (node !== null && node !== provisionalAfter) {
const nextNode = getNextSibling(node);
if ((STAGED_DOM?.view(node) ?? node).parentNode === domParent)
@@ -45564,7 +45565,7 @@
provisionalAfter = state.lite.block.endMarker;
state.unfinalized = false;
unmountLiteArm(state, false);
- if (parentBlock.disposed) return;
+ if (disposeTarget.disposed) return;
}
// A markerless branch may share its host boundary with a nested sole-root
// branch. The nested branch updates Block markers when it replaces that
@@ -45790,7 +45791,7 @@
STAGED_DOM?.view(oldEnd as ChildNode | null) ?? (oldEnd as ChildNode | null)
)?.remove();
}
- if (parentBlock.disposed || state.block !== r.wip.block || r.wip.block.disposed) return;
+ if (disposeTarget.disposed || state.block !== r.wip.block || r.wip.block.disposed) return;
return;
}
}
@@ -45805,11 +45806,11 @@
const oldBoundaryShared = sharesBlockBoundary(parentBlock, oldBlockStart, oldBlockEnd);
if (state.block) {
unmountBlock(state.block);
- if (parentBlock.disposed) return;
+ if (disposeTarget.disposed) return;
state.block = null;
} else if (state.lite !== null) {
unmountLiteArm(state, true);
- if (parentBlock.disposed) return;
+ if (disposeTarget.disposed) return;
}
state.branch = next;
if (state.start === null && body !== null && oldBoundaryShared) {You can send follow-ups to the cloud agent here.
Reviewed by Cursor Bugbot for commit dc4812a. Configure here.
…posal disposeReturnSlot already read a lite arm's bound for the deferred range; it now retires the arm's stand-in as well, as deferRootArmReplacement does, so queued renders under it stop with the slot. The post-teardown checks in renderBranchSlot read disposal from the owning Block, since a lite stand-in has none of its own. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Deploying with
|
| Status | Name | Latest Commit | Preview URL | Updated (UTC) |
|---|---|---|---|---|
| ✅ Deployment successful! View logs |
octane-website | ff9487b | Commit Preview URL Branch Preview URL |
Oct 08 2026, 07:28 PM |
Deploying with
|
| Status | Name | Latest Commit | Preview URL | Updated (UTC) |
|---|---|---|---|---|
| ✅ Deployment successful! View logs |
octane-website-mcp | ff9487b | Commit Preview URL Branch Preview URL |
Oct 08 2026, 07:30 PM |
unmountLiteArm copied deferRootUnmount's node collection, rollback restore and commit-time reconnect. Both now call deferRootTeardown with their own release (unmountBlock or releaseLiteArm, passed by reference so core teardown never names the lite path), and a lite arm's immediate detach uses removeRange after its cleanups, as unmountBlock does. Control-flow bundles shrink by about 500 B raw (hydrate-frame -517 raw, -145 gzip); a root without control flow pays +57 raw for the extra call. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Since #1875 a ready producer whose shared 5 ms host budget is spent waits for a host task (yieldForHostBudget). drain() only awaited microtasks, so on a loaded CI shard the stream-query adoption tests saw result$.get() throw its pending promise. drain() now lets a host task run after each microtask checkpoint. With the budget forced to 1e-9 ms (one unit per window), the old drain fails both stream cases and the new one passes. Co-Authored-By: Claude Opus 5.5 <[email protected]>


Summary
An
@ifor@switcharm that calls no hooks now renders without a component Block of its own. This is step 2 of the cold-mount plan. Step 1, #1896 (which slimsBlockImpl), has merged, and this branch includes it.controlFlowArmIsLite): an arm is lite when it calls no hook,useor context read, has no@try, and makes no call through a bare identifier while it renders. That includes a callee behind a TS cast,!,?.or a comma, a bare tag, andhelper.call/helper.apply. An inline event-handler orrefcallback doesn't count, because it runs after render. Any other value of those attributes is walked, soref={useRef(null)}keeps a Block. A member call is allowed unless it is named like a hook.ifBlocktakes a new trailing mask (1 = then, 2 = else).switchBlocktakes one too (bit 0 = default, bit i + 1 = case i). Arms that don't qualify emit no extra argument.ScopeImpl, with aLiteBlockImplstand-in asscope.block. It skipsBlockImpl,createBlock,createdInRootRenderandrenderBlock/renderBlockInner.BranchSlotgainslite: Scope | null.startMarker/endMarkerexactly as an arm Block would. So the boundary-sharing, journaling and live-end code readsstate.block ?? state.lite.blockand is otherwise unchanged.LiteBlockImplgainsstartMarker, set toundefinedfor lite components, which keeps their sole-root inherit-range decline.liteArmAllowed): a root render must be active and must have created the arm's owning Block. That Block's creation undo then discards the arm with it. Hydration, signal documents and owners, native reads and shared bodies keep Block arms.unmountSlot), so effect cleanup order stays in tree order. The arm is not registered inparentScope.children.forEachSubtreeChildvisitsslot.litefor Suspense and Activity.deferRootArmReplacement).unmountLiteArmdefers its release the waydeferRootUnmountdoes. Its nodes leave now, are restored on rollback, and reconnect for the release at commit.releaseLiteArmis idempotent: a rollback can restore a slot that names an already released arm.disposeReturnSlot. That way queued renders under it stop with it. After a teardown,renderBranchSlotreads disposal from the owning Block, since a stand-in has none of its own.arm.keep, like a kept Block arm. A lite arm is not a Block, so it doesn't count towardblock.createorblock.unmount;profiling.tsnow says so, as it already did for lite components.Measurements
Paired runs against main in Chromium, using production builds served statically.
run.mjs(order-balanced pairs) gives mount 0.93×.@ifor@switch, so its work counters can't change.Bundle bytes
Measured locally with
run-minimal.mjsagainst this branch's base, maincbc1e8e651:@if/@switch(root-static-specialized;hooks-state,cli-spa-starterandsuspense-transitionmatch)hydrate-frame(control flow)unmountLiteArmonly throughUNMOUNT_LITE_ARM, which the lite mount installs. A lite arm's commit-deferred teardown sharesdeferRootTeardownwithdeferRootUnmount; each passes its own release by reference, so core teardown never names the lite path. This sharing cut control-flow bundles by about 500 B raw (hydrate-frame−517 raw / −145 gzip against the previous head). A root without control flow pays +57 raw for the extra call.Validation
pnpm format:files:checkon every changed file.pnpm typecheck:files packages/octane/src/runtime.ts packages/octane/tests/hookless-arms.test.ts packages/octane/tests/_fixtures/hookless-arms.tsrxoctaneproject:@if,@switch, keyed lists, Suspense, transitions, Activity, refs, portals, ViewTransition, differential suites.hydration/directory: 165 files, 7,816 tests.octane,octane-prodandoctane-profile, 75 runs and 1,295 tests.profiling-runtime.test.tsrxinoctane-profile. CI's first run caught the missingarm.keepprobe. The test now swaps back as well, so it still sees a swap tear down a Block arm (the one the update mounted).pnpm test,pnpm typecheckandpnpm format:check: left to CI, per the shared-machine load rule.hookless-arms.test.ts(passes inoctaneandoctane-prod). Each scenario drives a hookless-arm form and a form whose arms calluseRef, and compares DOM and effect/ref logs after every step. Scenarios: swaps with siblings and refs, unmount while the arm is still lite, a transition into a suspending arm, keyed rows whose sole root is an arm, Activity hide and show, and a root render that rolls back.hookless control-flow arm proof): 13 cases. 4 must stay lite: static output, an inline handler, a member ref, a member tag. 9 must keep a Block: hook-producedref/onClickvalues, a bare call, cast,!,?.and comma callees,helper.call, a bare tag. 7 of the 9 failed on the previous proof;helper?.()andhelper()were already caught.perf-review:Risk / follow-ups
String(x),cx(...)ort(...), keeps an arm on a Block. Loosening it is a follow-up, measured on real apps.Provenance
agent-authored)🤖 Generated with Claude Code
Need help on this PR? Tag
@codesmith-botwith what you need. Autofix is disabled.Note
High Risk
Touches core control-flow mount, swap, rollback, and teardown in
runtime.ts; behavior must stay identical to Block arms across Suspense, transitions, hydration, and keyed moves.Overview
Hookless
@ifand@switcharms can now mount without allocating a control-flow Block. The compiler proves arms are “lite” withcontrolFlowArmIsLiteand passes a lite mask into_$ifBlock/_$switchBlock; qualifying arms render in a lightweight Scope + LiteBlockImpl stand-in inside the owner’s render, skippingcreateBlockand per-arm render bookkeeping.Runtime branch slots gain
lite, shared teardown/swap paths (renderLiteArm,unmountLiteArm,deferRootArmReplacement/deferRootTeardown), and stricter when lite is allowed (fresh root render that created the owner—no hydration, signals, etc.). Arms that use hooks,@try, bare helper calls, or swap into an already-committed slot still get a Block; committed lite arms use the same staged rollback-safe swap as Block arms.Tests add paired plain vs
useRefscenarios (DOM, effects, refs, transitions, keyed lists, Activity, rollback) plus compiler proof cases for the lite mask. Profiling docs note lite arms are notblock.create/block.unmount. Signal serialization tests use aMessageChannelhost task indrain()for more stable async timing.Reviewed by Cursor Bugbot for commit e7fb961. Bugbot is set up for automated code reviews on this repo. Configure here.