Skip to content

perf(octane): share one production formatter across published zero-argument errors - #1856

Merged
trueadm merged 1 commit into
mainfrom
perf/shared-error-formatter
Oct 7, 2026
Merged

trueadm merged 1 commit into
mainfrom
perf/shared-error-formatter

Conversation

@trueadm

@trueadm trueadm commented Oct 7, 2026 •

Copy link
Copy Markdown
Collaborator

Summary

  • The publish build's zero-argument error specialization (scripts/specialize-error-calls.mjs, perf: specialize zero-argument errors #1362) inlined a private __octaneNoArgError helper, with the full "Minified Octane error … or use a development build …" text, into every module it rewrote. Twenty-nine published modules carried their own copy.
  • Those modules now import formatNoArgumentErrorMessage from a new import-free src/error-message-no-arguments.ts. A consumer bundle holds the zero-argument text once, and a split application holds it in one shared chunk.
  • perf: specialize zero-argument errors #1362's contract is unchanged. Binding-only consumers still drop the generated catalog, the generic formatter (error-message.js) and its argument encoder. Development messages, production messages and the call-time NODE_ENV read are byte-identical.

Why

A production signals + hydration app audit found the formatter inlined in about 10 chunks. The duplication exists only in the published dist/. The in-repo size harness builds from source, so it never saw it.

Merging this text with the generic formatter's would leave one copy instead of two, but neither way of doing it fits:

  • Splitting formatProdErrorMessage into two functions costs about 40 B raw in every source-built bundle, which breaches every budget.
  • Routing zero-argument errors through the generic formatter would reattach the argument encoder to binding-only consumers.

Measured against the published dist/

Built with build-runtime.mjs on main 7e6bda5 and on this head. Both are measured with the same production Vite (Oxc) consumer builds. The fixture is the hydrate-frame scenario from #1855.

Consumer main head Δ
hydrate-frame, one bundle 9 copies, 376,258 B raw / 115,774 B gzip 2 copies, 374,901 / 115,592 −1,357 raw / −182 gzip
Same app lazily importing octane/behavior, octane/signals, octane/hydration, octane/dom-bindings and octane/hydration/streamed-signals (19 chunks) 22 copies in 10 chunks, 488,622 / 156,982 (sum of per-chunk gzip) 2 copies in 1 chunk, 484,960 / 155,877 −3,662 raw / −1,105 gzip
Compiled binding consumer (published-errors.test.mjs) 5 copies 1 copy

Bundle-size gate

The size harness builds the runtime from source, where this change only adds a module nothing imports. Both gates were run in CI mode, with BUDGET_BASE=origin/main and --budgets --ratchet, and both exit 0 with every bundle byte-identical to main. For example, hydrate-root is 137,671 / 44,037 B, deferred-hydration 230,935 / 72,354 B and binding-radix-vite 199,075 / 62,491 B (raw / gzip); the apps are rows 34,396, todo 37,297, chat 36,648, weather 42,873 and bindings 108,408 B framework gzip. No budget changes. The saving appears only in published builds, which the table above measures.

Validation

  • pnpm error-codes:check: catalog check plus 16 node --test cases, including a new nested-module case that resolves the import relative to signals/. Every zero-argument client and server code still formats exactly formatProdErrorMessage(code, []) in production.
  • node packages/octane/scripts/build.mjs (dist, declarations, verifyDist, smokeDist, published-errors.test.mjs): 3/3 passed. CI runs the same through packages:pack:check → prepack.
  • Regression check: with main's specializer, the new assertion in published-errors.test.mjs fails, because the compiled binding consumer carries 5 copies (actual: 5, expected: 1).
  • pnpm typecheck:files and pnpm format:files:check on the changed files.
  • pnpm test, pnpm typecheck and pnpm format:check were not run locally; CI runs them.

Risk / follow-ups

  • Each rewritten module gains one relative import (./ or ../error-message-no-arguments.js). verifyDist checks that every emitted relative import resolves, and the specializer derives the path from the module's location under src/.
  • The CommonJS tree bundles each entry, so each CommonJS entry keeps its own copy, as before.

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

Low Risk
Build-time publish transform only; error messages and NODE_ENV semantics are locked by existing and new tests, with only added relative imports in emitted modules.

Overview
Published zero-argument error modules no longer each inline ~190 bytes of the “Minified Octane error” production string. The publish specializer (specialize-error-calls.mjs) now swaps the generic formatter import for a relative import of new formatNoArgumentErrorMessage in error-message-no-arguments.ts, so consumers dedupe that text to one shared module (at most two copies in a bundle alongside the generic formatter for parameterized errors).

Runtime behavior is unchanged: development vs production branching and message text still match formatProdErrorMessage(code, []). Tests add a nested-module relative-import case and assert compiled binding bundles contain a single “Minified Octane error #” occurrence.

Reviewed by Cursor Bugbot for commit 570eca0. Bugbot is set up for automated code reviews on this repo. Configure here.

…gument errors

The publish-time error specialization inlined a private __octaneNoArgError
helper, carrying the full "Minified Octane error" text, into each of the 29
modules it rewrote. A consumer bundle carried one copy per such module, and
a code-split application one in every chunk that included any of them.

Rewritten modules now import formatNoArgumentErrorMessage from the new
import-free src/error-message-no-arguments.ts. Messages, the call-time
NODE_ENV read and #1362's binding-only contract (no generic formatter, no
argument encoder) are unchanged. error-message.ts is untouched, so
source-built bundles are byte-identical.

Published dist, hydrating signals app: 9 copies -> 2 (-1,357 raw); split
into 19 chunks: 22 copies in 10 chunks -> 2 in one (-3,662 raw, -1,105 gzip).

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@trueadm
trueadm marked this pull request as ready for review October 7, 2026 19:30
@github-actions github-actions Bot added agent-authored Diff or issue body substantially produced by an AI agent perf PR: performance work labels Oct 7, 2026
@cloudflare-workers-and-pages

cloudflare-workers-and-pages Bot commented Oct 7, 2026 •

Copy link
Copy Markdown

Deploying with  Cloudflare Workers  Cloudflare Workers

The latest updates on your project. Learn more about integrating Git with Workers.

Status Name Latest Commit Preview URL Updated (UTC)
✅ Deployment successful!
View logs
octane-website 570eca0 Commit Preview URL

Branch Preview URL
Oct 07 2026, 07:33 PM

@cloudflare-workers-and-pages

cloudflare-workers-and-pages Bot commented Oct 7, 2026 •

Copy link
Copy Markdown

Deploying with  Cloudflare Workers  Cloudflare Workers

The latest updates on your project. Learn more about integrating Git with Workers.

Status Name Latest Commit Preview URL Updated (UTC)
✅ Deployment successful!
View logs
octane-website-mcp 570eca0 Commit Preview URL

Branch Preview URL
Oct 07 2026, 07:35 PM

@github-actions

github-actions Bot commented Oct 7, 2026

Copy link
Copy Markdown
Contributor

Benchmark report

🟢 No budget breaches, no added work, and no timing changes beyond ±3%.

Compares 7e6bda5ec, the merge commit's first parent with bb204579d on the same runner. A byte value over its committed budget or any increase in a js-framework work counter fails this check. Wall time is a report: base and head samples alternate in one browser, and an operation is called slower or faster only when the 95% confidence interval of its ratio excludes ±3%. Workflow run

js-framework: 1k/10k row operations

All 20 timed operations (20 without a verdict)
target operation base ms head ms head/base 95% CI
octane-tsrx run 3.142 3.150 −3.3% −9.1% … −1.6% ⚪ within noise
octane-tsrx replace 7.683 7.492 ±0.0% −2.1% … +3.1% ⚪ within noise
octane-tsrx add 3.358 3.383 +2.9% −3.1% … +8.8% ⚪ within noise
octane-tsrx update 0.137 0.134 +0.3% −5.8% … +4.6% ⚪ within noise
octane-tsrx select 0.007 0.007 +1.4% −1.0% … +8.3% ⚪ within noise
octane-tsrx swap 0.036 0.037 ±0.0% −1.5% … +2.1% ⚪ within noise
octane-tsrx remove 0.018 0.020 +4.1% −0.4% … +15.8% ⚪ within noise
octane-tsrx runlots 32.408 30.725 +0.2% −4.6% … +6.6% ⚪ within noise
octane-tsrx select_lots 0.008 0.008 −0.4% −3.5% … +12.4% ⚪ within noise
octane-tsrx clear 67.025 65.283 −3.7% −11.4% … +0.6% ⚪ within noise
octane-jsx run 5.092 4.417 −0.6% −12.0% … +3.0% ⚪ within noise
octane-jsx replace 11.992 10.583 −1.5% −12.2% … +6.6% ⚪ within noise
octane-jsx add 4.350 4.400 −0.8% −4.9% … +7.5% ⚪ within noise
octane-jsx update 0.290 0.289 +1.8% −0.7% … +3.6% ⚪ within noise
octane-jsx select 0.158 0.162 −3.1% −5.3% … +0.6% ⚪ within noise
octane-jsx swap 0.318 0.333 +3.2% −4.5% … +13.0% ⚪ within noise
octane-jsx remove 0.237 0.250 −2.5% −6.3% … +12.4% ⚪ within noise
octane-jsx runlots 39.483 36.900 −1.9% −9.9% … +7.4% ⚪ within noise
octane-jsx select_lots 1.960 1.903 +1.4% −2.0% … +4.9% ⚪ within noise
octane-jsx clear 62.942 63.575 −1.2% −6.7% … +2.8% ⚪ within noise

All 64 work counters are unchanged.

Application bundle size (bytes)

No changes across 60 measured values.

Public-import reachability bundles (bytes)

No changes across 108 measured values.

@trueadm
trueadm merged commit 0f3abca into main Oct 7, 2026
50 of 53 checks passed
@trueadm
trueadm deleted the perf/shared-error-formatter branch October 7, 2026 20:08
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