Skip to content

perf(compiler): shrink plain-module hook boundaries and inline memo lowering - #1634

Merged
trueadm merged 1 commit into
mainfrom
perf/plain-hook-boundary-size
Oct 3, 2026
Merged

trueadm merged 1 commit into
mainfrom
perf/plain-hook-boundary-size

Conversation

@trueadm

@trueadm trueadm commented Oct 3, 2026 •

Copy link
Copy Markdown
Collaborator

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/.js hook modules. #1546 added a withSlot boundary 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)

  • memoSlot receives the hook name only for an authored slot, which a manual hook may leave undefined. A slot the compiler appended always resolves, so memoSlot(_h$0, 'useMemo') becomes memoSlot(_h$0).
    • The full compiler marks its appended slots too, which covers .tsrx custom hooks and the native auto-calculation region.
    • runtime.ts: name becomes optional. 0 bytes.
  • In plain modules, a memo dependency that is a never-reassigned local binding is read in place instead of through a __hkdN temporary.
  • The tier's admission and print move into createPlainProgramPrinter. The tier and the new fidelity test share it.

Fidelity test: tests/compiler/plain-hook-memo-fidelity.test.ts

  • Reprints every Octane module in packages/*/src that the printer admits.
  • Compares TypeScript syntax trees, ignoring only parentheses, { a } versus { a: a }, export { a as a }, and empty statements in statement lists.
  • Requires TypeScript and esbuild to parse the output.
  • Today all 127 packages pass. With the misprint guard disabled, 8 packages fail. That covers fix(compiler): inline plain-module memos beside parent-printed syntax #1577's "commit the audit" follow-up, so an esrap gap or upgrade fails CI instead of shipping to production only.

F3: local-hook boundary elision (hook-deps.js, plain pass only)

  • A call to a module-declared hook gets no boundary in two cases:
    • (a) The hook reads no slot. Through the module's own functions it calls nothing but useContext and other such hooks, and it constructs nothing.
    • (b) The call is the hook's only use, made directly in the body of another local hook that is used only by name (declaration, export, or direct calls), and the omitted calls form no cycle.
  • In both cases each omitted call runs at most once per enclosing slot path, exactly as it would with its boundary.
  • Signal-reading modules and $ 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/.js module in packages/*/src, examples/*/src and website/src (1,768 modules), base 27c2a12:

Tier Modules changed Min Gzip withSlot
Inline (production client default) 294 817,699 → 806,374 (−11,325) 351,911 → 345,923 (−5,988) −37
Surgical 21 76,095 → 75,260 (−835) 31,666 → 31,299 (−367) −37

In 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:

Variant bindings_app gzip raw brotli
main 122,497 358,410 102,475
this PR 121,724 (−773) 355,921 (−2,489) 101,693 (−782)
this PR without F3 121,731 (−766) 355,986 101,848

The framework chunk is unchanged at 119,125 B gzip.

Existing bundle rows: run-minimal.mjs hooks-state, binding-hooks and binding-vanilla are byte-identical. binding-apollo-client changes as follows:

Build Raw Gzip Brotli
vite −22 −15 +81
esbuild −22 −10 −42

.tsrx: the 16-file codegen corpus (benchmarks/compiler-output/corpus.mjs, client and server, also with inlineHookMemo) is byte-identical. Its components use the flat memo cache. A .tsrx custom hook with useMemo/useCallback drops 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:

apollo-client-vite brotli vs main
this PR +120
without the in-place dependency reads −26
without the memoSlot name drop +7
without F3 (F3 doesn't touch this row) +120
  • No single component causes the apollo-client-vite increase; it appears only when both are combined.
  • usehooks-ts (+28 vite, +18 esbuild) comes entirely from removing one 6-byte dependency temporary.
  • On the binding-heavy app above, brotli drops by 782 B.

Validation

  • pnpm format:check: not run repo-wide. pnpm format:files:check passes on every changed file.
  • pnpm typecheck: not run repo-wide. packages/octane/tsconfig.json excludes tests, and typecheck:files reports only the usual TS7016 on untyped compiler .js imports.
  • pnpm test: not run locally, because the machine is shared with other sessions. CI is the gate.
  • targeted tests, after rebasing onto 11a9da9:
    • 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.
    • Earlier on this change, before the rebase:
      • octane, 28 related compiler/runtime files.
      • octane-signals: signals-memos, signals-native-plain-module, signals-hook-declarations.
      • octane-signals-node: signals-state.
      • auto-calculation in octane and octane-prod.
  • Each new test fails when its rule is removed:
    • Without the cycle check, two hooks that only call each other share state across recursion depth.
    • Without the caller-escape check, a hook re-entered through a function value shares state.
    • Treating a reassigned dependency as stable recomputes a hit.
    • Dropping the name for every slot loses useMemo/useCallback from the missing-slot error.
    • Disabling the misprint guard fails the fidelity test in 8 packages.
  • pnpm sync: no changes.

Risk / follow-ups

  • F3 earns little. It is about 190 lines of analysis for 37 boundaries; on the binding bundle it adds only −7 B gzip on top of F4, because gzip already compresses the repeated wrappers well. The review's looser rules would reach about 24% of boundaries, but they let a hook re-entered through a function value, or through a non-hook helper, share state, so they are not taken. Dropping F3 from this PR is a reasonable call. The F4 and fidelity parts stand alone.
  • Not analyzed: F3 does not follow implicit calls such as accessors, coercions or iterators. A hook reached only through one already has no call site of its own to key.
  • Out of scope: a value use of an exported caller from another module, synchronously re-entered from inside the omitted hook, is not modeled.
  • The fidelity test parses about 1,800 modules, 12–15 s on a loaded machine. It runs in the node environment, because esbuild's TextEncoder check fails under jsdom.
  • Conflict: this touches the same lines in plain-hook-memo.js (allocateHookSlot) and external-hook-slot.test.ts as the forthcoming F1 PR, which hoists the slot constants before the module body. The combined resolution was validated locally: 433 tests pass.
  • Bench row: the binding-heavy row is owned by the bench-gates PR. Once its budgets land, the bindings budget can drop by this PR's −773 B (node benchmarks/bundle-size/run.mjs --write-budgets octane-tsrx).
  • Follow-up: .tsrx custom hooks still copy stable dependencies to temporaries. The same in-place read could apply there.

Provenance

  • An agent produced this diff (agent-authored)

🤖 Generated with Claude Code


View with [code]smith Autofix with [code]smith
Need help on this PR? Tag @codesmith-bot with 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/.js hook modules by tightening inline useMemo/useCallback lowering and dropping redundant withSlot boundaries, without changing hook semantics.

Inline memo (largest win): Compiler-appended slots are tagged (_octaneCompilerSlot), so emitted code calls memoSlot(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 _octaneStableRead and passed straight into memoTake/memoPublish instead of __hkdN temporaries (imports still get temporaries). The full compiler and plain pass share the same slot/memo rules; memoSlot's name argument is optional in runtime.ts.

Boundary elision (plain pass only): New analysis in hook-deps.js removes withSlot around module-local custom-hook calls when the callee is slot-free (only useContext-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: createPlainProgramPrinter is shared by the plain memo tier and a new fidelity test that reprints admitted packages/*/src modules 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.

…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]>
@github-actions github-actions Bot added agent-authored Diff or issue body substantially produced by an AI agent perf PR: performance work labels Oct 3, 2026
@github-actions
github-actions Bot marked this pull request as draft October 3, 2026 07:33
@github-actions

github-actions Bot commented Oct 3, 2026

Copy link
Copy Markdown
Contributor

Benchmark report

  • 🔴 bundle-reachability: 3 value(s) increased

Compares 11a9da935 with c155f0483 on the same runner. Timing verdicts require a change beyond the combined margin of error (at least 5%) and one 0.1ms timer tick, with the fastest sample also moving beyond that margin. Workflow run

js-framework: 1k/10k row operations (ms, lower is better)

All 20 timed operations (20 within noise)
target operation base head Δ noise
octane-tsrx run 3.58 3.65 +2.0% ±20% ⚪ within noise
octane-tsrx replace 8.89 8.14 −8.4% ±46% ⚪ within noise
octane-tsrx add 3.63 3.56 −1.9% ±16% ⚪ within noise
octane-tsrx update 0.57 0.51 −10.5% ±58% ⚪ within noise
octane-tsrx select 0.18 0.20 +11.1% ±75% ⚪ within noise
octane-tsrx swap 0.47 0.40 −14.9% ±56% ⚪ within noise
octane-tsrx remove 0.42 0.45 +7.1% ±41% ⚪ within noise
octane-tsrx runlots 31.42 31.59 +0.5% ±15% ⚪ within noise
octane-tsrx select_lots 0.27 0.28 +3.7% ±41% ⚪ within noise
octane-tsrx clear 46.89 47.72 +1.8% ±10% ⚪ within noise
octane-jsx run 3.64 3.63 −0.3% ±28% ⚪ within noise
octane-jsx replace 8.15 8.01 −1.7% ±11% ⚪ within noise
octane-jsx add 3.36 3.39 +0.9% ±14% ⚪ within noise
octane-jsx update 0.66 0.70 +6.1% ±35% ⚪ within noise
octane-jsx select 0.41 0.50 +22.0% ±28% ⚪ within noise
octane-jsx swap 0.74 0.73 −1.4% ±29% ⚪ within noise
octane-jsx remove 0.63 0.70 +11.1% ±29% ⚪ within noise
octane-jsx runlots 31.10 29.56 −5.0% ±11% ⚪ within noise
octane-jsx select_lots 2.73 2.73 −0.0% ±23% ⚪ within noise
octane-jsx clear 51.08 50.11 −1.9% ±8% ⚪ within noise

Application bundle size (bytes)

target metric base head Δ
octane-tsrx weather_js_raw 178,362 178,306 −56 (−0.0%) 🟢
octane-tsrx weather_js_gzip 58,358 58,348 −10 (−0.0%) 🟢
octane-tsrx weather_js_brotli 50,823 50,818 −5 (−0.0%) 🟢
octane-tsrx weather_app_raw 26,735 26,679 −56 (−0.2%) 🟢
octane-tsrx weather_app_gzip 9,044 9,034 −10 (−0.1%) 🟢
octane-tsrx weather_app_brotli 7,597 7,592 −5 (−0.1%) 🟢

39 other measured values are unchanged.

Public-import reachability bundles (bytes)

target metric base head Δ
binding-mantine-hooks-vite raw 98,028 97,874 −154 (−0.2%) 🟢
binding-mantine-hooks-vite gzip 32,600 32,520 −80 (−0.2%) 🟢
binding-mantine-hooks-vite brotli 28,917 28,897 −20 (−0.1%) 🟢
binding-mantine-hooks-esbuild raw 97,622 97,472 −150 (−0.2%) 🟢
binding-mantine-hooks-esbuild gzip 32,786 32,710 −76 (−0.2%) 🟢
binding-mantine-hooks-esbuild brotli 29,112 29,056 −56 (−0.2%) 🟢
binding-apollo-client-vite raw 358,254 358,232 −22 (−0.0%) 🟢
binding-apollo-client-vite gzip 112,253 112,239 −14 (−0.0%) 🟢
binding-apollo-client-vite brotli 97,970 98,090 +120 (+0.1%) 🔴
binding-apollo-client-esbuild raw 361,203 361,181 −22 (−0.0%) 🟢
binding-apollo-client-esbuild gzip 114,460 114,450 −10 (−0.0%) 🟢
binding-apollo-client-esbuild brotli 99,732 99,572 −160 (−0.2%) 🟢
binding-usehooks-ts-vite raw 98,661 98,655 −6 (−0.0%) 🟢
binding-usehooks-ts-vite gzip 32,764 32,761 −3 (−0.0%) 🟢
binding-usehooks-ts-vite brotli 29,090 29,118 +28 (+0.1%) 🔴
binding-usehooks-ts-esbuild raw 98,244 98,238 −6 (−0.0%) 🟢
binding-usehooks-ts-esbuild brotli 29,231 29,249 +18 (+0.1%) 🔴

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]>
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]>
@trueadm
trueadm marked this pull request as ready for review October 3, 2026 10:20
@trueadm
trueadm merged commit b319c16 into main Oct 3, 2026
35 of 36 checks passed
@trueadm
trueadm deleted the perf/plain-hook-boundary-size branch 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]>
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]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

agent-authored Diff or issue body substantially produced by an AI agent perf PR: performance work

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant