Repository navigation
perf(compiler): shrink plain-module hook boundaries and inline memo lowering - #1634
Merged
Merged
Conversation
…owering Production builds of plain .ts/.js hook modules grew with #1546 (a withSlot boundary per local custom-hook call) and #1577 (the inline memo tier admitted ~99% of modules). This trims both without changing behavior: - hook-deps.js omits a module-declared hook's call boundary when the hook reads no slot (it calls nothing but useContext and other such hooks), or when it is the hook's only use, made directly by another local hook that is used only by name, outside any cycle of such calls. Signal-reading modules and `$` hooks keep every boundary. - memoSlot receives the hook name only for an authored slot, which a manual hook may leave undefined; a compiler-appended slot always resolves. - A plain-module memo dependency that is a never-reassigned local binding is read in place instead of through a temporary. Imports stay copied: they are live bindings the factory can change. - The inline tier's admission and print move into createPlainProgramPrinter, and a corpus test reprints every Octane module in packages/*/src through it, comparing TypeScript syntax trees and requiring TypeScript and esbuild to parse the output, so an esrap gap fails CI instead of shipping to production only. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Contributor
Benchmark report
Compares js-framework: 1k/10k row operations (ms, lower is better)All 20 timed operations (20 within noise)
Application bundle size (bytes)
39 other measured values are unchanged. Public-import reachability bundles (bytes)
88 other measured values are unchanged. |
trueadm
added a commit
that referenced
this pull request
Oct 3, 2026
Brotli is not monotonic in code size. #1634 removes code and shrinks raw and gzip on every reachability row, yet raises brotli on three: +120 B on binding-apollo-client-vite and +28/+18 B on the usehooks-ts rows. The two changes that cause the apollo-vite rise each move brotli by single or double digits on their own; only their combination gives +120. A measured + 32 brotli budget would fail a change that strictly removes code, and under the budget-raise rule that change would need a separate raise. Raw and gzip stay at measured + 32 and remain the growth gate. Brotli becomes measured + 256, about twice the largest swing observed, so it still catches real compressed growth without blocking reductions. Co-Authored-By: Claude Opus 5.5 <[email protected]>
5 of 6 tasks
trueadm
added a commit
that referenced
this pull request
Oct 3, 2026
Brotli is not monotonic in code size. #1634 removes code and shrinks raw and gzip on every reachability row, yet raises brotli on three: +120 B on binding-apollo-client-vite and +28/+18 B on the usehooks-ts rows. The two changes that cause the apollo-vite rise each move brotli by single or double digits on their own; only their combination gives +120. A measured + 32 brotli budget would fail a change that strictly removes code, and under the budget-raise rule that change would need a separate raise. Raw and gzip stay at measured + 32 and remain the growth gate. Brotli becomes measured + 256, about twice the largest swing observed, so it still catches real compressed growth without blocking reductions. Co-Authored-By: Claude Opus 5.5 <[email protected]>
trueadm
added a commit
that referenced
this pull request
Oct 3, 2026
Brotli is not monotonic in code size. #1634 removes code and shrinks raw and gzip on every reachability row, yet raises brotli by up to 120 B, so a measured + 32 brotli budget would fail a pure reduction and force a raise. Budgets keep 32 bytes of headroom for raw and gzip, which remain the growth gate, and get 256 for brotli: `ratchetBudget` writes that, and the docs say which metric judges growth. The bindings application's brotli budgets move with the rest. Co-Authored-By: Claude Opus 5.5 <[email protected]>
5 of 6 tasks
trueadm
marked this pull request as ready for review
October 3, 2026 10:20
trueadm
added a commit
that referenced
this pull request
Oct 3, 2026
…endencies markStableMemoDependencies, added on main by #1634, walks every inferred dependency list on the plain-module path. A hook whose omitted list reads a later binding now infers null, so the walk threw "result.dependencies is not iterable" while compiling such a module. A null list has no dependencies to mark. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Merged
2 of 5 tasks
trueadm
added a commit
that referenced
this pull request
Oct 3, 2026
…es read a later binding (#1657) * fix(signals): re-run a local declaration that captures a later or reassigned variable #1635 compares the render values a local derived$ or query$ captures where the declaration runs. A var declared after the declaration is still undefined there, and a let or var assigned again holds an earlier value than the one the lazy closure reads. Both compared equal across renders, so the declaration kept its first render's closure after the variable changed. Capture analysis now records every variable declaration, using a repeated var's last one, and does not list a callback that captures a reassigned binding. Such declarations reevaluate on every render as before. Co-Authored-By: Claude Opus 5.5 <[email protected]> * fix(signals): do not list a capture read inside its own initializer A declaration inside the initializer of a variable its closure reads, such as `const api = { count$: derived$(() => api.items.length), items }`, had `[api.items]` listed. The list is read where the declaration runs, while `api` is still in its temporal dead zone, so rendering threw. Capture analysis now compares each binding's initialization end, the end of its last declarator or class, so such a declaration keeps no list. Co-Authored-By: Claude Opus 5.5 <[email protected]> * fix(compiler): run a hook on every render when its omitted dependencies read a later binding An omitted dependency array is inferred from the callback's captures and read where the hook is called. A capture that the component initializes after the call was read too early: a later let, const or class threw a temporal-dead-zone ReferenceError at render, a later var was still undefined so the hook never re-ran, and `const f = useCallback(() => f())` read f inside its own initializer. React runs a hook with an omitted array on every render, so inference now emits null for such a hook. lateDependencyFinder compares only bindings of the hook's own function, using #1650's initializationEnds, so a module let declared below a component keeps its list. All four places that print an inferred list emit null. Strong mode rejects an authored null list, so it reports OCTANE_STRONG_UNTRACKED_EFFECT at the late read instead. Co-Authored-By: Claude Opus 5.5 <[email protected]> * fix(compiler): skip a null inferred list when marking stable memo dependencies markStableMemoDependencies, added on main by #1634, walks every inferred dependency list on the plain-module path. A hook whose omitted list reads a later binding now infers null, so the walk threw "result.dependencies is not iterable" while compiling such a module. A null list has no dependencies to mark. Co-Authored-By: Claude Opus 5.5 <[email protected]> --------- Co-authored-by: Claude Opus 5.5 <[email protected]>
trueadm
added a commit
that referenced
this pull request
Oct 3, 2026
* ci(bench): re-set every byte budget to measured + 32 bytes Every reachability scenario (minimal-budgets.json) and every complete Octane application (app-budgets.json, jsx-budgets.json) now has a budget of exactly its production bytes on main plus 32, for raw, gzip and brotli. Twenty-one budgets had been exceeded with no pull request failing, because pull request CI enforced only five scenarios. Others had 4-30% slack that no change could breach. As ratchets, each budget now fails on more than 32 bytes of growth once CI enforces all of them (the follow-up pull request), and a raise lands on its own with the bytes and the reason, as this one does. Measured on main 11a9da9 with Node 24. Local and CI reachability bytes matched exactly on all 105 values compared. Co-Authored-By: Claude Opus 5.5 <[email protected]> * ci(bench): give brotli budgets 256 bytes of headroom Brotli is not monotonic in code size. #1634 removes code and shrinks raw and gzip on every reachability row, yet raises brotli on three: +120 B on binding-apollo-client-vite and +28/+18 B on the usehooks-ts rows. The two changes that cause the apollo-vite rise each move brotli by single or double digits on their own; only their combination gives +120. A measured + 32 brotli budget would fail a change that strictly removes code, and under the budget-raise rule that change would need a separate raise. Raw and gzip stay at measured + 32 and remain the growth gate. Brotli becomes measured + 256, about twice the largest swing observed, so it still catches real compressed growth without blocking reductions. Co-Authored-By: Claude Opus 5.5 <[email protected]> * ci(bench): re-measure budgets on main bc6761f Main moved while budgets were unenforced: 70 values shrank and are lowered to measured + headroom; 30 grew past the reset values and are raised to measured + headroom (largest: hydrate-root +88 gzip, octane-jsx rows framework +100 gzip). Identical to the values in #1639. Co-Authored-By: Claude Opus 5.5 <[email protected]> * ci(bench): re-measure budgets on main ac729dc Main grew again while budgets were unenforced (most bundles +37-68 raw bytes, todo framework +34 B gzip). Breached metrics are raised to measured + headroom, shrunk ones lowered. Identical to the values in #1639. Co-Authored-By: Claude Opus 5.5 <[email protected]> --------- Co-authored-by: Claude Opus 5.5 <[email protected]>
trueadm
added a commit
that referenced
this pull request
Oct 3, 2026
… feature changes (#1639) * ci(bench): re-set every byte budget to measured + 32 bytes Every reachability scenario (minimal-budgets.json) and every complete Octane application (app-budgets.json, jsx-budgets.json) now has a budget of exactly its production bytes on main plus 32, for raw, gzip and brotli. Twenty-one budgets had been exceeded with no pull request failing, because pull request CI enforced only five scenarios. Others had 4-30% slack that no change could breach. As ratchets, each budget now fails on more than 32 bytes of growth once CI enforces all of them (the follow-up pull request), and a raise lands on its own with the bytes and the reason, as this one does. Measured on main 11a9da9 with Node 24. Local and CI reachability bytes matched exactly on all 105 values compared. Co-Authored-By: Claude Opus 5.5 <[email protected]> * ci: enforce every byte budget on pull requests and keep raises out of feature changes PR CI now checks every committed byte budget, in one step in test shard 1/4: `run-minimal.mjs --budgets` covers all 35 public-import reachability builds, and `run.mjs --budgets octane-tsrx octane-jsx` covers every complete Octane application. Before this, PR CI enforced five scenarios. Twenty-one budgets had been exceeded on main with no pull request failing. These builds also run each scenario's executable and reachability gates, including the behavior-only and Apollo tree-shaking checks that had their own steps. - run-minimal.mjs and run.mjs gain `--write-budgets`, which records measured + 32 bytes for what they built. run.mjs also gains target selection and `--budgets`. - A new lint step, benchmarks/bundle-size/budget-raises.mjs, fails a change that raises any committed budget while also changing anything other than budget files and prose. It compares a pull request with its merge commit's first parent, and a push with the previous commit. Feature changes may lower budgets, never raise them. - bundle-size gains an Octane-only bindings application that renders Radix, Base UI, React Aria, Mantine hooks, usehooks-ts, Floating UI and Motion. The bindings ship source, so its `bindings_app_*` bytes move with compiler output for plain `.ts` binding hooks, which no other row contained. - The weekly guards cover the bindings set and the Apollo reachability scenarios, which had no guards. - CONTRIBUTING.md, the performance-audit skill and the benchmarks README document the policy and the commands. Co-Authored-By: Claude Opus 5.5 <[email protected]> * ci(bench): give brotli budgets 256 bytes of headroom Brotli is not monotonic in code size. #1634 removes code and shrinks raw and gzip on every reachability row, yet raises brotli on three: +120 B on binding-apollo-client-vite and +28/+18 B on the usehooks-ts rows. The two changes that cause the apollo-vite rise each move brotli by single or double digits on their own; only their combination gives +120. A measured + 32 brotli budget would fail a change that strictly removes code, and under the budget-raise rule that change would need a separate raise. Raw and gzip stay at measured + 32 and remain the growth gate. Brotli becomes measured + 256, about twice the largest swing observed, so it still catches real compressed growth without blocking reductions. Co-Authored-By: Claude Opus 5.5 <[email protected]> * ci: gate growth on raw and gzip, and give brotli budgets 256 bytes Brotli is not monotonic in code size. #1634 removes code and shrinks raw and gzip on every reachability row, yet raises brotli by up to 120 B, so a measured + 32 brotli budget would fail a pure reduction and force a raise. Budgets keep 32 bytes of headroom for raw and gzip, which remain the growth gate, and get 256 for brotli: `ratchetBudget` writes that, and the docs say which metric judges growth. The bindings application's brotli budgets move with the rest. Co-Authored-By: Claude Opus 5.5 <[email protected]> * fix(bench): make --write-budgets a ratchet that raises only a breached metric `--write-budgets` set every metric to measured + headroom. After a change that saved bytes, that could lift a brotli budget, since brotli can grow when code is removed, so the change would trip the budget-raise gate it was meant to satisfy. Each metric now drops to measured + headroom when that is lower, stays where the measurement still fits, and rises only when the measurement exceeds it. A raise therefore comes only from a real breach, and the gate stays strict for all three metrics. Rewriting unchanged bytes is a no-op. Co-Authored-By: Claude Opus 5.5 <[email protected]> * ci(bench): re-measure budgets on main bc6761f Main moved while budgets were unenforced: 70 values shrank and are lowered; 30 grew past the reset values and are raised to measured + headroom by the ratchet writer (largest: hydrate-root +88 gzip, octane-jsx rows framework +100 gzip). The same values go to the budget pull request, #1638. Co-Authored-By: Claude Opus 5.5 <[email protected]> * ci(bench): re-measure budgets on main ac729dc Main grew again while budgets were unenforced: most bundles gained 37-68 raw bytes, and the todo framework gained 34 B gzip. The ratchet writer raises the breached metrics (cli-spa-starter tripped this branch's gate by 13 raw bytes) and lowers the ones that shrank. The same values go to #1638. Co-Authored-By: Claude Opus 5.5 <[email protected]> --------- Co-authored-by: Claude Opus 5.5 <[email protected]>
3 of 6 tasks
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
This PR addresses review findings F3 and F4 (see the 2026-10-02 review of the window from #1476 to #1611). #1546 and #1577 grew production output for plain
.ts/.jshook modules. #1546 added awithSlotboundary per local custom-hook call; #1577 widened the production-only inline memo tier to about 99% of modules. This PR trims both without changing behavior, and commits #1577's corpus print-fidelity audit as a CI test.F4: inline memo lowering (almost all of the win)
memoSlotreceives the hook name only for an authored slot, which a manual hook may leave undefined. A slot the compiler appended always resolves, somemoSlot(_h$0, 'useMemo')becomesmemoSlot(_h$0)..tsrxcustom hooks and the native auto-calculation region.runtime.ts:namebecomes optional. 0 bytes.__hkdNtemporary.createPlainProgramPrinter. The tier and the new fidelity test share it.Fidelity test:
tests/compiler/plain-hook-memo-fidelity.test.tspackages/*/srcthat the printer admits.{ a }versus{ a: a },export { a as a }, and empty statements in statement lists.F3: local-hook boundary elision (
hook-deps.js, plain pass only)useContextand other such hooks, and it constructs nothing.$hooks keep every boundary, because their custom-hook call sites key signal declarations.Measurements
Per module, client production, esbuild minify, gzip -9, summed over every Octane
.ts/.jsmodule inpackages/*/src,examples/*/srcandwebsite/src(1,768 modules), base 27c2a12:withSlotIn the inline tier, F4 alone gives −10,441 min / −5,603 gzip over 286 modules. F3 alone gives −367 gzip in the surgical tier.
Bundles: the binding-heavy app row from the bench-gates work (radix, base-ui, aria, mantine-hooks, usehooks-ts, floating-ui, motion), same build settings as
run.mjs:bindings_appgzipThe framework chunk is unchanged at 119,125 B gzip.
Existing bundle rows:
run-minimal.mjshooks-state,binding-hooksandbinding-vanillaare byte-identical.binding-apollo-clientchanges as follows:.tsrx: the 16-file codegen corpus (benchmarks/compiler-output/corpus.mjs, client and server, also withinlineHookMemo) is byte-identical. Its components use the flat memo cache. A.tsrxcustom hook withuseMemo/useCallbackdrops the name literal.Brotli on the reachability rows: the bench report flags three brotli increases. All three are on rows where raw and gzip both shrink, so they are compression artifacts, not added code. Reproduced locally with
run-minimal.mjs binding-apollo-client binding-usehooks-ts, matching CI byte for byte:memoSlotname dropValidation
pnpm format:check: not run repo-wide.pnpm format:files:checkpasses on every changed file.pnpm typecheck: not run repo-wide.packages/octane/tsconfig.jsonexcludestests, andtypecheck:filesreports only the usual TS7016 on untyped compiler.jsimports.pnpm test: not run locally, because the machine is shared with other sessions. CI is the gate.octane, 13 files, 474 passed: plain-hook-memo, plain-hook-memo-codegen, plain-hook-memo-fidelity, inline-hook-memo (+ codegen), plain-hook-local-custom-hooks, transitive-hook-ownership, plain-hook-import-alias, external-hook-slot, auto-hook-deps, hook-method-diagnostics, member-hook-boundary, native-reads.octane-prod, 5 runtime files, 165 passed.octane, 28 related compiler/runtime files.octane-signals: signals-memos, signals-native-plain-module, signals-hook-declarations.octane-signals-node: signals-state.auto-calculationinoctaneandoctane-prod.useMemo/useCallbackfrom the missing-slot error.pnpm sync: no changes.Risk / follow-ups
plain-hook-memo.js(allocateHookSlot) andexternal-hook-slot.test.tsas the forthcoming F1 PR, which hoists the slot constants before the module body. The combined resolution was validated locally: 433 tests pass.bindingsbudget can drop by this PR's −773 B (node benchmarks/bundle-size/run.mjs --write-budgets octane-tsrx)..tsrxcustom hooks still copy stable dependencies to temporaries. The same in-place read could apply there.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 hook slot boundaries and memo dependency evaluation in the compiler; correctness relies on static analysis (cycles, reassignment, opaque code) though behavior is heavily tested.
Overview
Shrinks production client output for plain
.ts/.jshook modules by tightening inlineuseMemo/useCallbacklowering and dropping redundantwithSlotboundaries, without changing hook semantics.Inline memo (largest win): Compiler-appended slots are tagged (
_octaneCompilerSlot), so emitted code callsmemoSlot(slot)without the'useMemo'/'useCallback'name literal; authored/manual slots still pass the name for missing-slot errors. Never-reassigned local memo dependencies are marked_octaneStableReadand passed straight intomemoTake/memoPublishinstead of__hkdNtemporaries (imports still get temporaries). The full compiler and plain pass share the same slot/memo rules;memoSlot's name argument is optional inruntime.ts.Boundary elision (plain pass only): New analysis in
hook-deps.jsremoveswithSlotaround module-local custom-hook calls when the callee is slot-free (onlyuseContext-class hooks) or is a single-use callee of a name-only outer hook, with cycle and escape checks; signal/$hooks keep boundaries.CI / refactor:
createPlainProgramPrinteris shared by the plain memo tier and a new fidelity test that reprints admittedpackages/*/srcmodules and asserts TS/esbuild-parseable, shape-stable output.Reviewed by Cursor Bugbot for commit 3a94399. Bugbot is set up for automated code reviews on this repo. Configure here.