Skip to content

perf(octane): drop dead module-load work from server and universal bundles - #1662

Merged
trueadm merged 2 commits into
mainfrom
perf/server-dead-init
Oct 3, 2026
Merged

trueadm merged 2 commits into
mainfrom
perf/server-dead-init

Conversation

@trueadm

@trueadm trueadm commented Oct 3, 2026 •

Copy link
Copy Markdown
Collaborator

Summary

Two pieces of module-load work in runtime.server.ts were kept in every server bundle, including server-hooks, which imports only escapeHtml and hookSlots. Neither is read there:

  • ASCII_ASYNC_IDENTITY_UNITS was filled by a top-level for loop. No bundler can drop a loop.
  • EMPTY_SNAPSHOT_LIST = Object.freeze([]). Bundlers cannot prove Object.freeze pure.

universal-core.ts had the same Object.freeze problem with five constants: UNIVERSAL_LAZY_METADATA, UNIVERSAL_CONTEXT_METADATA, EMPTY_STATIC_HOST_PROPS, EMPTY_STATIC_PROP_NAMES and UNIVERSAL_FORM_STATUS. A scan of the client scenarios shows runtime.ts has none of these left. It lists the top-level expression statements in unminified Vite builds of every non-binding scenario.

Changes

  • ASCII table: built with /* @__PURE__ */ Array.from({ length: 128 }, …).
    • It is still built once at module load.
    • The per-code-unit lookup in encodeAsyncIdentityString is unchanged, and V8 still makes it a packed array (%HasHoleyElements is false, as for the push loop).
    • I measured a pure IIFE around the loop as an alternative. It costs +26 raw bytes wherever the table is live; Array.from is −2.
  • EMPTY_SNAPSHOT_LIST and the five universal-core constants get a /* @__PURE__ */ annotation. Identity and frozenness are unchanged: each is still one module-level value.
  • run-minimal.mjs assertion, keyed on a stable export signal:
    • A server bundle must contain the encoder's .toString(16).padStart(4,"0") formatting exactly when runtime.server.ts renders encodeAsyncIdentityString, the table's only reader.
    • server-render is the control: it must render the encoder.
    • The other constants have no export signal, so they get no assertion.

Bytes

node benchmarks/bundle-size/run-minimal.mjs server-hooks server-render hooks-state, on main e93bb26ccc vs this branch (raw / gzip / brotli):

scenario main this PR
server-hooks 571 / 391 / 332 477 / 329 / 256
server-render 64995 / 22412 / 20192 64993 / 22418 / 20255
hooks-state 88983 / 29551 / 26264 unchanged

The table is live in server-render, so that bundle only changes form there. Its compressed numbers move within noise for a ~70-byte region: +6 gzip, +63 brotli. The IIFE form measured +26 / +10 / +10. The table exists only in server bundles, which are not sent over the network, so raw size (parse cost) is the metric that matters, and Array.from is the smaller one.

For universal-core I built two throwaway Vite probes. Importing only hookSlots from octane/universal drops from 390 to 179 raw. A createUniversalRoot + object driver bundle drops by 65 raw / 29 gzip; only UNIVERSAL_FORM_STATUS was dead there.

Validation

  • pnpm format:check: not run repo-wide. Scoped pnpm format:files:check passes on all changed files.
  • pnpm typecheck: not run repo-wide. Scoped pnpm typecheck:files passes on both source files.
  • pnpm test: not run in full.
  • targeted tests, run in the octane and octane-prod projects separately, 197/197 in each: ssr-async-identity-encoding, ssr-async-identity-surrogate-regression, parallel-use, universal-renderer, universal-props.
  • The new run-minimal assertion fails on main's source with true !== false and passes on this branch.
  • With the table broken on purpose (length: 127), the existing ssr-async-identity-encoding.test.ts fails (expected 'undefined' to be '007f'). The rewritten construction is covered behaviorally.
  • esbuild transform check: a pure-annotated Object.freeze(...) as never[] and Array.from(...) are dropped when unused and kept when used, matching Rolldown.
  • pnpm sync produced no changes.

Risk / follow-ups

  • No semantic change: a @__PURE__ annotation only lets a bundler drop a call whose result is unused.
  • octane/react has similar module-level Object.freeze constants (react/shared.ts, react/react-compat*.ts). I did not look at them.

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
Annotations only affect dead-code elimination; encoding and frozen singleton semantics stay the same when exports still pull those modules in.

Overview
Marks server and universal module-init work as tree-shakeable so minimal bundles stop paying for code they never use.

On the server runtime, the ASCII async-identity lookup table is built with a /* @__PURE__ */ Array.from(...) instead of a top-level for loop, and EMPTY_SNAPSHOT_LIST gets the same pure annotation on Object.freeze. In universal-core, five frozen sentinels (lazy/context metadata, empty static props, default useFormStatus result) are annotated the same way. Runtime behavior when those values are still referenced is unchanged; bundles that only import things like escapeHtml can drop the table and frozen constants.

run-minimal.mjs now asserts that server output includes the encoder’s .toString(16).padStart(4, '0') pattern exactly when encodeAsyncIdentityString is still exported (with server-render as the positive control). Reported wins: server-hooks ~571→477 bytes raw; universal entries that never call useFormStatus ~65 bytes raw.

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

…ndles

The server runtime built its ASCII async-identity table in a top-level loop and
froze a shared empty snapshot list with Object.freeze. Bundlers cannot prove
either one free of side effects, so every server bundle kept both, including
the server-hooks bundle that only escapes HTML. universal-core had the same
problem with five frozen constants.

Build the table with a pure-annotated Array.from. It is still built once at
load, stays a packed array, and is smaller than the loop where it is live. Mark
the frozen constants pure as well.

Add a run-minimal reachability check: a server bundle contains the encoder's
code-unit formatting exactly when it renders encodeAsyncIdentityString, with
server-render as the control.

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 10:28
@trueadm
trueadm marked this pull request as ready for review October 3, 2026 10:30
@github-actions

github-actions Bot commented Oct 3, 2026

Copy link
Copy Markdown
Contributor

Benchmark report

🟢 No size increases and no timing regressions outside noise.

Compares 950ef0b0b with 03fd576e4 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.74 +4.5% ±25% ⚪ within noise
octane-tsrx replace 7.17 7.74 +7.9% ±11% ⚪ within noise
octane-tsrx add 3.43 3.40 −0.9% ±7% ⚪ within noise
octane-tsrx update 0.39 0.40 +2.6% ±41% ⚪ within noise
octane-tsrx select 0.15 0.16 +6.7% ±105% ⚪ within noise
octane-tsrx swap 0.39 0.36 −7.7% ±60% ⚪ within noise
octane-tsrx remove 0.44 0.40 −9.1% ±34% ⚪ within noise
octane-tsrx runlots 31.31 29.92 −4.4% ±13% ⚪ within noise
octane-tsrx select_lots 0.29 0.21 −27.6% ±52% ⚪ within noise
octane-tsrx clear 43.54 43.84 +0.7% ±9% ⚪ within noise
octane-jsx run 3.73 3.67 −1.6% ±14% ⚪ within noise
octane-jsx replace 7.89 7.11 −9.9% ±20% ⚪ within noise
octane-jsx add 3.36 3.21 −4.5% ±7% ⚪ within noise
octane-jsx update 0.58 0.51 −12.1% ±33% ⚪ within noise
octane-jsx select 0.42 0.37 −11.9% ±42% ⚪ within noise
octane-jsx swap 0.72 0.64 −11.1% ±35% ⚪ within noise
octane-jsx remove 0.64 0.56 −12.5% ±23% ⚪ within noise
octane-jsx runlots 29.14 28.37 −2.6% ±9% ⚪ within noise
octane-jsx select_lots 2.88 2.90 +0.7% ±48% ⚪ within noise
octane-jsx clear 45.79 46.65 +1.9% ±10% ⚪ within noise

Application bundle size (bytes)

No changes across 45 measured values.

Public-import reachability bundles (bytes)

target metric base head Δ
server-hooks raw 571 477 −94 (−16.5%) 🟢
server-hooks gzip 391 329 −62 (−15.9%) 🟢
server-hooks brotli 332 256 −76 (−22.9%) 🟢
server-render raw 65,077 65,075 −2 (−0.0%) 🟢
server-render gzip 22,432 22,431 −1 (−0.0%) 🟢
server-render brotli 20,253 20,248 −5 (−0.0%) 🟢

99 other measured values are unchanged.

@trueadm
trueadm merged commit 541ecdc into main Oct 3, 2026
48 checks passed
@trueadm
trueadm deleted the perf/server-dead-init branch October 3, 2026 11:03
trueadm added a commit that referenced this pull request Oct 4, 2026
… (#1710)

#1700 freezes a fresh root's decoded program runs so a first mount takes
the dense host record store again. That costs the main thread 141 raw
bytes: preview main gzip 83,657 -> 83,742 and IFR 89,331 -> 89,404,
both over their measured + 32 caps. The weekly-only lynx-bundle-size
gate never ran on that pull request.

Raise both caps to the new measurement + 32. Re-pin the background
program at 288,390: it shrank after the 2026-10-03 reset (#1652, #1662),
and its exact pin is the next gate in the same block. Budget values and
their comment only.

Refs #1055

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