Repository navigation
fix(compiler): cache a const that only another cached calculation reads - #1625
Merged
Merged
Conversation
Automatic calculation cached a `const` only when the template read it, so
in `const a = f(x); const b = g(a); <p>{b}</p>` `a` recomputed every
render and `b`'s cache, keyed on `a`, missed every render too. The same
happened to a const read only by a Strong inline calculation hoisted into
`__calc`.
closeCalculationReads closes the template's reads through every
calculation rewriteAutoCalculation would cache, with a worklist run to a
fixed point, in compileFunctionBody and compileReturnJsxFunction. Hook
calls, live receivers, `let`, self-references, and handler-only values
still add nothing.
A cache evaluates its dependencies at its declaration, so a calculation
whose callback reads a later binding threw in the temporal dead zone. Main
already crashed when the template read one; following chains would have
spread it. Such a calculation now stays uncached.
Co-Authored-By: Claude Opus 5.5 <[email protected]>
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. |
trueadm
marked this pull request as ready for review
October 3, 2026 08:27
This was referenced Oct 3, 2026
trueadm
added a commit
that referenced
this pull request
Oct 3, 2026
…#1647) The dev-SSR hydration e2e picked its port with getFreePort(), which closed the probe socket before the .vite cache removal and the vite spawn. On PR #1625 another process took the port in that window and the strictPort dev server died with "Port 41193 is already in use". - reserveFreePort() now holds the port on 127.0.0.1 and ::1. The servers listen on `localhost`, which Node can resolve to ::1, and a hold on 127.0.0.1 alone does not stop a ::1 listener from taking the same port. - The dev server clears the optimize-deps cache first, then reserves, and releases immediately before the spawn via startServerOnFreePort(). - startServerOnFreePort() retries, on a fresh reservation and at most three times, only when the child exits before listening because vite reported that exact port in use. The pnpm and vite startup between release and bind is a window no reservation can cover. - getFreePort() is removed; it had no other caller. 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
Automatic calculation cached a
constonly when the template read it. Inconst a = f(x); const b = g(a); <p>{b}</p>,arecomputed every render, sob's cache (keyed ona) missed every render andgran every render too. The same applied to a const read only by a Strong inline calculation hoisted into__calc. Found in the 2026-10-02 review as the G-1 follow-up.closeCalculationReads(incompile.js, besiderewriteAutoCalculation) seeds fromcollectRenderReadNamesand runs a worklist to a fixed point: every const thatrewriteAutoCalculationwould cache adds its dependencies. It coverscompileFunctionBodyandcompileReturnJsxFunction. In return-JSX components only statements after the first authored hook take part, because nothing before it is cached.let, self-references, and handler-only values add nothing.nativeReadslowering applies to every rewritten const.const x = make(() => later); const later = f(y)threwCannot access 'later' before initializationonce the template readx. That was already true on main. Following chains would have spread it: the corpus compile hit it insignals-parallel-useParallelAuthLocalunder Strong. A calculation whose dependency is declared later now stays uncached.calculationDeclaratorholds the declarator shape check thatrewriteAutoCalculationand the closure share.docs/differences-from-react.md, and a patch changeset.Validation
pnpm format:check, not run (scopedpnpm format:files:checkon every changed file passes)pnpm typecheck, not run. Scopedpnpm typecheck:fileson the changed tests and fixtures reports three errors, all on lines this PR does not touch: the existing.ts/.tsxextension imports andauto-memo-child.tsrx.pnpm test, not run (one owning file and one project at a time, per local load rules)auto-calculation.test.ts: 21/21 inoctaneand inoctane-prod. The new cases compile with prod options. They cover a three-link@{}chain, a return-JSX chain, Strong@{}and return chains through__calc, and the later-constcase in direct, chained, and Strong forms. Every new case failed before the fix, or with the guard disabled. The chained and Strong later-constforms each fail alone without the guard.signals-rendering.test.ts: 26/26 inoctane-signals,octane-signals-prod, andoctane-signals-strong. The new native-reads chain reads a signal in its first link. It failed without the closure, and it goes stale ('1' instead of '5') if the native witness check is removed.signals-parallel-use.test.ts: 6/6 inoctane-signals-strongandoctane-signals-prod.parallel-use.test.ts: 64/64 inoctane..tsrx(Ripple benchmark sources excluded) was compiled with{ mode: 'client', hmr: false, dev: false }, plain and withstrong: true, comparing main's compiler with this branch:signals-parallel-usetest fixture.getAssetKeys,errorArguments,getInternalNodesBounds,createStyleCache, or localquery$. The template-read form already got that shape on main.root-chained-jsx.tsx, compile byte-identical.Risk / follow-ups
collectMutatedNamesexclusion has to act insidecloseCalculationReads, skipping or dropping names the way the later-binding guard does. Until then, the closure widens the pre-existing G-12 hazard: inconst list = make(rows); list.push(x); const v = wrap(list),listis now cached. This closure also replaces that fix's G-1 change.octane-signals-strongdoesn't reach this path. It passedsignals-parallel-useeven with the guard disabled. The source-loader tests above and the corpus compile are the evidence for production Strong chains.Provenance
agent-authored)🤖 Generated with Claude Code
Need help on this PR? Tag
@codesmith-botwith what you need. Autofix is disabled.Note
Medium Risk
Compiler optimization changes when derived values are memoized and can alter call frequency for impure helpers; TDZ guard avoids a class of runtime crashes but chain closure may cache more bindings until related follow-up fixes land.
Overview
Extends automatic
constcaching to full dependency chains so intermediate derived values stay stable when only the last link is read in the template (including Strong hoisted inline calculations). The compiler now runscloseCalculationReadsaftercollectRenderReadNames, walking eligible cached calculations to a fixed point beforerewriteAutoCalculationruns in@{}bodies and post-hookreturn <jsx>components.Guards against temporal-dead-zone crashes: calculations whose dependency tracking would read a
constdeclared later are removed from the cached set and left uncached (directly and when reached via chain closure).Docs note chain behavior; tests cover multi-link chains, return-JSX/Strong paths, forward-read cases, and signal-invalidated chains (
NativeChainedReader).Reviewed by Cursor Bugbot for commit ce61f91. Bugbot is set up for automated code reviews on this repo. Configure here.