Skip to content

perf(octane): keep server seed serialization out of client signal bundles - #2035

Merged
trueadm merged 3 commits into
mainfrom
perf/server-only-seed-serialization
Oct 13, 2026
Merged

trueadm merged 3 commits into
mainfrom
perf/server-only-seed-serialization

Conversation

@trueadm

@trueadm trueadm commented Oct 13, 2026 •

Copy link
Copy Markdown
Collaborator

Note

Paused (draft), measurements kept. Byte-tuning of signal integration is paused while #2031 (thin signals core) rewrites seeds and adoption. The measured result stays as evidence for #2031 item E: removing serializeRead from ScopeImpl keeps the server seed serializer out of client signal bundles, −2,134 raw / −486 gzip on the signals chunk with signal-free rows byte-identical.

Summary

Every client bundle that reads signals shipped the server's seed serializer. Graph sources serialized through node.owner.serializeRead(...), and ScopeImpl implemented that as a class method. A bundler cannot drop a method from a class it keeps, so serializeRead kept serializeScopeRead, scopeSeedEntry and encodeSignalValue in the client. Only the server read driver ever serializes a source.

  • Graph sources now call nativeReadSerializer (read-protocol.ts). Only createNativeServerReadDriver supplies it, the same way hydration supplies the NativeAdoptionMiss class through supplyNativeAdoptionMiss.
  • serializeScopeRead and scopeSeedEntry move unchanged from signals/engine.ts to a new signals/seed-serialization.ts, which only the engine (for the public scope.serialize()) and the server read driver import. They reach the graph through its registration (candidateGraph.assertAlive, candidateGraph.ScopedNode), so the server renderer still loads no graph in apps without signals. A first revision put them in native-read-seeds.ts, but every hydrating client imports that module, and its added imports reordered modules and moved signal-free bundles by a few bytes. The second commit splits them out, and signal-free rows are byte-identical to main again.
  • GraphOwner.serializeRead is removed. The public scope.serialize() still uses scopeSeedEntry, so apps that call it keep it.

Part of #2031 (item E, seeds and adoption): this removes serializeRead from ScopeImpl, which is half of the class move that item measures.

Bytes

After merging main at c8256d8 (#2033), against that main plus #2032's scenario:

row raw gzip
split-shell-signals 76,233 → 74,099 (−2,134) 23,530 → 23,044 (−486)
split-shell (all chunks) 417,861 → 415,727 (−2,134) 133,510 → 133,023 (−487)
split-shell-runtime 331,940 (unchanged) 105,346 → 105,347 (+1)
hydrate-frame 343,339 → 341,196 (−2,143) 108,745 → 108,242 (−503)
hydrate-root, suspense-transition unchanged unchanged

The earlier measurement against d37bd28:

node benchmarks/bundle-size/run-minimal.mjs, base d37bd284d3. The split-shell rows come from #2032's scenario, copied into both trees for the measurement:

row raw gzip brotli
split-shell-signals 76,053 → 73,919 (−2,134) 23,437 → 22,970 (−467) 21,074 → 20,678 (−396)
split-shell (all chunks) 422,740 → 420,606 (−2,134) 134,960 → 134,500 (−460) 115,978 → 115,607 (−371)
split-shell-runtime 336,999 (unchanged) 106,892 (unchanged) 90,889 → 90,912 (+23)
hydrate-frame 348,219 → 346,076 (−2,143) 110,168 → 109,668 (−500) 94,533 → 94,109 (−424)

These rows are byte-identical to base in raw and gzip: hydrate-root, deferred-hydration, suspense-transition, root-static-specialized, component-owned-effects, binding-radix-vite and binding-usehooks-ts-vite. node benchmarks/bundle-size/run.mjs octane-jsx: the signal app-shell row drops 511 gzip (125,051 → 124,540), while the rows app and the ceiling are byte-identical (54,021 and 174,796 gzip).

Validation

  • Targeted tests, all projects (octane, octane-prod, octane-signals, -signals-prod, -signals-strong, -signals-node): signals-native-seeds, signals-pending-promotion-graph, signals-hydration, hydration/direct-signal-bindings, hydration/signal-instance-identity, signals-native-collection, signals-pending-stream, signals-streams, streamed-signal-cancellation, native-read-empty-branches, signals-parallel-use, signals-deferred-values, behavior-root, signals-dom-bindings. 33 files, 1,779 tests pass.

  • Regression evidence: the preserved behavior is that server seeds reach the client and hydration adopts them. Existing suites pin it. Removing the driver's supplyNativeReadSerializer call fails 350 tests in signals-hydration, hydration/direct-signal-bindings and hydration/signal-instance-identity with nativeReadSerializer is not a function.

  • pnpm typecheck:files on the six changed modules

  • pnpm format:files:check, pnpm sync (no generated changes)

  • pnpm test: not run locally; left to CI. hydration/native-condition-demand.test.ts times out one vi.waitFor case per run on this loaded machine on both base and head, a different case each time.

  • perf-review:

    Perf review: perf/server-only-seed-serialization (d37bd28..d213d1c)

    Scan: node scripts/perf-review-scan.mjs found 2 candidates.

    Hot paths touched:

    • createGraphSource (signals/graph.ts:861): its serialize member now reads a module binding instead of calling an owner method. It runs per server serialization of an observed source, never on the client. The source literal's keys and order are unchanged.
    • createNativeServerReadDriver (native-read-server.ts:24): supplies the serializer once per driver, which is created once per server process.
    # Severity Location Dimension Finding Required evidence Provided?
    1 note packages/octane/src/signals/graph.ts:869 reachability Client bundles no longer reach the serializer through a class method. Bundle rows yes (table above)

    Dismissed candidates:

    • packages/octane/src/signals/seed-serialization.ts:53,58 [conditional-shape]: code moved verbatim from engine.ts. These are server-only wire SignalSeedEntry objects whose omitted keys are part of the JSON format. They are not hot records.

    Not checked: compiled output, which is unchanged because no compiler file changed.

  • concise-code:

    • Size: src +129 −110. One new file, signals/seed-serialization.ts, holding only the moved functions; keeping them out of native-read-seeds.ts keeps signal-free bundles byte-identical. New exports: nativeReadSerializer and supplyNativeReadSerializer (read-protocol), and scopeSeedEntry and serializeScopeRead (seed-serialization). All are moved code or have exactly one caller each.
    • Alternatives:
      • Have the server import the serializer from engine.ts. Rejected: the server renderer would load the engine and graph in apps that never create a signal.
      • Install serializeRead on ScopeImpl.prototype from the server. Rejected: the server would need a reference to ScopeImpl, which means importing the engine.
      • Folding the functions into native-read-seeds.ts. Rejected: that module's added imports reordered modules in every hydrating client (+7 to +20 raw on signal-free rows in the first CI report).

Risk / follow-ups

  • Any future consumer of NativeReadSource.serialize outside the server read driver must supply the serializer first. Today the driver's serialize is the only one, and a missing supply fails loudly with a TypeError rather than producing wrong seeds.
  • Related, separate: dead HydrationCapability members have the same class-method cause, but most can't move. Their callers are client-reachable behind hydrating guards that esbuild never folds, so moving them would grow esbuild/Rspack createRoot-only bundles. Only three methods whose sole caller is activateHydrateBoundary are being moved (~0.4 KB), in a separate session.

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.


Note

Low Risk
Refactor for bundle reachability only; serialization logic is moved unchanged and the server driver must still supply the serializer (missing supply fails loudly in tests).

Overview
Client signal bundles no longer include server-only seed serialization (~2.1 kB raw / ~0.5 kB gzip). Runtime behavior for hydration and scope.serialize() is unchanged.

Graph NativeReadSource.serialize now calls an injectable nativeReadSerializer in read-protocol.ts instead of ScopeImpl.serializeRead, which bundlers could not tree-shake off the client. createNativeServerReadDriver registers serializeScopeRead at startup via supplyNativeReadSerializer.

serializeScopeRead and scopeSeedEntry move verbatim into seed-serialization.ts (imported by the engine for public serialization and by the server driver for native reads). GraphOwner.serializeRead is removed from the owner API.

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

…dles

Every graph source named `node.owner.serializeRead(...)`, and ScopeImpl
implemented it as a class method. A bundler cannot drop a method of a class
it keeps, so every client that reads signals shipped the server's seed
serializer (serializeScopeRead, scopeSeedEntry and encodeSignalValue), although
only the server read driver ever serializes a source.

Graph sources now call a serializer that read-protocol.ts holds and only
createNativeServerReadDriver supplies, as hydration supplies the
NativeAdoptionMiss class. The serializer moves to native-read-seeds.ts beside
serializeNativeSeedReads, its only consumer, and reaches the graph through its
registration (candidateGraph), so the server renderer still loads no graph in
applications without signals. The public scope.serialize() keeps using
scopeSeedEntry from there.

A production rolldown + oxc split-chunk app's signals chunk drops 2,134 raw /
480 gzip bytes; hydrate-frame drops 2,143 / 490. Signal-free bundles are
unchanged.

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

cloudflare-workers-and-pages Bot commented Oct 13, 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 Updated (UTC)
⚠️ Deployment skipped
View logs
octane-website f2d7dd3 Oct 13 2026, 11:05 AM

@cloudflare-workers-and-pages

cloudflare-workers-and-pages Bot commented Oct 13, 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 Updated (UTC)
⚠️ Deployment skipped
View logs
octane-website-mcp f2d7dd3 Oct 13 2026, 11:05 AM

@github-actions

github-actions Bot commented Oct 13, 2026 •

Copy link
Copy Markdown
Contributor

Benchmark report

  • 🔴 bundle-size: 1 value(s) increased

Compares 5594cb06e, the merge commit's first parent (main has moved 1 commit(s) past the pull request's recorded base c8256d8a8) with ae15a4d32 on the same runner. Any increase in a js-framework work counter fails this check; byte changes are a report. 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 2.375 2.417 +1.4% ±0.0% … +4.3% ⚪ within noise
octane-tsrx replace 5.842 5.733 −1.5% −3.8% … +0.8% ⚪ within noise
octane-tsrx add 2.350 2.283 ±0.0% ±0.0% … +4.3% ⚪ within noise
octane-tsrx update 0.120 0.121 +0.8% ±0.0% … +2.3% ⚪ within noise
octane-tsrx select 0.005 0.005 +1.1% +0.5% … +1.9% ⚪ within noise
octane-tsrx swap 0.016 0.016 −1.1% −2.1% … +0.0% ⚪ within noise
octane-tsrx remove 0.014 0.013 −2.3% −6.3% … ±0.0% ⚪ within noise
octane-tsrx runlots 23.158 22.942 +0.4% −3.1% … +1.7% ⚪ within noise
octane-tsrx select_lots 0.006 0.006 +0.3% −0.6% … +1.6% ⚪ within noise
octane-tsrx clear 42.367 41.875 −1.0% −1.8% … +1.1% ⚪ within noise
octane-jsx run 3.250 3.258 ±0.0% −4.4% … +0.0% ⚪ within noise
octane-jsx replace 6.400 6.467 −2.2% −5.9% … +0.7% ⚪ within noise
octane-jsx add 3.092 3.008 −0.0% −3.2% … ±0.0% ⚪ within noise
octane-jsx update 0.252 0.240 −3.9% −5.7% … −2.4% ⚪ within noise
octane-jsx select 0.133 0.123 −2.7% −3.8% … −1.2% ⚪ within noise
octane-jsx swap 0.163 0.160 −1.1% −2.3% … +0.6% ⚪ within noise
octane-jsx remove 0.168 0.167 −2.5% −3.7% … −0.5% ⚪ within noise
octane-jsx runlots 27.542 27.350 −1.1% −3.4% … +1.8% ⚪ within noise
octane-jsx select_lots 1.424 1.425 +0.9% −1.4% … +2.2% ⚪ within noise
octane-jsx clear 45.633 46.142 −0.4% −1.5% … +0.8% ⚪ within noise

All 64 work counters are unchanged.

Application bundle size (bytes)

target metric base head Δ
octane-tsrx wayfinder_js_raw 459,987 457,842 −2,145 (−0.5%) 🟢
octane-tsrx wayfinder_js_gzip 149,391 148,908 −483 (−0.3%) 🟢
octane-tsrx wayfinder_js_brotli 129,474 129,047 −427 (−0.3%) 🟢
octane-jsx shell_js_raw 392,280 390,133 −2,147 (−0.5%) 🟢
octane-jsx shell_js_gzip 123,035 122,524 −511 (−0.4%) 🟢
octane-jsx shell_js_brotli 105,105 104,581 −524 (−0.5%) 🟢
octane-jsx shell_app_gzip 770 769 −1 (−0.1%) 🟢
octane-jsx shell_app_brotli 668 676 +8 (+1.2%) 🔴
octane-jsx shell_fw_raw 391,187 389,040 −2,147 (−0.5%) 🟢
octane-jsx shell_fw_gzip 122,265 121,755 −510 (−0.4%) 🟢
octane-jsx shell_fw_brotli 104,437 103,905 −532 (−0.5%) 🟢
octane-jsx shell_client_js_raw 326,214 324,070 −2,144 (−0.7%) 🟢
octane-jsx shell_client_js_gzip 101,755 101,223 −532 (−0.5%) 🟢
octane-jsx shell_client_js_brotli 87,793 87,408 −385 (−0.4%) 🟢
octane-jsx shell_client_app_gzip 768 765 −3 (−0.4%) 🟢
octane-jsx shell_client_app_brotli 663 661 −2 (−0.3%) 🟢
octane-jsx shell_client_fw_raw 325,113 322,969 −2,144 (−0.7%) 🟢
octane-jsx shell_client_fw_gzip 100,987 100,458 −529 (−0.5%) 🟢
octane-jsx shell_client_fw_brotli 87,130 86,747 −383 (−0.4%) 🟢

74 other measured values are unchanged.

Public-import reachability bundles (bytes)

target metric base head Δ
hydrate-frame raw 343,339 341,196 −2,143 (−0.6%) 🟢
hydrate-frame gzip 108,745 108,242 −503 (−0.5%) 🟢
hydrate-frame brotli 93,421 93,110 −311 (−0.3%) 🟢
binding-usehooks-ts-esbuild brotli 23,742 23,740 −2 (−0.0%) 🟢

107 other measured values are unchanged.

Every hydrating client imports native-read-seeds.ts, so its new imports
reordered modules and moved signal-free bundles by a few bytes (+7 raw on
root-static-specialized, +20 on binding-radix-vite). The serializer moves
to its own module that only the engine and the server read driver import;
signal-free rows are byte-identical to main again.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@trueadm
trueadm marked this pull request as draft October 13, 2026 11:09
@trueadm
trueadm marked this pull request as ready for review October 13, 2026 12:03
@trueadm
trueadm merged commit 1c7f7cb into main Oct 13, 2026
59 of 81 checks passed
@trueadm
trueadm deleted the perf/server-only-seed-serialization branch October 13, 2026 12:50
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