Skip to content

perf(hydration): measure shell overhead, retain server ranges and opt in native seeds - #2033

Merged
domgan-oai merged 2 commits into
octanejs:mainfrom
openai-oss-forks:feat/hydration-cursor-2028
Oct 13, 2026
Merged

domgan-oai merged 2 commits into
octanejs:mainfrom
openai-oss-forks:feat/hydration-cursor-2028

Conversation

@domgan-oai

@domgan-oai domgan-oai commented Oct 13, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Hydrating the production shell currently costs 23,280 B gzip beyond its createRoot twin. This implements the measurement and first safe reductions for #2028: add reported-only shell_client_ twins, opt in native seed materialization/early capture only for signal hydration, retain adopted server anchors rather than walking and rewriting the complete owner tree after hydration, and share marker parsing with streaming.

This PR does not close #2028. It reduces the Oxc shell hydration increment to 21,260 B, still above the ~5 kB goal. It covers measurement, signal ownership, and post-hydration compaction removal. Range lending/remainders, per-value mismatch settlement, the separate boundary retry machinery, and HydrationCapability removal remain necessary further steps. No @Try semantics are changed here.

The subsequent issue breakdown confirms full marker unification must precede the capability collapse, and boundary retries should follow #2029. Retaining adopted anchors alone does not remove the current framed/unframed/lent adoption distinctions.

complete JS, gzip B Oxc base Oxc head esbuild base esbuild head
Octane hydrate shell 125,020 123,000 130,411 128,705
Octane createRoot twin 101,740 101,740 114,067 114,142
Increment 23,280 21,260 16,344 14,563

React 19.3 controls remain unchanged (Oxc 65 B total increment). Oxc wins 2,020 B total; esbuild hydrate wins 1,706 B but its createRoot bundle grows 75 B. Measurements use the same shell fixture, Vite config, and exact base runtime snapshot d37bd28, with provenance assertions for the base modules.

Decisions: retain SSR's explicit anchors (option B); keep liteRanges because suspended replay still reads them; keep generic immutable initialDocumentSignals snapshot before an engine import. Signals register availability in the renderer-free protocol; only hydrating runtime paths activate the native parser and early capture bridge, before or after a signal module loads. This keeps Node-only engine consumers DOM-free and tiny scalar and createRoot consumers free of hydration setup. Late retry validation is inside the root transaction and all late/deferred seed materialization validates the root's expected document scope. Positional use() seed decoding is independent of native signals.

Validation

  • Full repository formatting passed in CI at 4c3c715. Local config still cannot load svelte/compiler; changed files also passed locally with repository TS options and @tsrx/prettier-plugin.
  • Full pnpm typecheck passed in CI at 4c3c715, including strict Three and no-DOM engine consumers. Scoped core typecheck also passed locally.
  • All four Node 24 repository test shards, React parity shards, browser/ordinary client work gates, integrations, and package validation passed in CI at 4c3c715. Full run (27/27). PR benchmark report passed at the same head.
  • targeted tests: real Vitest dev and prod hydration run 16,086/16,096 initially passed; the 10 failures across four project files were only legacy compaction-count assertions. Those test files now check adopted nodes/content plus complete cleanup, and the targeted rerun passed 38/38 across both projects. Nested-wrapper adoption 16/16; native signal late import/unmount 4/4 including dev/prod built bundles; disabling signal seed lookup turns both adoption cases red and restoration returns them green.
  • Final signal load-order graph: Node-only signals and strict Three tsconfig typechecks; scoped core typecheck; 396/396 tests across dev/prod/Node covering native seeds, initialDocumentSignals, lazy imports and early input capture.
  • CI regression repros fixed without relaxing gates: scalar handle casts now retain 0 general-only bytes; canonical run-hydration-free.mjs passes all 14 client-only scenarios and three positive controls, including createRoot-signals esbuild and Vite. hydrate-root and hydrate-frame gates pass.
  • node --test benchmarks/pr-report.test.mjs benchmarks/size-review.test.mjs scripts/bundle-size-workflow.test.mjs: 35/35.
  • node benchmarks/bundle-size/run.mjs octane-jsx, matched Octane/React shell builds (Oxc and esbuild); node benchmarks/bundle-size/run-minimal.mjs hydrate-root hydrate-frame.
  • node benchmarks/hydration-range-compaction/run.mjs 5: 64/512 wrappers pass adopted leaf, live click, server anchor retention, full unmount. Comment counts are kept in this benchmark, outside consumer tests.
  • node benchmarks/app-frame-hydration/run.mjs 10 --base=<exact-base-snapshot>: real Chromium 4x CPU, 1,156 elements adopted and 1,653 blocks/renders unchanged in both scenarios; cold head/base ratios 0.836 (95% 0.816–0.860) frame and 0.870 (0.819–0.905) live sections. Warm 0.761/0.756. Jitless production calls down 61,092 in each. Same SSR bytes, live signals/events, clean unmount.
  • Complete pnpm sync: ran immediately before publication and included all resulting changes. Generation through bindings, package inventory and parity lockfiles reports current; remaining sync is blocked on importing svelte/compiler in the repository's Prettier config. Frozen install with registry failed on locked legacy-javascript metadata and Svelte 5.57.2 HTTP 403. No lockfile/security configuration changes were made. Validate in CI with a complete install.

Risk / follow-ups

Current-head CI and benchmarks are green. Full local sync remains incomplete as described above; it still needs a machine with the locked Svelte dependency. Additional explicit server comments are retained; their memory cost is offset by removal of the compaction graph in the measured frame. Legacy counted pairs are still accepted for existing binding/stream protocols. Changeset is patch because the public API and hydration contracts are unchanged. This is an initial measured part of #2028, not the complete architecture rewrite.

Related open PRs: #2035 separately removes server-only signal seed serialization from client bundles. Both edit signals/engine.ts, signals/native-read-seeds.ts and signals/read-protocol.ts, so integrate those edits and rerun the signal/bundle suites if it lands first. #2032 adds a multi-chunk Rolldown shell to run-minimal; this PR adds matched hydrateRoot/createRoot twins to run.mjs. They share only benchmarks/README.md and answer different measurement questions.

Provenance

  • An agent produced this diff (agent-authored)

Origin: Codex task · host com-79386.


View with [code]smith Autofix with [code]smith
Need help on this PR? Tag @codesmith-bot with what you need.


Note

Medium Risk
Core hydration and native-signal adoption paths changed (range retention replaces compaction), though the public API is unchanged and behavior is heavily regression-tested.

Overview
Hydration no longer runs a post-pass that merged nested server range markers — the large coalesceHydratedRanges path, hasAdjacentRangePair, and end-of-hydration coalesce() calls are removed. Adopted SSR comment pairs and their runtime owners stay in place through hydration and updates.

Native signal seed work is opt-in via the signals module: nativeSignalHydration flips on when the engine loads; ownNativeAdoption can defer manifest parsing until then; initialDocumentSignals snapshots when signals are absent. Root hydration wires early signal hydration through startEarlySignalHydration instead of always materializing native manifests at entry.

Benchmarking adds shell_client_* bundle-size rows (same app shell via createRoot + index-client.html) so PRs can report hydrate-minus-client JS overhead; the hydration-range benchmark now asserts retained physical pairs instead of compaction to one pair.

Tests drop compaction-count expectations in favor of adopted nodes, edited fields/refs, and clean unmount; marker multiplicity parsing moves to stream-protocol for shared streaming/hydration behavior.

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

@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
@domgan-oai
domgan-oai marked this pull request as ready for review October 13, 2026 10:24
@github-actions

Copy link
Copy Markdown
Contributor

Benchmark report

  • 🔴 bundle-size: 5 value(s) increased
  • 🔴 bundle-reachability: 2 value(s) increased

Compares d37bd284d, the merge commit's first parent with 787dd5034 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 4.008 3.717 +2.1% −3.4% … +6.8% ⚪ within noise
octane-tsrx replace 8.442 8.667 +1.1% −4.2% … +6.3% ⚪ within noise
octane-tsrx add 2.992 2.967 −1.7% −7.0% … +6.1% ⚪ within noise
octane-tsrx update 0.138 0.133 +0.8% −5.3% … +6.6% ⚪ within noise
octane-tsrx select 0.007 0.007 +1.7% −0.0% … +3.3% ⚪ within noise
octane-tsrx swap 0.020 0.021 +3.4% +2.1% … +7.5% ⚪ within noise
octane-tsrx remove 0.018 0.018 −2.3% −6.7% … −1.4% ⚪ within noise
octane-tsrx runlots 24.958 24.867 −0.4% −2.9% … +4.2% ⚪ within noise
octane-tsrx select_lots 0.008 0.007 −1.7% −5.0% … +4.9% ⚪ within noise
octane-tsrx clear 47.683 45.925 −1.9% −7.9% … +0.5% ⚪ within noise
octane-jsx run 3.383 3.350 +1.4% ±0.0% … +3.1% ⚪ within noise
octane-jsx replace 6.242 6.317 ±0.0% −2.3% … +2.4% ⚪ within noise
octane-jsx add 3.217 3.358 +3.0% −0.0% … +6.5% ⚪ within noise
octane-jsx update 0.252 0.255 −1.3% −3.0% … +0.9% ⚪ within noise
octane-jsx select 0.128 0.129 −0.3% −1.4% … +0.3% ⚪ within noise
octane-jsx swap 0.168 0.168 ±0.0% −1.0% … +0.5% ⚪ within noise
octane-jsx remove 0.162 0.159 −0.9% −1.9% … ±0.0% ⚪ within noise
octane-jsx runlots 26.658 29.925 +1.9% −0.5% … +3.6% ⚪ within noise
octane-jsx select_lots 1.427 1.470 +3.9% +2.1% … +5.9% ⚪ within noise
octane-jsx clear 43.825 46.317 +6.4% +1.5% … +9.2% ⚪ within noise

All 64 work counters are unchanged.

Application bundle size (bytes)

target metric base head Δ
octane-tsrx wayfinder_js_raw 464,816 459,987 −4,829 (−1.0%) 🟢
octane-tsrx wayfinder_js_gzip 150,990 149,391 −1,599 (−1.1%) 🟢
octane-tsrx wayfinder_js_brotli 130,842 129,474 −1,368 (−1.0%) 🟢
octane-tsrx pagecraft_esbuild_js_raw 590,740 591,071 +331 (+0.1%) 🔴
octane-tsrx pagecraft_esbuild_js_gzip 188,649 188,776 +127 (+0.1%) 🔴
octane-tsrx pagecraft_esbuild_js_brotli 159,532 159,602 +70 (+0.0%) 🔴
octane-tsrx full_fw_raw 577,747 568,834 −8,913 (−1.5%) 🟢
octane-tsrx full_fw_gzip 174,796 172,158 −2,638 (−1.5%) 🟢
octane-tsrx full_fw_brotli 146,958 145,017 −1,941 (−1.3%) 🟢
octane-jsx shell_js_raw 398,694 392,280 −6,414 (−1.6%) 🟢
octane-jsx shell_js_gzip 125,051 123,035 −2,016 (−1.6%) 🟢
octane-jsx shell_js_brotli 106,542 105,105 −1,437 (−1.3%) 🟢
octane-jsx shell_app_gzip 765 770 +5 (+0.7%) 🔴
octane-jsx shell_app_brotli 656 668 +12 (+1.8%) 🔴
octane-jsx shell_fw_raw 397,601 391,187 −6,414 (−1.6%) 🟢
octane-jsx shell_fw_gzip 124,286 122,265 −2,021 (−1.6%) 🟢
octane-jsx shell_fw_brotli 105,886 104,437 −1,449 (−1.4%) 🟢
octane-jsx shell_client_js_raw – 326,214 – 🆕
octane-jsx shell_client_js_gzip – 101,755 – 🆕
octane-jsx shell_client_js_brotli – 87,793 – 🆕
octane-jsx shell_client_app_raw – 1,101 – 🆕
octane-jsx shell_client_app_gzip – 768 – 🆕
octane-jsx shell_client_app_brotli – 663 – 🆕
octane-jsx shell_client_fw_raw – 325,113 – 🆕
octane-jsx shell_client_fw_gzip – 100,987 – 🆕
octane-jsx shell_client_fw_brotli – 87,130 – 🆕
octane-jsx full_fw_raw 577,747 568,834 −8,913 (−1.5%) 🟢
octane-jsx full_fw_gzip 174,796 172,158 −2,638 (−1.5%) 🟢
octane-jsx full_fw_brotli 146,958 145,017 −1,941 (−1.3%) 🟢

64 other measured values are unchanged.

Public-import reachability bundles (bytes)

target metric base head Δ
hydrate-root raw 118,834 108,731 −10,103 (−8.5%) 🟢
hydrate-root gzip 38,760 35,766 −2,994 (−7.7%) 🟢
hydrate-root brotli 34,129 31,676 −2,453 (−7.2%) 🟢
deferred-hydration raw 199,963 191,201 −8,762 (−4.4%) 🟢
deferred-hydration gzip 63,746 61,094 −2,652 (−4.2%) 🟢
deferred-hydration brotli 55,304 53,249 −2,055 (−3.7%) 🟢
hydrate-frame raw 348,219 343,339 −4,880 (−1.4%) 🟢
hydrate-frame gzip 110,168 108,745 −1,423 (−1.3%) 🟢
hydrate-frame brotli 94,533 93,421 −1,112 (−1.2%) 🟢
binding-base-ui-esbuild brotli 61,302 61,271 −31 (−0.1%) 🟢
binding-aria-esbuild gzip 3,141 3,139 −2 (−0.1%) 🟢
binding-aria-esbuild brotli 2,810 2,808 −2 (−0.1%) 🟢
binding-radix-esbuild gzip 70,377 70,378 +1 (+0.0%) 🔴
binding-radix-esbuild brotli 61,258 61,167 −91 (−0.1%) 🟢
binding-mantine-hooks-esbuild brotli 23,563 23,540 −23 (−0.1%) 🟢
binding-apollo-client-esbuild gzip 116,890 116,889 −1 (−0.0%) 🟢
binding-apollo-client-esbuild brotli 102,217 102,153 −64 (−0.1%) 🟢
binding-usehooks-ts-esbuild gzip 26,455 26,456 +1 (+0.0%) 🔴
binding-usehooks-ts-esbuild brotli 23,743 23,742 −1 (−0.0%) 🟢

92 other measured values are unchanged.

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.

Hydration: collapse the hydration engine back into the mount path (Ripple/Svelte-style cursor), 23 kB → ~5 kB gzip

1 participant