Skip to content

perf(octane): move the hydration-only HydrationCapability methods to module functions (#2028) - #2082

Merged
trueadm merged 2 commits into
nextfrom
perf/hydration-methods-to-functions
Oct 15, 2026
Merged

trueadm merged 2 commits into
nextfrom
perf/hydration-methods-to-functions

Conversation

@trueadm

@trueadm trueadm commented Oct 15, 2026 •

Copy link
Copy Markdown
Collaborator

Summary

Why

  • Minifiers never mangle property names, so each method name ships in full at its definition and at every call site; a module function's name is mangled.
  • esbuild never folds hydrating, so a function called from code a client-only bundle keeps would ship in that bundle, where a method leaves with its class. So only methods with no client-reachable caller can move.

Changes

  • Which methods move is measured, not assumed. An esbuild bundle of every runtime export except the five that keep the class by themselves (Hydrate, __HydrateCompiled, hydrateRoot, __hydrateVoidRoot, createIndependentHydrateActivator) keeps no HydrationCapability. TypeScript's language service resolves every reference to each method through its type, and the callers of these 21 all lie outside that bundle:
    passSeeds, discardSeeds, holdDiagnostics, releaseDiagnostics, cursorIn, rendersAgain, fragmentRoots, adoptOrDefer, defer, claimDeferred, takeDeferred, hydrationFailure, thrownWhileAdopting, adopt, skipForeign, claimRoots, unclaimedText, framedContent, renderBeforeMismatch, adoptText, settleTexts.
  • The other 54 stay methods. Their callers include childSlot, componentSlotLite, the branch, list and try blocks, the host writers and useThenable. holds and awaitsCommit stay too, because they're called through HYDRATION_PASS?..
  • parseSeeds only wrapped parseSeedJson, which its two callers now call directly. holdDiagnostics and releaseDiagnostics take no capability.
  • failure becomes hydrationFailure, because a local of that name shadows it at one caller.
  • The fields the functions read drop private, which is TypeScript-only.
  • benchmarks/bundle-size/hydration-free-gates.mjs lists the 21 functions next to the class, so a createRoot bundle that maps into any of them fails the hydration-free gate.
  • Behaviour-neutral: no runtime semantics change, no changeset.

Validation

  • pnpm typecheck

  • pnpm format:check: not run repo-wide; pnpm format:files:check on both changed files passes.

  • pnpm test: not run repo-wide. The full octane, octane-prod, octane-signals, octane-signals-prod and octane-signals-strong family ran with the render-write guard:

    • 1,688 of 1,689 files pass.
    • The one failure was compiler-vite-options' wall-clock assertion (6.69 s against a 6 s limit under load). It passes in isolation, 34/34.
  • run-hydration-free on Rolldown and esbuild passes, and hydration-free-gates.test.mjs passes 11/11.

  • Survivor check: none of the 21 appears in the class-free all-exports esbuild bundle above (2,106 names, no class).

  • Hydration probe audit (scripts/hydration-probe-audit.mjs): every family 0/0 except roots, 104/104.

  • app-frame-hydration, 20 pairs against next: cold head/base 0.999, 0.990, 0.995 and 0.986 for frame, live-sections, plain and boundaries.

  • Bytes against next:

    Row Raw Gzip
    shell_ full −634 −84
    shell_ base_hydrate −634 −101
    shell_ nohydrate, base 0 0
    hydrate-root-vite −739 −125
    deferred-hydration-vite −803 −244
    hydrate-root-export-esbuild −634 −115
    every Vite and esbuild createRoot row 0 0 (create-root-export-esbuild +1)
  • perf-review: node scripts/perf-review-scan.mjs --diff on this diff finds no candidates. No hot-path changes:

    • Each converted call site trades a method dispatch for a direct call with the same arguments, on hydration-only paths.
    • No Block or Scope field changes.
    • No new runtime imports.
  • concise-code: src +496 −492 in runtime.ts (a move), plus 23 gate lines.

    • No new files or exports.
    • Alternative: convert all 75 methods, which the earlier plan estimated at −4 kB raw. Rejected: the 54 kept methods have callers that client-only bundles keep, so moving them would grow esbuild createRoot bundles.
    • Bytes: see the table above.

Risk / follow-ups

Provenance

  • An agent produced this diff (agent-authored)

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


Note

Low Risk
Behavior-neutral structural refactor on hydration-only paths; createRoot bundle size and runtime semantics are intended to stay the same per validation in the PR.

Overview
Twenty-one hydration-only HydrationCapability methods become module-level functions (passSeeds, adopt, settleTexts, hydrationFailure, etc.) that take the capability as their first argument. Call sites switch from hydration.foo() to foo(hydration, …); parseSeeds is dropped in favor of direct parseSeedJson calls. Several class fields lose private so those helpers can read pass state. This is a move-only refactor aimed at smaller hydrate bundles (mangleable function names vs fixed method names); createRoot bundles are unchanged.

The hydration-free bundle gate now lists all 21 top-level functions so a client-only build cannot accidentally retain them. render-writers.mjs tracks adoptText as a top-level writer instead of HydrationCapability.adoptText.

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

…module functions (#2028)

A method's name ships in every bundle that keeps it, since no minifier
mangles property names; a module function's is mangled. Every method that
no client-only code calls becomes a function of the capability,
`name(h, …)`, declared after the class: 21 of the 75. Client-only code is
measured, not assumed: an esbuild bundle of every runtime export but
Hydrate and the hydrateRoot entry points keeps no HydrationCapability, and
the TypeScript references of each method, resolved through its type,
place every caller of these 21 outside that bundle. The other 54, called
from childSlot, componentSlotLite, the branch, list and try blocks, the
host writers or useThenable, stay methods: esbuild never folds `hydrating`,
so a function named there would ship in client-only bundles, where a
method leaves with its class. holds and awaitsCommit stay too, called
through HYDRATION_PASS?.; parseSeeds was parseSeedJson, which its callers
now call, and the diagnostic holds take no capability. failure becomes
hydrationFailure, as a local of that name shadows it at a caller. The
fields the functions read lose `private`.

The hydration-free gate lists the 21 functions with the class, so a
createRoot bundle that maps into any of them fails it.

shell_ full and base_hydrate shrink 634 B raw (84 to 102 B gzip), and
hydrateRoot bundles 634 to 803 B raw (107 to 239 B gzip). Every Vite and
esbuild createRoot row is byte-identical in raw size. Cold hydration pairs
flat against the previous step.

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

cloudflare-workers-and-pages Bot commented Oct 15, 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 Preview URL Updated (UTC)
✅ Deployment successful!
View logs
octane-website ad47772 Commit Preview URL

Branch Preview URL
Oct 15 2026, 12:46 PM

@cloudflare-workers-and-pages

cloudflare-workers-and-pages Bot commented Oct 15, 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 Preview URL Updated (UTC)
✅ Deployment successful!
View logs
octane-website-mcp ad47772 Commit Preview URL

Branch Preview URL
Oct 15 2026, 12:45 PM

@github-actions

github-actions Bot commented Oct 15, 2026 •

Copy link
Copy Markdown
Contributor

Benchmark report

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

Compares 98ce9c362, the merge commit's first parent (main has moved 1 commit(s) past the pull request's recorded base c8c0898ae) with 604d42974 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.592 2.675 +1.8% −3.5% … +3.9% ⚪ within noise
octane-tsrx replace 5.317 5.433 +2.1% −1.7% … +6.1% ⚪ within noise
octane-tsrx add 2.250 2.342 ±0.0% −2.0% … +4.3% ⚪ within noise
octane-tsrx update 0.094 0.095 −0.2% −2.0% … +0.9% ⚪ within noise
octane-tsrx select 0.005 0.005 ±0.0% −0.5% … +1.3% ⚪ within noise
octane-tsrx swap 0.017 0.017 +1.1% −0.5% … +2.2% ⚪ within noise
octane-tsrx remove 0.014 0.015 +2.8% −0.9% … +6.3% ⚪ within noise
octane-tsrx runlots 21.950 21.742 −6.2% −11.9% … +2.3% ⚪ within noise
octane-tsrx select_lots 0.006 0.006 +0.3% −1.2% … +1.2% ⚪ within noise
octane-tsrx clear 45.367 43.475 +5.0% +0.6% … +16.7% ⚪ within noise
octane-jsx run 3.050 3.117 ±0.0% −2.8% … +0.0% ⚪ within noise
octane-jsx replace 5.567 5.742 +2.5% −1.9% … +6.2% ⚪ within noise
octane-jsx add 2.942 3.042 ±0.0% −3.3% … +1.6% ⚪ within noise
octane-jsx update 0.163 0.165 +1.4% +0.7% … +2.2% ⚪ within noise
octane-jsx select 0.087 0.086 −1.3% −2.5% … +1.3% ⚪ within noise
octane-jsx swap 0.136 0.134 +0.6% −4.0% … +3.1% ⚪ within noise
octane-jsx remove 0.116 0.117 +2.2% −0.3% … +3.2% ⚪ within noise
octane-jsx runlots 23.883 24.167 +0.6% −5.4% … +3.3% ⚪ within noise
octane-jsx select_lots 0.921 0.928 +0.5% −2.9% … +6.4% ⚪ within noise
octane-jsx clear 49.858 49.108 +1.7% −4.0% … +5.5% ⚪ within noise

All 64 work counters are unchanged.

Application bundle size (bytes)

target metric base head Δ
octane-tsrx wayfinder_js_raw 438,520 437,886 −634 (−0.1%) 🟢
octane-tsrx wayfinder_js_gzip 145,014 144,859 −155 (−0.1%) 🟢
octane-tsrx wayfinder_js_brotli 125,980 125,906 −74 (−0.1%) 🟢
octane-tsrx full_fw_raw 522,644 521,944 −700 (−0.1%) 🟢
octane-tsrx full_fw_gzip 163,487 163,366 −121 (−0.1%) 🟢
octane-tsrx full_fw_brotli 138,759 138,551 −208 (−0.1%) 🟢
octane-jsx shell_js_raw 327,649 327,015 −634 (−0.2%) 🟢
octane-jsx shell_js_gzip 107,202 107,124 −78 (−0.1%) 🟢
octane-jsx shell_js_brotli 92,691 92,540 −151 (−0.2%) 🟢
octane-jsx shell_app_gzip 762 769 +7 (+0.9%) 🔴
octane-jsx shell_app_brotli 669 661 −8 (−1.2%) 🟢
octane-jsx shell_fw_raw 326,556 325,922 −634 (−0.2%) 🟢
octane-jsx shell_fw_gzip 106,440 106,355 −85 (−0.1%) 🟢
octane-jsx shell_fw_brotli 92,022 91,879 −143 (−0.2%) 🟢
octane-jsx full_fw_raw 522,644 521,944 −700 (−0.1%) 🟢
octane-jsx full_fw_gzip 163,487 163,366 −121 (−0.1%) 🟢
octane-jsx full_fw_brotli 138,759 138,551 −208 (−0.1%) 🟢

76 other measured values are unchanged.

Public-import reachability bundles (bytes)

target metric base head Δ
hydrate-root raw 96,720 96,086 −634 (−0.7%) 🟢
hydrate-root gzip 32,473 32,406 −67 (−0.2%) 🟢
hydrate-root brotli 28,956 28,967 +11 (+0.0%) 🔴
deferred-hydration raw 180,701 180,001 −700 (−0.4%) 🟢
deferred-hydration gzip 58,902 58,765 −137 (−0.2%) 🟢
deferred-hydration brotli 51,418 51,387 −31 (−0.1%) 🟢
hydrate-frame raw 340,877 340,244 −633 (−0.2%) 🟢
hydrate-frame gzip 110,091 109,949 −142 (−0.1%) 🟢
hydrate-frame brotli 95,149 95,060 −89 (−0.1%) 🟢
split-shell raw 391,752 391,052 −700 (−0.2%) 🟢
split-shell gzip 128,364 128,248 −116 (−0.1%) 🟢
split-shell brotli 111,248 110,983 −265 (−0.2%) 🟢
split-shell-runtime raw 316,369 315,669 −700 (−0.2%) 🟢
split-shell-runtime gzip 102,498 102,382 −116 (−0.1%) 🟢
split-shell-runtime brotli 87,977 87,720 −257 (−0.3%) 🟢
binding-base-ui-esbuild gzip 66,886 66,885 −1 (−0.0%) 🟢
binding-base-ui-esbuild brotli 58,754 58,847 +93 (+0.2%) 🔴
binding-mantine-hooks-esbuild gzip 27,500 27,498 −2 (−0.0%) 🟢
binding-mantine-hooks-esbuild brotli 24,849 24,797 −52 (−0.2%) 🟢
binding-usehooks-ts-esbuild gzip 27,715 27,717 +2 (+0.0%) 🔴
binding-usehooks-ts-esbuild brotli 25,059 25,019 −40 (−0.2%) 🟢

102 other measured values are unchanged.

…e render-write ledger (#2028)

adoptText moved from a HydrationCapability method to a module function, so
the writer ledger's 'HydrationCapability.adoptText' entry no longer matched
it and check-render-writes reported its nodeValue write as unclassified.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@trueadm
trueadm merged commit 9442337 into next Oct 15, 2026
53 of 57 checks passed
@trueadm
trueadm deleted the perf/hydration-methods-to-functions branch October 15, 2026 13:00
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