Repository navigation
perf(octane): drop dead module-load work from server and universal bundles - #1662
Merged
Merged
Conversation
…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]>
trueadm
marked this pull request as ready for review
October 3, 2026 10:30
Contributor
Benchmark report🟢 No size increases and no timing regressions outside noise. Compares js-framework: 1k/10k row operations (ms, lower is better)All 20 timed operations (20 within noise)
Application bundle size (bytes)No changes across 45 measured values. Public-import reachability bundles (bytes)
99 other measured values are unchanged. |
This was referenced Oct 3, 2026
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]>
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
Two pieces of module-load work in
runtime.server.tswere kept in every server bundle, includingserver-hooks, which imports onlyescapeHtmlandhookSlots. Neither is read there:ASCII_ASYNC_IDENTITY_UNITSwas filled by a top-levelforloop. No bundler can drop a loop.EMPTY_SNAPSHOT_LIST = Object.freeze([]). Bundlers cannot proveObject.freezepure.universal-core.tshad the sameObject.freezeproblem with five constants:UNIVERSAL_LAZY_METADATA,UNIVERSAL_CONTEXT_METADATA,EMPTY_STATIC_HOST_PROPS,EMPTY_STATIC_PROP_NAMESandUNIVERSAL_FORM_STATUS. A scan of the client scenarios showsruntime.tshas none of these left. It lists the top-level expression statements in unminified Vite builds of every non-binding scenario.Changes
/* @__PURE__ */ Array.from({ length: 128 }, …).encodeAsyncIdentityStringis unchanged, and V8 still makes it a packed array (%HasHoleyElementsis false, as for the push loop).Array.fromis −2.EMPTY_SNAPSHOT_LISTand the five universal-core constants get a/* @__PURE__ */annotation. Identity and frozenness are unchanged: each is still one module-level value.run-minimal.mjsassertion, keyed on a stable export signal:.toString(16).padStart(4,"0")formatting exactly whenruntime.server.tsrendersencodeAsyncIdentityString, the table's only reader.server-renderis the control: it must render the encoder.Bytes
node benchmarks/bundle-size/run-minimal.mjs server-hooks server-render hooks-state, on maine93bb26cccvs this branch (raw / gzip / brotli):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, andArray.fromis the smaller one.For universal-core I built two throwaway Vite probes. Importing only
hookSlotsfromoctane/universaldrops from 390 to 179 raw. AcreateUniversalRoot+ object driver bundle drops by 65 raw / 29 gzip; onlyUNIVERSAL_FORM_STATUSwas dead there.Validation
pnpm format:check: not run repo-wide. Scopedpnpm format:files:checkpasses on all changed files.pnpm typecheck: not run repo-wide. Scopedpnpm typecheck:filespasses on both source files.pnpm test: not run in full.octaneandoctane-prodprojects separately, 197/197 in each:ssr-async-identity-encoding,ssr-async-identity-surrogate-regression,parallel-use,universal-renderer,universal-props.true !== falseand passes on this branch.length: 127), the existingssr-async-identity-encoding.test.tsfails (expected 'undefined' to be '007f'). The rewritten construction is covered behaviorally.Object.freeze(...) as never[]andArray.from(...)are dropped when unused and kept when used, matching Rolldown.pnpm syncproduced no changes.Risk / follow-ups
@__PURE__annotation only lets a bundler drop a call whose result is unused.octane/reacthas similar module-levelObject.freezeconstants (react/shared.ts,react/react-compat*.ts). I did not look at them.Provenance
agent-authored)🤖 Generated with Claude Code
Need help on this PR? Tag
@codesmith-botwith 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-levelforloop, andEMPTY_SNAPSHOT_LISTgets the same pure annotation onObject.freeze. In universal-core, five frozen sentinels (lazy/context metadata, empty static props, defaultuseFormStatusresult) are annotated the same way. Runtime behavior when those values are still referenced is unchanged; bundles that only import things likeescapeHtmlcan drop the table and frozen constants.run-minimal.mjsnow asserts that server output includes the encoder’s.toString(16).padStart(4, '0')pattern exactly whenencodeAsyncIdentityStringis still exported (withserver-renderas the positive control). Reported wins:server-hooks~571→477 bytes raw; universal entries that never calluseFormStatus~65 bytes raw.Reviewed by Cursor Bugbot for commit 668edf6. Bugbot is set up for automated code reviews on this repo. Configure here.