Repository navigation
perf(compiler): lower conditional JSX returns to template control flow - #674
Merged
Merged
Conversation
if (c) return <A/>; return <B/>; (and ternary returns) now compile to the same ifBlock arms as @if/@else in both dialects and both compile modes, so branch-selected output stops running through the de-opt descriptor renderer. Admission is conservative: capitalized module-level function declarations whose component-level returns are all syntactic JSX/null reachable through if/else only, pairwise-distinct arm root types with at least one host root, no fragment arms, no self-recursive arm roots, no hooks in arm-bound content, and no non-render module references. The bundler mirrors the decision for cross-module void classification. spa-navigation octane-jsx nav_deep 4.50 -> 2.10ms (now ahead of solid 2.00), nav_mount 4.10 -> 1.60, nav_deep_6x 29.80 -> 13.60; de-opt counters hostElementBody/deoptItemBody 1023/2046 -> 0/0. work.mjs ceilings tightened to hold both dialects at zero de-opt calls, and ratios.json gains nav_teardown/nav_deep/nav_mount guards vs solid. 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 hook gate misses unstable hooks
- Replaced the local isHookName predicate in containsHookCall with the shared isHookCalleeName function, which already handles unstable_/UNSTABLE_ prefixed hook names via HOOK_NAME_CONVENTION_RE.
Or push these changes by commenting:
@cursor push 4b1180c1b9
Preview (4b1180c1b9)
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
@@ -23328,7 +23328,6 @@
*/
function containsHookCall(node) {
const seen = new WeakSet();
- const isHookName = (name) => name === 'use' || /^use[A-Z0-9_]/.test(name);
const walk = (value) => {
if (value == null || typeof value !== 'object') return false;
if (Array.isArray(value)) {
@@ -23345,12 +23344,12 @@
return false;
if (value.type === 'CallExpression') {
const callee = value.callee;
- if (callee?.type === 'Identifier' && isHookName(callee.name)) return true;
+ if (callee?.type === 'Identifier' && isHookCalleeName(callee.name)) return true;
if (
callee?.type === 'MemberExpression' &&
callee.computed !== true &&
callee.property?.type === 'Identifier' &&
- isHookName(callee.property.name)
+ isHookCalleeName(callee.property.name)
)
return true;
}You can send follow-ups to the cloud agent here.
Reviewed by Cursor Bugbot for commit 68909d5. Configure here.
containsHookCall hand-rolled the use* pattern and missed unstable_use*/ UNSTABLE_use* hooks, so a component calling one behind an early return could still lower and lose its slot state to the arm scope on a branch flip. Use isHookCalleeName (HOOK_NAME_CONVENTION_RE) instead; regression test pins component-scope state across flips for an unstable_use* hook. Co-Authored-By: Claude Fable 5 <[email protected]>
trueadm
marked this pull request as ready for review
August 9, 2026 23:01
# Conflicts: # packages/octane/tests/_server-fixture.ts
95 tasks done
trueadm
added a commit
that referenced
this pull request
Oct 3, 2026
trueadm
added a commit
that referenced
this pull request
Oct 3, 2026
… samples Two quick CI runs of the paired, ~20 ms harness and same-runner A/B runs against the commits that set each guard decided every waiver: - Passing, waiver removed: activity reports, ssr-workerd cold_spawn_to_first_byte, svg-dashboard pan_zoom, memo-wall parent_rerender_equal_A and octane-jsx mount, spa-navigation nav_teardown and nav_mount (no Octane change since #674 on one runner). - Rebaselined: svg-dashboard icon_swap 1.2 -> 1.6, because #983's esbuild minification made React 15% faster while Octane stayed flat. - Confirmed Octane regressions, waiver kept and pointed at the fix: js-framework-reorder rotateb (1.41x per click since #639), memo-wall one_change_B (1.5x) and ctx_through_wall_B (1.44x), and svg-dashboard tooltip_swarm (1.31x since #635). - The rotateb note claimed React moves every survivor; it moves one. A new rotatef guard covers the LIS-vs-lastPlacedIndex differentiator (0.043x). Co-Authored-By: Claude Opus 5.5 <[email protected]>
trueadm
added a commit
that referenced
this pull request
Oct 3, 2026
The 1.2 ceiling came from a local 0.94x reading. On CI runners #674 itself measures 1.15x and head 1.09-1.16x, so the ceiling left 3% of quick-mode headroom; 1.35 keeps a margin while still catching per-node mount growth. Co-Authored-By: Claude Opus 5.5 <[email protected]>
1 of 4 tasks
trueadm
added a commit
that referenced
this pull request
Oct 3, 2026
…nd re-judge them (#1646) * ci(bench): triage the weekly ratio-guard breaches so new ones show The weekly Bench job (`bench.mjs --quick --ratios`) was red with 81 ratio breaches, 4 suites that wrote no numbers and 4 harness gate failures, so a new breach was invisible. Every item is now a fix or a rebaseline. - Harness drift, fixed. Each harness had stopped producing numbers when runtime source it anchors on changed: - ssr-final-replay: a second suspended loop since 2026-09-29. - root-transactions/contracts: staged-DOM text and attribute journaling since 2026-09-15. - signal-dom-bindings: a second native style Block allocation site since 2026-09-23. - codegen-size: the server runtime's lazy streamed-signals chunk since 2026-09-16. - recursive-context: counted a pure-call annotation and trailing newlines as output growth. - Rebaselined, with numbers in each note: five cross-framework bundle-size ratios and the workerd script-size ratio. The absolute app and server-render budgets are now the ratchet. Lynx's no-worklet byte caps from 2026-08-17 are reset to measured + 32, with the background program pinned exactly. - Fix pending, with dated waivers that expire 2026-10-24, each with an owner task: - three exact counters the revived harnesses exposed (one extra closure per ssrTry, 128 live text reads per 128 unchanged compiled updates, compiled output at 1.295x its source); - Lynx create ratios and the re-entrant transport gate; - superlinear hydrate boundary preparation; - Octane Three versus R3F size and frame dispatch; - two timing regressions near the timer floor; - ten quick-mode timing guards whose samples are noise-bound; - the scoped descriptor shape change. - bench.mjs supports a guard `waiver` ({ reason, expires }). A waived breach prints and does not fail, and fails again once the date passes. HARNESS_FAILURE_ALLOWLIST now also covers a suite whose harness writes no numbers. The budget breaches (57) clear when the budget reset lands. Co-Authored-By: Claude Opus 5.5 <[email protected]> * fix(benchmarks): pair and lengthen the timing samples behind waived ratio guards Twelve timing guards breached in weekly quick runs without a verdict. Their samples sat near Chromium's 100 µs clock or under two-sample noise, and each target ran its whole block minutes after the other side of its guard. - benchmarks/lib/paired.mjs: rotating per-round visit order and a ~20 ms sample calibration shared by the harnesses below. - js-framework-reorder, memo-wall, svg-dashboard, spa-navigation: every target's page stays open in one browser and each sample round visits all targets; short ops repeat until a sample takes about 20 ms (clicks, hook invocations, op batches, and summed navigation legs). - activity caught-reveal: a sample reveals several independent hidden roots in one window, with the small case revealing eight times as many roots so both cases do equal work; the cases alternate per round. - ssr-workerd: an untimed priming spawn per target, then paired cold-spawn rounds; quick mode runs six rounds instead of two. - bench.yml: a `suites` dispatch input to run selected suites. Co-Authored-By: Claude Opus 5.5 <[email protected]> * fix(benchmarks): collect garbage before every timed spa-navigation leg The untimed return leg mounts a whole route, and its collection landed inside the next timed teardown: nav_teardown samples ran at 17-45% rme. Co-Authored-By: Claude Opus 5.5 <[email protected]> * fix(benchmarks): re-judge the twelve waived timing guards with paired samples Two quick CI runs of the paired, ~20 ms harness and same-runner A/B runs against the commits that set each guard decided every waiver: - Passing, waiver removed: activity reports, ssr-workerd cold_spawn_to_first_byte, svg-dashboard pan_zoom, memo-wall parent_rerender_equal_A and octane-jsx mount, spa-navigation nav_teardown and nav_mount (no Octane change since #674 on one runner). - Rebaselined: svg-dashboard icon_swap 1.2 -> 1.6, because #983's esbuild minification made React 15% faster while Octane stayed flat. - Confirmed Octane regressions, waiver kept and pointed at the fix: js-framework-reorder rotateb (1.41x per click since #639), memo-wall one_change_B (1.5x) and ctx_through_wall_B (1.44x), and svg-dashboard tooltip_swarm (1.31x since #635). - The rotateb note claimed React moves every survivor; it moves one. A new rotatef guard covers the LIS-vs-lastPlacedIndex differentiator (0.043x). Co-Authored-By: Claude Opus 5.5 <[email protected]> * fix(benchmarks): rebaseline spa-navigation nav_mount to its CI baseline The 1.2 ceiling came from a local 0.94x reading. On CI runners #674 itself measures 1.15x and head 1.09-1.16x, so the ceiling left 3% of quick-mode headroom; 1.35 keeps a margin while still catching per-node mount growth. Co-Authored-By: Claude Opus 5.5 <[email protected]> * ci(bench): drop the three weekly waivers that now have fix PRs The waived guards now have owner PRs: ssr-final-replay try_closures (#1644), root-transactions equal_reads (#1643) and codegen-size gzip compiled/source (#1645). #1645 rebaselines the same codegen-size entry, so this branch no longer edits it. Co-Authored-By: Claude Opus 5.5 <[email protected]> * ci(bench): leave lynx-render to its owner fix The lynx-render transport gate failure and the create_1k/create_10k ratio breaches both trace to #885's JSON-encoded transport and now have an owner fix. Its branch re-notes those two guards, so this branch drops their waivers and the suite's allowlist entry instead of editing the same entries. Co-Authored-By: Claude Opus 5.5 <[email protected]> * ci(bench): keep harness failures unwaivable and leave descriptor shapes to their owner Waiving a suite that throws before it writes numbers would hide any crash in that suite, not only the known shape change, and skip all of its guards. The scoped-descriptor-shapes defect has an owner fix in progress. That fix re-pins the harness's expected keys, so narrowing the waiver here would edit the same assertion. HARNESS_FAILURE_ALLOWLIST is empty again, and a thrown suite failure always fails the job. Dated waivers remain only on individual ratio guards. Co-Authored-By: Claude Opus 5.5 <[email protected]> * ci(bench): leave the Three guards to their owner fixes three-renderer frame_1k_subscribers and the two three-bundle-size ratios have owner PRs (#1651, #1652) that re-note and ratchet those entries, so this branch drops their waivers instead of editing the same entries. Co-Authored-By: Claude Opus 5.5 <[email protected]> * fix(benchmarks): point the four kept timing waivers at their attributed fixes rotateb and ctx_through_wall_B clear with #1655 and #1656; one_change_B's per-row remainder and tooltip_swarm's scoped-descriptor accessor reads each have their own fix task. Co-Authored-By: Claude Opus 5.5 <[email protected]> * fix(benchmarks): point parent_rerender_equal_A's note at its per-commit journal fix Co-Authored-By: Claude Opus 5.5 <[email protected]> --------- 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
The compiler now lowers React-style conditional JSX returns —
if (c) return <A/>; return <B/>;, early-exit chains, and ternary returns — to the same template control flow as@if/@else, in both dialects and both compile modes. Branch-selected output stops running through the de-opt descriptor renderer entirely. Follow-up to #670 (finding 4 of the same spa-navigation audit); a.tsrxfunction using plain returns had the exact same de-opt cost, so this is a dialect-neutral lowering, not.tsxspecial-casing.Why
After #670, the spa-navigation
.tsxtwin still cost 2.4× the.tsrxtwin: its recursiveNodevalue-lowered tocreateScopedElementhost descriptors withcreateScopedValuechildren — 4,099createElement/ 4,094childSlot/ 2,046deoptItemBody/ 1,023hostElementBodycalls per navigation that the directive dialect never makes.Changes
lowerJsxReturnBranchComponents(compile.js), run in every compiler mode immediately afterlowerNullishComponentExitsin both the client and server entries, so SSR markers stay symmetric: restructures an admitted body into setup statements plus one directive-shaped render root, then the existing@{}pipeline compiles it —ifBlock,componentSlotVoid/Lite, autoMemo, warm plans and all.FunctionDeclarations only;use*names and lowercase helpers keep the callable value ABI;Animate ? <A/> : <B/>selectors) gain nothing and pay an SSR control range per level (caught by the visx SSR baseline);return <Self/>chain compiles to per-level control-flow frames that overflow 1000-deep SSR trees the value path renders fine (caught by the Fizz conformance suite);const {wrapper: MDXLayout} = …is a runtime-chosen value; caught by the mdx suite);memo(...)/lazy(...)argument.bundler.jsmirrors the decision via the exportedhasLowerableJsxReturnBranchesso cross-module void-output classification agrees with what each module compiled to.work.mjsceilings tightened: BOTH dialects now held at zero de-opt-renderer calls per navigation;ratios.jsongainsnav_teardown/nav_deep/nav_mountguards against solid (adapted from the now-superseded WIP: perf(teardown): single dom detach #615).VISX_CAPTURE_SERVER_HTMLregeneration path; one hydration assertion that pinned marker-comment bytes now asserts adoption by node identity plus comment-stripped content (markers are hydration's own claim-time bookkeeping).Benchmarks (same machine as #670's numbers,
node benchmarks/bench.mjs spa-navigation, medians in ms)The
.tsxtwin now beats Solid on the full navigation. Deterministic counters:hostElementBody/deoptItemBody1,023/2,046 → 0/0,childSlot4,094 → 2,createElement4,099 → 1,029, withNode's 2,046 arms oncomponentSlotVoid. The residual gap vs.tsrx(renderBlock 6,147 vs 5,119; createElement 1,029) is the single-return_fragwrapper ABI — the audit's finding 5, deliberately out of scope here.Validation
pnpm test— 1,612 files / 17,269 tests pass (includes octane-prod, differential, conformance, all binding projects)pnpm typecheckpnpm format:files:checkon changed filesjsx-return-branches.test.ts(20 cases: recursion, early-exit chains, state retention across arm flips AND across null outputs, non-returning else paths, fragments, destructured props, memo wrapping, direct-call anduse*controls, SSR adoption by node identity) — written and passing against the OLD value path first, so they pin semantics, not the implementation;spa-navigationfull + quick runs with all semantic/work/ratio gates green.Risk / follow-ups
@{}component; in-module direct calls are detected and reject lowering, cross-module direct calls of exported components were already unsupported in dev (HMR wrapper ABI)..tsxcomponents the block-body ABI instead ofcreateElement(_frag$N, holes)— that is the remaining 1.2× renderBlock gap.Provenance
agent-authored)🤖 Generated with Claude Code
Note
Medium Risk
Touches the core compile pipeline and client/server/hydration DOM shape for admitted components; risk is mitigated by conservative lowering rules and broad conformance/benchmark coverage, but wrong admission could change React reconciliation semantics.
Overview
Adds
lowerJsxReturnBranchComponentsin the Octane compiler (client and server, right after nullish-exit lowering) so React-style branch-selected JSX returns—if (c) return <A/>; return <B/>, early-exit chains, ternary returns—compile as@if/@elsetemplate control flow instead of the de-opt descriptor path when admission rules say the branches are remount-equivalent under React semantics.Admission stays narrow: capitalized module-level components only; distinct arm root types with at least one host root; no fragment/same-type/self-recursive arms, hooks in arm-bound code, or non-JSX-only references (direct calls keep the value ABI).
hasLowerableJsxReturnBranchesis exported and wired inbundler.jsso void-output classification matches compile-time lowering.Benchmarks:
spa-navigationREADME andwork.mjsnow expect zerohostElementBody/deoptItemBodyon JSX navigation;ratios.jsonaddsnav_teardown/nav_deep/nav_mountvs Solid. Tests: newjsx-return-branchesfixture and suite; hydration checks adoption by node identity (not marker bytes); visx committed SSR HTML refreshed with aVISX_CAPTURE_SERVER_HTMLregen hook.Reviewed by Cursor Bugbot for commit 4288d22. Bugbot is set up for automated code reviews on this repo. Configure here.