Skip to content

perf: trim production runtime overhead - #1356

Merged
trueadm merged 4 commits into
mainfrom
perf/prod-runtime-overhead
Sep 28, 2026
Merged

trueadm merged 4 commits into
mainfrom
perf/prod-runtime-overhead

Conversation

@trueadm

@trueadm trueadm commented Sep 27, 2026 •

Copy link
Copy Markdown
Collaborator

Summary

Four production-overhead:

  1. Hydration root recovery no longer runs dev-only diagnostics in production (5ef1af04a).
    • The problem: finishRoot and both abandonRoot callers built the dev warning's inputs, which were then thrown away by the stripped warning. Those inputs are componentSourceLoc (Function.prototype.toString over the root component) and the describeHydrationNode strings.
    • The fix: abandonRoot now takes the diagnostic as a dev-gated thunk, finishRoot gates its warning, and HydrationCapability.describe() returns '' in production so its dev-only callers stop retaining the describer.
    • Side effect: this also stops the childSlot root path from pulling componentSourceLoc into createRoot-only bundles.
  2. Delegated events with no handler on their path leave the native event alone (e99af7160).
    • The problem: once any component registers a type, every native event of that type under the root reaches both queues. That includes pointer, touch and input traffic no Octane handler can see. Each such event still read the stopPropagation descriptor, installed a patched method, restored it, and deleted currentTarget unconditionally.
    • The fix: snapshotDelegatedSlots now reports whether the phase found a handler. With none (and, for bubbling, no form action to drive), the queue skips the propagation frame.
    • The capture queue still reports "not stopped", so non-bubbling families such as play continue into their bubble queue.
  3. Native-read modules skip the read scope around empty block bodies (1383e7e5a).
    • Empty @if/@else arms compiled to begin/endNativeReadScope around try {}, entering and publishing an empty read scope on every render. A production application bundle carries six of these.
    • wrapNativeReadScope now returns an empty statement list unchanged. Module activation already enables collection.
  4. Signals, hydration and DOM-binding errors use production error codes (83dc7ec42).
    • The problem: about 250 plain-English framework messages from signals/*, hydration/* and dom-binding*.ts shipped in production, because the catalog was only enforced in runtime.ts/runtime.server.ts.
    • Codes 81–331 are added. Dev messages are byte-identical: I checked all 260 removed message literals against the catalog, including the %s concatenations.
    • The generator now enforces those paths, including Error subclasses. Shared modules use formatClientError with codes registered for both runtimes.
    • Two audited exceptions re-wrap foreign or compiler-provided message data. data-encoding.ts and most of server/* are still in English (see follow-ups).

Production bundle size (esbuild, minified, NODE_ENV=production)

Bundle origin/main gzip This PR gzip Δ
hydrateRoot consumer 84,086 83,580 −506 B
createRoot consumer 66,078 65,965 −113 B
every octane export 152,560 152,016 −544 B
client surface (index + signals + hydration + dom-binding entries), item 4 only 208,718 205,072 −3.6 KB

Deterministic work (new benchmark gates plus ratio guards)

  • event-delegation/dispatch-work, new idle target (Chromium, 3 × 15 rounds × 4,000 events):
    • 128 clicks with no handler on their path: 512 → 0 defineProperty/getOwnPropertyDescriptor calls on the Event.
    • Median idle dispatch: 2.70 → 2.43 µs.
    • Handled dispatch unchanged at 4.85 µs.
    • Guard: idleEventDefinitions.
  • compiler-output/native-read-scopes (new script, per empty-arm module):
    • Empty brackets 1 → 0; runtime scope entries over 64 cycles 448 → 320; minified 833 → 811 B.
    • Signal-driven text is asserted at every step, and a two-arm control is unchanged.
    • Guards: empty_brackets.

Validation

  • pnpm format:check
  • pnpm typecheck
  • pnpm test: package prechecks passed. The single-process vitest run hits the default heap limit locally (CI shards it), so I reran it with NODE_OPTIONS=--max-old-space-size=16384: 4,310 files and 72,091 tests passed, 2 failed. Both failures are in base-ui-pristine-browser, which runs upstream Base UI against React rather than Octane, and both are hover/pointer timing tests. Rerun 3× in isolation on this branch and on an untouched origin/main worktree, each passed 3/3.
  • targeted tests:
    • tests/hydration/mismatch-structural.test.ts: 3 new production cases failed on main (1 root-source read each) and pass now. A new dev case pins the location warnings; it went red when I disabled either dev path.
    • tests/unhandled-delegated-events.test.ts (new): native currentTarget/stopPropagation for native listeners, capture-only paths, the non-bubbling play path, and disabled controls. Sabotage checks:
      • Dropping the submitRec guard fails 11 action/submission tests.
      • Never clearing currentTarget fails the new suite.
      • A naive capture stopped expression fails the play case.
    • tests/native-read-empty-branches.test.tsrx (new): the reading arm stays reactive and unsubscribes cleanly beside empty arms. This is a preservation test: reads are also framed by the runtime, so the size and work claim lives in the ratio-guarded benchmark.
    • Event, form, action and React-conformance suites: 113 files, 2,730 tests passed.
    • node scripts/error-codes/generate.mjs --check and node --test scripts/error-codes/generate.test.mjs (5/5). The new generator test went red when the covered-path pattern was emptied.
    • pnpm ci:workflow:test (276/276) and every later lint-job step, including pnpm build. benchmarks/scoped-signals/bundle-boundaries.test.mjs now expects the coded production error Feat/playground layout #301 instead of the English "duplicate keys" text.
    • node benchmarks/bench.mjs --quick --ratios compiler-output: 18 guards, pass. node benchmarks/event-delegation/dispatch-work.mjs: gate pass.

Risk / follow-ups

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
Touches event dispatch semantics, hydration failure paths, and production error text across large runtime surfaces, though new benchmarks and tests aim to pin behavior.

Overview
This PR cuts production bundle size and hot-path work across hydration recovery, delegated events, compiled native-read scopes, and framework error formatting.

Production error codes (81–331) replace full English strings from the signal engine, hydration, and DOM-binding runtimes with Minified Octane error #<code> in production; dev messages stay the same. Catalog, CLI data, and generated formatters are extended accordingly.

Delegated events skip installing/restoring stopPropagation and currentTarget on the Event when a phase has no handler on the path (and bubbling has no form action), while capture still reports “not stopped” so non-bubbling types keep flowing. Benchmarks add an idle click target and an idleEventDefinitions ratio guard.

Compiler wrapNativeReadScope no longer wraps empty @if/@else arms, avoiding pointless read-scope entry each render; native-read-scopes.mjs and ratio guards lock this in.

Hydration (per changeset/PR context) gates dev-only root recovery diagnostics in production so bundles do not stringify root components or build mismatch descriptions.

Tests and benchmark READMEs are updated (e.g. production bundle expectations for coded duplicate-key errors).

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

trueadm and others added 2 commits September 27, 2026 21:08
finishRoot and both abandonRoot callers built the dev warning's inputs in
production: componentSourceLoc (Function.prototype.toString over the root
component) and describeHydrationNode strings, only for a stripped warning to
drop them. abandonRoot now takes the diagnostic as a dev-gated thunk,
finishRoot gates its warning, and HydrationCapability.describe returns '' in
production so its dev-only callers stop retaining the describer.

Production hydrateRoot bundle: -295 B gzip; createRoot: -111 B gzip (the
childSlot root path no longer drags componentSourceLoc into non-hydrating
bundles).

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…o handler

Once any component registers a delegated type, every native event of that
type under the root reaches the capture and bubble queues, including pointer,
touch, and input traffic that no Octane handler can see. Both queues still
read the stopPropagation descriptor, installed a patched method, and restored
it (plus an unconditional currentTarget delete) per event.

snapshotDelegatedSlots now reports whether the phase found a handler. With
none (and, for bubbling, no form action to drive) the queue leaves the native
event untouched. The capture queue keeps reporting 'not stopped' so
non-bubbling families still reach their bubble queue.

dispatch-work gains an idle-target gate: 128 idle clicks go from 512 Event
descriptor reads/definitions to 0 (ratio guard idleEventDefinitions), median
idle dispatch 2.70 -> 2.43 us, handled dispatch unchanged at 4.85 us.

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 Sep 27, 2026
@github-actions
github-actions Bot marked this pull request as draft September 27, 2026 21:27
@trueadm trueadm changed the title perf: trim production runtime overhead found in the chatgpt.com bundle audit perf: trim production runtime overhead Sep 28, 2026
@trueadm
trueadm marked this pull request as ready for review September 28, 2026 07:24
trueadm and others added 2 commits September 28, 2026 08:25
Modules that import octane/signals bracket every compiled block body with
beginNativeReadScope/endNativeReadScope. An empty @if/@else arm has no code
that can read, yet it still entered and published an empty read scope on
every render (a production application bundle ships six such bodies).
wrapNativeReadScope now returns an empty statement list unchanged; module
activation already enables collection.

compiler-output gains native-read-scopes.mjs: per empty-arm module, 1 -> 0
empty brackets, 448 -> 320 runtime scope entries over 64 cycles, 833 -> 811
minified bytes, with signal-driven text asserted at every step and a two-arm
control unchanged. Ratio guards hold empty_brackets at zero.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…uction

Production bundles shipped ~250 plain-English framework error messages from
signals/*, hydration/*, and dom-binding*.ts because the error-code catalog was
enforced only in runtime.ts and runtime.server.ts. Every framework-owned
construction in those modules now formats a catalog code (81-331); dev
messages are byte-identical, production gets the minified code.

The generator now enforces the covered paths (including Error subclasses,
checked at their construction or super() call). Shared modules use
formatClientError with codes registered for both runtimes. Two audited
exceptions re-wrap foreign or compiler-provided message data.

Production client surface (index + signals + hydration + dom-binding entries):
-3.6 KB gzip; hydrateRoot -265 B gzip.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@trueadm
trueadm force-pushed the perf/prod-runtime-overhead branch from 8234b60 to 83dc7ec Compare September 28, 2026 07:32
@trueadm
trueadm merged commit 5f58b63 into main Sep 28, 2026
30 checks passed
@trueadm
trueadm deleted the perf/prod-runtime-overhead branch September 28, 2026 10:35
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