Repository navigation
perf(compiler): cache Strong inline render expressions like named consts - #1611
Merged
Merged
Conversation
A Strong module asserts that render-time calls are pure projections of
witnessed inputs, so `<output>{total.toFixed(2)}</output>` and
`const formatted = total.toFixed(2); <output>{formatted}</output>` are the
same program. Only the declaration reached rewriteAutoCalculation, so the
inline form recomputed on every entered render while the extracted form
was cached (#1610).
In production client builds, an eligible expression that the template
evaluates on every render (a host child hole, a host attribute, or a
component prop) now moves to a compiler-named const appended to setup.
The existing declaration path then admits or declines it under the same
rule, which is factored out as autoCalculationOf. Directive arms,
component children, built-in boundaries, expressions holding JSX, event
handlers, refs, keys, and render trees that write keep their evaluation
where it is written. A return-JSX component gets the same calculations
before a top-level `return <jsx>` only after an authored hook, so a
hookless one stays an ordinary deferred function.
A parallel use() warm plan runs outside the body that declares the
hoisted name, so it now reads the authored prop expression. Otherwise a
param-only prop such as `version={next(props.version)}` would make the
child look local-dependent and drop it from the first-attempt warm walk.
Closes #1610
Co-Authored-By: Claude Opus 5.5 <[email protected]>
…nder-calculations
trueadm
marked this pull request as ready for review
October 2, 2026 21:08
Contributor
Benchmark report🟢 No size increases and no timing regressions outside noise. Compares js-framework: 1k/10k row operations (ms, lower is better)All 20 timed operations (20 within noise)
Application bundle size (bytes)No changes across 45 measured values. Public-import reachability bundles (bytes)No changes across 105 measured values. |
This was referenced Oct 3, 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
Closes #1610.
A Strong module asserts that every render-time call is a pure projection of witnessed inputs, so these are the same program:
Only the declaration reached
rewriteAutoCalculation, so the inline form recomputed on every entered render while the extracted form was cached. React Compiler caches both.In production client builds, an eligible expression the template evaluates on every render is now moved into a compiler-named
constappended to setup. That covers host child holes, host attributes, and component props. The existing declaration path then admits or declines it under the same rule, which this change factors out asautoCalculationOf. For the issue's repro, the inline output now matches the extracted output's cache region. It also skips the extracted form's pending-output guard, because the moved calls were never setup calls.What stays where it is written
@if/@for/@switch/@tryarmsoctane.map(… => <li/>),cond && <X/>)on*handlers,ref,key,childrenstrongMemois off, or holes carry direct signal bindings.React-style return components get the same calculations only for a top-level
return <jsx>reached after an authored hook call. This is the existing render-scope proof the declaration path already uses there, so a hookless return component stays an ordinary deferred function.Warm plans
A parallel
use()warm plan is printed outside the body that declares a hoisted name.collectWarmChildtherefore uses the authored prop expression for a hoisted prop. Without this, a param-only prop such asversion={next(props.version)}turns into a component local. The child then drops out of the first-attempt warm walk, and its request waterfalls.Validation
pnpm format:check(onlypnpm format:files:checkon the changed files, which passes)pnpm typecheck(only scopedpnpm typecheck:fileson the changed files; it reports nothing in the added lines, only existing fixture-import and implicit-anylines)pnpm test(left to CI)auto-calculation.test.ts: 16 passed (octaneandoctane-prod)parallel-use.test.ts: passed (octaneandoctane-prod)for.test.tsunderoctane-prod: 113 passed. Its Strong fixtures now get hoisted props, including the server-render-then-hydrate cases.compiler/strong-*.test.ts(8 files): 1,874 passedoctane-prod:event-bundle-captures,event-signal-owner,hydrate-compiler,hydration/range-boundary,hydration/direct-signal-bindings, all passedcompiler/for-item-purity,bundler-compiler,compiler-vite-options,native-reads: passedNew tests compile their Strong sources with production options, so both projects exercise the cache. I checked that each fails on a realistic broken version:
id1becomesid3).@ifarm and in component children evaluate only when they renderTypeErrorreadingnameofnull).second:1waterfalls).Compatibility-mode output for the issue's inline repro is byte-identical before and after.
Cost
I made no runtime speed claim and ran no benchmark locally. Each hoisted expression adds one memo cell and guard. That is about 45–50 gzip bytes after minification: the new five-calculation test module grows from 1,539 to 1,776 B gzip. The existing
for-strong.tsrxfixture grows by 39 B gzip.for-strong.tsxandevent-signal-owner-strong.tsrxare unchanged. This is the trade the declaration path already makes.template-call-memoshould not move: its top-level calls use a global callee (String(tick)), which stays live, and its rows are@forarms.Risk / follow-ups
constalready had.@if,@for, and@switchheads are not hoisted yet. For example,@for (const r of rows.filter(…))would gain a stable iterable. It needs its own check against keyed-list lowering.<ui.Button>,<{Tag}>) are skipped conservatively.Provenance
agent-authored)🤖 Generated with Claude Code
Need help on this PR? Tag
@codesmith-botwith what you need. Autofix is disabled.Note
Medium Risk
Changes Strong production client lowering and memo timing for inline expressions; incorrect hoisting could alter evaluation order or break warm-plan prefetching, though guards and new tests target those edges.
Overview
Strong production client builds now treat eligible inline template expressions (host text holes, attributes, and component props) like an authored
constin setup: the compiler hoists them to compiler-named declarations and runs them through the sameautoCalculationOf/rewriteAutoCalculationmemo path, aligning with React Compiler for cases such as{total.toFixed(2)}androws={project(rows)}.Hoisting is skipped where evaluation must stay conditional or special-cased—directive arms, component children, built-in/
octaneboundaries, JSX-bearing expressions, handlers/refs/keys, render trees with side-effect writes, returned-output bodies, native-read modules, dev/server, and hooklessreturn <jsx>components (caching only after an authored hook establishes render scope).Parallel
use()warm plans still evaluate hoisted prop expressions from the authored source viactx.hoistedRenderCalculations, so sibling prefetches are not lost when props become setup locals.Docs and a patch changeset describe the behavior;
auto-calculation.test.tsandparallel-use.test.tsadd production-compiled Strong coverage.Reviewed by Cursor Bugbot for commit 46f462b. Bugbot is set up for automated code reviews on this repo. Configure here.