Skip to content

perf(octane): stop shipping Suspense in hydrating bundles without Suspense - #1803

Merged
trueadm merged 5 commits into
mainfrom
perf/suspense-hydration-reachability
Oct 6, 2026
Merged

trueadm merged 5 commits into
mainfrom
perf/suspense-hydration-reachability

Conversation

@o-alexandrov

@o-alexandrov o-alexandrov commented Oct 6, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Why

  • The HydrationCapability constructor installs renderInitialSuspenseHydration so that client-only Suspense does not ship the hydrator. That function, however, calls mountTry, switchToCatch, createTryBody and setTryBranch directly, so every hydrating bundle retained them and everything they reach (hidden reveal, Activity hiding, catch switching, pending arms): about 30 kB raw.
  • tryBlock now passes those four operations to the hydrator at its only call site. The hydrator is still installed by the capability, so neither direction regresses: client-only Suspense does not gain the hydrator (run-minimal.mjs reachability gate holds), and hydration without Suspense no longer gains Suspense.

Bytes (run-minimal.mjs, committed budgets vs origin/main 8aeb6c0e5)

scenario main gzip this PR gzip
hydrate-root 54,277 45,357 (−8,920)
deferred-hydration 74,278 unchanged (uses Suspense)
suspense-transition (client-only) 51,875 51,867
root-static, cli-spa-starter unchanged unchanged

With #1792's minify: 'oxc' the same change takes hydrate-root from 51,707 to 43,249 B gzip. No budget raised (budget-raises.mjs --base origin/main).

Alternatives measured and rejected: making the hydrator call the four functions directly and having the capability set a flag, or routing through a capability method, either kept the hydrator in client-only Suspense bundles (+870 B gzip on suspense-transition, and the reachability gate fails) or kept Suspense in hydrating bundles. Passing an ops object instead of positional arguments cost about 40 B more on Suspense bundles.

Changes

  • packages/octane/src/runtime.ts: renderInitialSuspenseHydration takes createTryBody, setTryBranch, mountTry and switchToCatch as parameters; tryBlock passes them.
  • Budgets lowered with --write-budgets; changeset added.

Validation

  • pnpm typecheck:files packages/octane/src/runtime.ts
  • pnpm vitest run --project octane --project octane-prod: 42,039 passed, 1 failed (behavior-root textarea retirement, the same full-suite load flake as on main; 293/293 in isolation).
  • Coverage of each passed operation, by sabotage: breaking switchToCatch fails 10 tests in the Suspense/try hydration files; breaking mountTry fails 18 in unclosed-range and markerless-arm-retry; skipping the hydrator fails 56 across the Suspense hydration files. No new test was needed: behavior is unchanged and existing tests pin every routed call.
  • run-minimal.mjs --budgets, run.mjs --budgets octane-tsrx octane-jsx, budget-raises.mjs --base origin/main
  • pnpm sync, pnpm format:files:check
  • full pnpm test (left to CI)

Risk / follow-ups

  • Bundles that use Suspense grow by the four call arguments: the CI benchmark report shows +2 B gzip on deferred-hydration, +12 B gzip on the whole-API ceiling, and −8 B gzip on suspense-transition, all within budget.
  • No behavior change intended; the four functions are called with the same arguments at the same points.
  • Hydration bundles still carry HydrationCapability (27.7 kB raw) in full. Per-site recovery inside it is being deleted by fix(octane): handle hydration mismatches like React 19 (boundary/root client-render fallback) #1784.

Rework on top of #1784 (2026-10-06)

#1784 (the React 19 hydration fallback) rewrote renderInitialSuspenseHydration. Hydration now reaches the boundary machinery from more places than the original parameter passing covered: the dehydrated-boundary fallback (clientRenderDehydratedTry → renderDehydratedTry → mountTry), and HydrationCapability.adoptServerCatch / fallBackServerCatch.

The goal is the same, with a different mechanism. tryBlock, the only place a TrySlot is created, installs a TRY_OPS table (createTryBody, setTryBranch, mountTry, switchToCatch) once hydrationStarted is set, and every hydration-side caller goes through it. The guard folds out of createRoot bundles, so they are unchanged; the todo app's framework gzip is identical with or without this change.

Current numbers (oxc, after #1792):

Scenario Before After
hydrate-root (esbuild probe) 170,177 raw / 55,033 gzip 140,583 raw / 45,990 gzip
hydrate-root budget (run-minimal, oxc) 166,889 / 52,659 137,746 / 44,082 (−29,143 / −8,577)
deferred-hydration (renders a boundary) — +134 raw / +73 gzip for the indirection

The deferred-hydration raise landed separately in budget-only #1811. Every other budget is min(main, measured + headroom).

Validation on the merged head:

  • octane + octane-prod: 42,490 tests pass.
  • run-minimal --budgets, run.mjs --budgets octane-tsrx octane-jsx and run-hydration-free.mjs pass.
  • budget-raises.mjs: no raise.

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. Autofix is disabled.


Note

Medium Risk
Touches core hydration and Suspense/try routing in runtime.ts with no intended behavior change; regressions would show up as hydration or boundary mismatches rather than compile failures.

Overview
Hydrating clients that never render Suspense or @try no longer pull in Suspense boundary machinery (mountTry, catch switching, Activity/hidden-reveal paths). The minimal hydrate-root budget drops by roughly 9 kB gzip (~16%).

In runtime.ts, hydration paths that used to call createTryBody, setTryBranch, mountTry, and switchToCatch directly now go through a lazy TRY_OPS table. tryBlock—the only place that creates a TrySlot—installs those four functions once hydration has started, so plain hydrateRoot trees never statically reference that code. Behavior is intended to be unchanged when a boundary is actually rendered; deferred-hydration and client-only Suspense scenarios stay within existing reachability gates.

Bundle-size budget JSON files and an octane patch changeset reflect the new measurements.

Reviewed by Cursor Bugbot for commit adbdd29. 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 6, 2026
@o-alexandrov
o-alexandrov marked this pull request as ready for review October 6, 2026 01:14
@github-actions

github-actions Bot commented Oct 6, 2026 •

Copy link
Copy Markdown
Contributor

Benchmark report

  • 🔴 bundle-size: 6 value(s) increased within budget
  • 🔴 bundle-reachability: 3 value(s) increased within budget

Compares 4b46332e2, the merge commit's first parent with b4a5f1646 on the same runner. A byte value over its committed budget or any increase in a js-framework work counter fails this check. 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.625 2.633 −0.0% −3.6% … ±0.0% ⚪ within noise
octane-tsrx replace 5.617 5.858 ±0.0% −1.8% … +5.5% ⚪ within noise
octane-tsrx add 2.383 2.383 +0.0% ±0.0% … +4.3% ⚪ within noise
octane-tsrx update 0.128 0.127 +0.8% −0.5% … +2.4% ⚪ within noise
octane-tsrx select 0.005 0.005 −0.5% −2.3% … ±0.0% ⚪ within noise
octane-tsrx swap 0.038 0.040 +2.0% +0.6% … +4.0% ⚪ within noise
octane-tsrx remove 0.021 0.020 −3.9% −7.8% … +5.4% ⚪ within noise
octane-tsrx runlots 24.892 24.800 −0.6% −1.7% … +1.1% ⚪ within noise
octane-tsrx select_lots 0.006 0.006 −0.3% −1.0% … +0.9% ⚪ within noise
octane-tsrx clear 45.025 44.442 −1.3% −3.3% … +1.2% ⚪ within noise
octane-jsx run 3.667 3.442 ±0.0% −4.3% … +2.9% ⚪ within noise
octane-jsx replace 6.358 6.233 −1.7% −5.1% … +2.8% ⚪ within noise
octane-jsx add 3.092 3.233 +0.0% −2.9% … +3.3% ⚪ within noise
octane-jsx update 0.246 0.270 +1.4% −1.4% … +6.1% ⚪ within noise
octane-jsx select 0.128 0.130 +0.3% −1.1% … +2.7% ⚪ within noise
octane-jsx swap 0.246 0.247 −1.1% −3.6% … +0.4% ⚪ within noise
octane-jsx remove 0.175 0.177 +1.5% −0.6% … +3.3% ⚪ within noise
octane-jsx runlots 28.100 29.000 +2.9% +0.2% … +4.4% ⚪ within noise
octane-jsx select_lots 1.331 1.321 ±0.0% −1.0% … +2.1% ⚪ within noise
octane-jsx clear 46.950 47.342 +0.7% −2.6% … +4.1% ⚪ within noise

All 64 work counters are unchanged.

Application bundle size (bytes)

target metric base head Δ
octane-tsrx full_fw_raw 562,159 562,291 +132 (+0.0%) 🔴
octane-tsrx full_fw_gzip 168,880 168,962 +82 (+0.0%) 🔴
octane-tsrx full_fw_brotli 142,166 142,181 +15 (+0.0%) 🔴
octane-jsx full_fw_raw 562,159 562,291 +132 (+0.0%) 🔴
octane-jsx full_fw_gzip 168,880 168,962 +82 (+0.0%) 🔴
octane-jsx full_fw_brotli 142,166 142,181 +15 (+0.0%) 🔴

54 other measured values are unchanged.

Public-import reachability bundles (bytes)

target metric base head Δ
hydrate-root raw 166,814 137,714 −29,100 (−17.4%) 🟢
hydrate-root gzip 52,615 44,050 −8,565 (−16.3%) 🟢
hydrate-root brotli 45,718 38,549 −7,169 (−15.7%) 🟢
deferred-hydration raw 230,816 230,948 +132 (+0.1%) 🔴
deferred-hydration gzip 72,282 72,355 +73 (+0.1%) 🔴
deferred-hydration brotli 62,191 62,210 +19 (+0.0%) 🔴

99 other measured values are unchanged.

@trueadm

trueadm commented Oct 6, 2026

Copy link
Copy Markdown
Collaborator

This now conflicts with main in runtime.ts and both budget files. The runtime.ts conflict can't be resolved by picking a side. #1784 (React 19 hydration fallback, merged as 91079dd) rewrote renderInitialSuspenseHydration, and the hydrating paths now reach the Suspense machinery from more places than this PR covers:

  • renderInitialSuspenseHydration still calls createTryBody, setTryBranch and switchToCatch directly.
  • It also calls clientRenderDehydratedTry, which calls renderDehydratedTry, which calls mountTry. That is the dehydrated-boundary fallback, and the update path (updated) uses it as well.
  • HydrationCapability itself calls switchToCatch (the adopted server @catch arm) and renderDehydratedTry (an update reaching a dehydrated boundary). That class ships in every hydrating bundle.

Passing the four functions as parameters from tryBlock no longer reaches all of these. A shape that would:

  1. tryBlock installs a small table of try operations (createTryBody, setTryBranch, mountTry, switchToCatch, renderDehydratedTry) the first time it runs. It is the only way a TrySlot comes into existence.
  2. Every hydration-side caller goes through that table: renderInitialSuspenseHydration, clientRenderDehydratedTry/renderDehydratedTry, and the two HydrationCapability sites.

After that:

  • Merge main.
  • Re-measure with node benchmarks/bundle-size/run-minimal.mjs --write-budgets and keep only values at or below main's. hydrate-root on main is now 55,222 gzip.
  • Confirm node benchmarks/bundle-size/run-hydration-free.mjs still passes.

Also note that #1792 (bench sizes measured with Vite 8's default minifier) is about to re-cut every budget, so measure after it lands.

trueadm and others added 3 commits October 6, 2026 12:45
#1784 rewrote renderInitialSuspenseHydration, and hydration now reaches the
boundary machinery from more places: the dehydrated-boundary fallback
(clientRenderDehydratedTry -> renderDehydratedTry -> mountTry) and two
HydrationCapability sites (adoptServerCatch, fallBackServerCatch). Re-apply
this branch's goal on top: tryBlock, which alone creates a TrySlot, installs
a TRY_OPS table once hydration has started, and every hydration-side caller
goes through it.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
hydrate-root's budget drops from 166,889 raw / 52,659 gzip to 137,746 raw /
44,082 gzip (-29,143 / -8,577) now that hydrating bundles without a Suspense
or @Try boundary no longer ship the boundary machinery. Values are
min(main, measured + headroom); deferred-hydration, which renders a
boundary, pays for the indirection and is raised in a separate budget-only
pull request.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
trueadm added a commit that referenced this pull request Oct 6, 2026
… overage (#1811)

- deferred-hydration (raw 230,846 -> 230,980, gzip 72,314 -> 72,387): #1803
  routes hydration's boundary operations through a table that tryBlock
  installs, so hydrating bundles without Suspense drop about 8.6 kB gzip.
  A hydrating bundle that renders a boundary pays for the indirection.
- todo framework/total raw (+43 each): main already measures 115,067 raw
  against a 115,056 budget. #1808, merged after #1792 re-derived the budgets
  under oxc, adds a few bytes to input-handling paths. #1803 does not change
  todo; the framework gzip is identical with either runtime.

Values are measured + 32.

Co-authored-by: Claude Opus 5.5 <[email protected]>
…on-reachability

# Conflicts:
#	benchmarks/bundle-size/minimal-budgets.json
@trueadm

trueadm commented Oct 6, 2026

Copy link
Copy Markdown
Collaborator

I took this over at the maintainer's request and reworked it on top of #1784 (adbdd29). The goal is the same, but hydration now reaches the boundary operations through a TRY_OPS table that tryBlock installs, because #1784 added more hydration-side paths into the Suspense machinery. hydrate-root's budget drops by 8,577 gzip. See the "Rework" section in the description for the numbers and validation. deferred-hydration's small indirection cost landed in budget-only #1811.

🤖 Addressed by Claude Code

trueadm added a commit that referenced this pull request Oct 6, 2026
Take #1811's budgets: its todo raw raise matches this branch's
measurement, and its deferred-hydration row is kept as main has it so
#1803 still fits.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@trueadm
trueadm merged commit e03350a into main Oct 6, 2026
31 checks passed
@trueadm
trueadm deleted the perf/suspense-hydration-reachability branch October 6, 2026 12:10
trueadm added a commit that referenced this pull request Oct 6, 2026
Take main's budgets after #1803. Re-recording with this branch's
runtime ratchets every value to main's (#1803 already cut them to
measured + headroom), and deferred-hydration keeps main's row.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
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.

2 participants