Skip to content

perf(hydration): ship island-only activation code only with <Hydrate> - #2038

Merged
trueadm merged 2 commits into
mainfrom
perf/hydration-capability-feature-methods
Oct 13, 2026
Merged

trueadm merged 2 commits into
mainfrom
perf/hydration-capability-feature-methods

Conversation

@trueadm

@trueadm trueadm commented Oct 13, 2026 •

Copy link
Copy Markdown
Collaborator

Parked (draft), 2026-10-13: hydration byte-tuning is paused because #2028 (#2028) removes HydrationCapability. The measurements are in #2028 (comment). The new island fallback tests are worth carrying into the cursor rewrite.

Summary

renderSuspended, finishRoot and keepChanges were HydrationCapability methods whose only caller is activateHydrateBoundary, the <Hydrate> island activation. A bundler keeps every method of a class it keeps, so every hydrating bundle carried them, islands or not. This PR moves them to module functions beside activateHydrateBoundary, so they ship only with <Hydrate>. Behavior is unchanged.

Gates code in the area that #2028 (#2028) redesigns. It moves island-only code next to the feature that creates the capability, so the gain survives the planned collapse into a cursor.

Why only these three

A dead-member scan of the hydrating fixtures found 13.1 KB of never-called class members on hydrate-root, 7.2 KB on deferred-hydration and about 1.3 KB on hydrate-frame. Most of that comes from methods called by client-reachable code: childSlot, setStyle/setAttribute, mountTry, forBlock, ifBlock, childTextHole and others. Moving those breaks the documented flag invariant (hydration-flag.ts, run-hydration-free.mjs): esbuild never folds hydrating, so hydration bodies must stay on the capability or an installed driver.

A probe moved keepsStyle out of the class. create-root-export-vite still dropped it, but create-root-export-esbuild retained it. The broad move would therefore add each feature's hydration bodies to esbuild createRoot-only bundles (Rspack untested), and only Vite hydrating fixtures would shrink. The 13 KB on hydrate-root comes mostly from it being a one-component fixture. These three are the only dead members whose caller constructs the capability itself, so client-only bundles cannot reach them under any bundler.

Changes

  • packages/octane/src/runtime.ts: the three methods become renderSuspended(hydration, source), finishRoot(hydration) and keepChanges(hydration) above activateHydrateBoundary, with their doc comments unchanged. The six fields they read lose TS private; runtime shape is unchanged.
  • packages/octane/tests/hydration/unframed-component-range.test.ts with a new HeldBranch fixture: an island whose server HTML has an element the client renders nothing for, found once a suspended call resumes. One case puts it inside the call's own range, where only renderSuspended's restored claim catches it. The other puts it after the island's range, where only finishRoot catches it. Both cases run under development and production compiles.
  • Changeset: octane patch.

Validation

Bundle size, node benchmarks/bundle-size/run-minimal.mjs (Vite 8 + oxc), base 5594cb0 against head:

row raw gzip brotli
hydrate-root 108,731 → 108,318 (−413) 35,766 → 35,660 (−106) 31,676 → 31,589 (−87)
hydrate-frame 343,339 → 342,926 (−413) 108,745 → 108,657 (−88) 93,421 → 93,294 (−127)
deferred-hydration 191,201 → 191,134 (−67) 61,094 → 61,083 (−11) 53,249 → 53,290 (+41)
  • deferred-hydration uses an island, so it keeps all three functions. Its small change comes from the code no longer being class methods.
  • The other 34 run-minimal rows are byte-identical, including every createRoot-only Vite and esbuild row.

Other checks:

  • node benchmarks/bundle-size/run-hydration-free.mjs: all 15 client bundles hydration-free, controls pass.
  • targeted tests: vitest run --project octane tests/hydration/unframed-component-range, 50 passed.
  • Break-proofs: with renderSuspended's claim branch disabled, only the in-range case fails, under both compiles. With finishRoot as a no-op, only the after-range case fails, under both compiles.
    • Before these tests, a throw-probe over all 168 hydration test files showed the claim branch reached by 8 files (114 tests) and the finishRoot mismatch branch reached by none. With the claim disabled, all 252 tests in those 8 files still passed.
  • pnpm typecheck:files on the three changed source and test files: pass.
  • pnpm format:files:check on the changed files: pass. pnpm sync: clean.
  • pnpm format:check, pnpm typecheck, pnpm test: left to CI.
  • perf-review: node scripts/perf-review-scan.mjs found no candidates. No hot path is touched: the three functions run once per <Hydrate> activation attempt, and their only call sites are the existing ones in activateHydrateBoundary. No compiled output changes, and no new imports or references reach client paths (byte-identical createRoot rows). benchmarks/app-frame-hydration has no islands, so it never runs this code; no paired run.
  • concise-code:
    • Size: src +60 −54 (runtime +60 −54). New files: the changeset only. No new runtime exports; HeldBranch is a test-fixture export.
    • Alternatives rejected: moving all 50+ dead members out of the class, for the esbuild invariant reason above. Inlining the three bodies into activateHydrateBoundary gives the same bytes, since oxc already inlines single-use functions, and loses the names other comments cite.
    • Bytes: the table above.

Risk / follow-ups

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-only relocation of existing island activation paths with new tests and verified bundle shrink; no intended hydration behavior change.

Overview
Moves island-only hydration logic out of HydrationCapability into module-level helpers (renderSuspended, finishRoot, keepChanges) colocated with activateHydrateBoundary, so bundles that call hydrateRoot without <Hydrate> can drop that code (~0.4 kB minified). Call sites in island activation now invoke the free functions; several capability fields lose private so those helpers can read them—runtime behavior is unchanged.

Adds HeldBranch fixtures and parameterized tests covering mismatch detection after a suspended call resumes (extra server element inside the call’s range vs after the island’s range), guarding the refactored renderSuspended and finishRoot paths. Includes an octane patch changeset.

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

trueadm and others added 2 commits October 13, 2026 12:07
renderSuspended, finishRoot and keepChanges were HydrationCapability
methods whose only caller is activateHydrateBoundary. A bundler keeps every
method of a class it keeps, so every hydrating bundle carried them. As
module functions beside activateHydrateBoundary they ship only with
<Hydrate> islands. Their callers construct the capability themselves, so
createRoot-only bundles are unchanged under Vite and esbuild.

Adds island fallback cases that pin both moved branches: a resumed call
whose own range has trailing server content (renderSuspended's claim) and
an island whose server HTML continues past its range (finishRoot). No
existing test failed when either branch was broken.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
# Conflicts:
#	packages/octane/src/runtime.ts
@cloudflare-workers-and-pages

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 435c2a0 Oct 13 2026, 11:12 AM

@cloudflare-workers-and-pages

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 435c2a0 Oct 13 2026, 11:12 AM

@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
@trueadm
trueadm marked this pull request as ready for review October 13, 2026 11:13
@trueadm
trueadm marked this pull request as draft October 13, 2026 11:14
@github-actions

github-actions Bot commented Oct 13, 2026 •

Copy link
Copy Markdown
Contributor

Benchmark report

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

Compares 5594cb06e, the merge commit's first parent with 7b3d0f781 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.850 2.792 +0.0% −1.7% … +3.7% ⚪ within noise
octane-tsrx replace 7.367 7.667 +6.8% −2.7% … +15.8% ⚪ within noise
octane-tsrx add 2.808 2.900 +3.8% −5.5% … +10.9% ⚪ within noise
octane-tsrx update 0.126 0.126 −0.4% −4.6% … +4.2% ⚪ within noise
octane-tsrx select 0.006 0.006 +0.0% −0.5% … +1.1% ⚪ within noise
octane-tsrx swap 0.017 0.017 −1.1% −2.9% … +3.8% ⚪ within noise
octane-tsrx remove 0.016 0.016 −0.4% −4.4% … +0.8% ⚪ within noise
octane-tsrx runlots 27.700 27.058 −0.6% −3.5% … +3.5% ⚪ within noise
octane-tsrx select_lots 0.006 0.006 +0.5% +0.3% … +1.6% ⚪ within noise
octane-tsrx clear 42.033 41.892 +0.5% −0.9% … +1.9% ⚪ within noise
octane-jsx run 3.400 3.283 ±0.0% −2.8% … +3.0% ⚪ within noise
octane-jsx replace 7.175 6.867 −4.1% −5.4% … +1.4% ⚪ within noise
octane-jsx add 3.075 3.158 ±0.0% ±0.0% … +3.3% ⚪ within noise
octane-jsx update 0.250 0.250 −0.7% −1.8% … +0.0% ⚪ within noise
octane-jsx select 0.119 0.118 −0.5% −0.8% … +1.1% ⚪ within noise
octane-jsx swap 0.167 0.164 −1.0% −2.0% … ±0.0% ⚪ within noise
octane-jsx remove 0.171 0.168 −1.3% −2.5% … +1.0% ⚪ within noise
octane-jsx runlots 28.783 28.450 −0.5% −2.8% … +1.1% ⚪ within noise
octane-jsx select_lots 1.520 1.445 −1.2% −3.4% … +1.1% ⚪ within noise
octane-jsx clear 46.658 46.100 −0.4% −2.2% … +1.9% ⚪ within noise

All 64 work counters are unchanged.

Application bundle size (bytes)

target metric base head Δ
octane-tsrx wayfinder_js_raw 459,987 459,574 −413 (−0.1%) 🟢
octane-tsrx wayfinder_js_gzip 149,391 149,306 −85 (−0.1%) 🟢
octane-tsrx wayfinder_js_brotli 129,474 129,335 −139 (−0.1%) 🟢
octane-tsrx full_fw_raw 568,834 568,767 −67 (−0.0%) 🟢
octane-tsrx full_fw_gzip 172,158 172,189 +31 (+0.0%) 🔴
octane-tsrx full_fw_brotli 145,017 145,025 +8 (+0.0%) 🔴
octane-jsx shell_js_raw 392,280 391,867 −413 (−0.1%) 🟢
octane-jsx shell_js_gzip 123,035 122,942 −93 (−0.1%) 🟢
octane-jsx shell_js_brotli 105,105 104,900 −205 (−0.2%) 🟢
octane-jsx shell_app_gzip 770 766 −4 (−0.5%) 🟢
octane-jsx shell_app_brotli 668 667 −1 (−0.1%) 🟢
octane-jsx shell_fw_raw 391,187 390,774 −413 (−0.1%) 🟢
octane-jsx shell_fw_gzip 122,265 122,176 −89 (−0.1%) 🟢
octane-jsx shell_fw_brotli 104,437 104,233 −204 (−0.2%) 🟢
octane-jsx full_fw_raw 568,834 568,767 −67 (−0.0%) 🟢
octane-jsx full_fw_gzip 172,158 172,189 +31 (+0.0%) 🔴
octane-jsx full_fw_brotli 145,017 145,025 +8 (+0.0%) 🔴

76 other measured values are unchanged.

Public-import reachability bundles (bytes)

target metric base head Δ
hydrate-root raw 108,731 108,318 −413 (−0.4%) 🟢
hydrate-root gzip 35,766 35,660 −106 (−0.3%) 🟢
hydrate-root brotli 31,676 31,589 −87 (−0.3%) 🟢
deferred-hydration raw 191,201 191,134 −67 (−0.0%) 🟢
deferred-hydration gzip 61,094 61,083 −11 (−0.0%) 🟢
deferred-hydration brotli 53,249 53,290 +41 (+0.1%) 🔴
hydrate-frame raw 343,339 342,926 −413 (−0.1%) 🟢
hydrate-frame gzip 108,745 108,657 −88 (−0.1%) 🟢
hydrate-frame brotli 93,421 93,294 −127 (−0.1%) 🟢

102 other measured values are unchanged.

@trueadm
trueadm marked this pull request as ready for review October 13, 2026 12:02
@trueadm
trueadm merged commit e75d7a8 into main Oct 13, 2026
75 of 103 checks passed
@trueadm
trueadm deleted the perf/hydration-capability-feature-methods branch October 13, 2026 12:51
@github-actions github-actions Bot mentioned this pull request Oct 13, 2026
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