Skip to content

perf(hydration): keep the binding-marker validator out of client-only bundles - #1637

Merged
trueadm merged 1 commit into
mainfrom
claude/elegant-poitras-e9e7f4
Oct 3, 2026
Merged

trueadm merged 1 commit into
mainfrom
claude/elegant-poitras-e9e7f4

Conversation

@trueadm

@trueadm trueadm commented Oct 3, 2026 •

Copy link
Copy Markdown
Collaborator

Summary

  • Apps that never call hydrateRoot no longer ship the hydration range-marker validator (dom-binding-protocol.ts, through isBlockOpen → hydrationMarkerMultiplicity → isBindingOpenComment). Every renderer app with a dynamic {x} text hole that may hold a signal handle paid for it: about −580 to −650 B gzip and −1,597 B raw per app.
  • Adopting a binding view's server text range is now HydrationCapability.adoptBindingText. bindingText calls it through activeHydration(), so bundles that never construct the capability drop it. Hydration behavior is unchanged.

Why

Review of 85cb387feb..6ea582e37c, finding H1 (P1, size). The compiler emits bindSignalText for ordinary holes, for example … ? htext(...) : bindSignalText(__s, …). bindSignalText calls bindingText, whose inline if (hydration !== null && isBlockOpen(posNode)) { … } branch kept the whole binding-marker prefix and validator reachable. The core-engineering rule puts hydration-only logic in HydrationCapability methods for exactly this reason. #1582 grew the validator with the y0–y2 check (+24..30 B gzip on every app) and raised the root-chained-jsx budget to absorb it. The defect itself is older.

#1623 closed the other route, through mountTry's streamed-boundary check. With both changes, a client-only @try app (suspense-transition) also drops the validator.

Changes

  • packages/octane/src/runtime.ts: move the hydrating branch of bindingText into HydrationCapability.adoptBindingText(posNode, text): Text | null, which returns null when posNode opens no range. The body moves unchanged.
  • benchmarks/bundle-size/run-minimal.mjs: new markerFreeClientScenarios assertion. dom-binding-protocol.ts must not be emitted for cli-spa-starter, root-chained-jsx, prop-attributes, context, suspense-transition, binding-mantine-hooks or binding-usehooks-ts. It sits next to the existing per-scenario module assertions, including perf(hydration): keep the streamed-boundary validator out of client-only @try apps #1623's streamClaimFreeClientScenarios, because verify-reachability.mjs only receives the built code.
  • benchmarks/bundle-size/minimal-budgets.json:
  • packages/octane/tests/behavior-root.test.ts: new test, "hydrates a binding view's filled and empty text holes with the ordinary renderer", in dev and prod compile. It pins:
    • adoption of the server's text node;
    • adoption of an empty server range;
    • in-place updates afterwards, with the view's markup equal to the server's for the same values.
  • Changeset: octane patch.

Bundle size

node benchmarks/bundle-size/run-minimal.mjs, all scenarios, one run on 11a9da935a (main, after #1616, #1619, #1620 and #1623) and one on this branch.

scenario before raw / gzip / brotli after raw / gzip / brotli Δ
root-chained-jsx (CI budget) 85,941 / 28,529 / 25,334 84,344 / 27,881 / 24,833 −1,597 / −648 / −501
prop-attributes (CI budget) 97,393 / 32,385 / 28,676 95,796 / 31,774 / 28,217 −1,597 / −611 / −459
context (CI budget) 110,798 / 36,702 / 32,499 109,201 / 36,119 / 32,026 −1,597 / −583 / −473
cli-spa-starter 116,492 / 39,366 / 34,383 114,895 / 38,762 / 33,916 −1,597 / −604 / −467
suspense-transition 166,742 / 53,582 / 46,878 165,145 / 53,003 / 46,418 −1,597 / −579 / −460
binding-mantine-hooks-vite 98,028 / 32,600 / 28,917 96,431 / 31,991 / 28,434 −1,597 / −609 / −483
binding-mantine-hooks-esbuild 97,622 / 32,786 / 29,112 96,030 / 32,165 / 28,613 −1,592 / −621 / −499
binding-usehooks-ts-vite 98,661 / 32,764 / 29,090 97,064 / 32,156 / 28,573 −1,597 / −608 / −517
binding-usehooks-ts-esbuild 98,244 / 32,930 / 29,231 96,652 / 32,316 / 28,719 −1,592 / −614 / −512
hydrate-root 172,762 / 54,761 / 47,804 172,836 / 54,795 / 47,808 +74 / +34 / +4
deferred-hydration 236,147 / 74,660 / 64,515 236,221 / 74,695 / 64,439 +74 / +35 / −76
binding-apollo-client-esbuild 361,203 / 114,460 / 99,732 361,203 / 114,461 / 99,684 0 / +1 / −48 (identical raw size; compression noise)

The other 23 scenarios are byte-identical, including capture-only, hooks-state, root-static*, behavior-root-* and binding-apollo-client-vite. Hydrating bundles pay +74 B raw for the method name and the dispatch.

Reachability (dom-binding-protocol.ts emitted?)

scenario before after
root-chained-jsx, prop-attributes, context, cli-spa-starter, suspense-transition, binding-mantine-hooks-{vite,esbuild}, binding-usehooks-ts-{vite,esbuild} yes no (now asserted)
hydrate-root, deferred-hydration yes yes (hydrates)
capture-only yes yes (legitimate: event-capture → isRendererStreamBoundaryTemplate → rendererRangeClose)

Validation

  • Pre-fix failure of the reachability assertion: with the pre-fix runtime.ts, node benchmarks/bundle-size/run-minimal.mjs root-chained-jsx fails with REACHABILITY FAIL … a client that never hydrates retained the binding-marker validator (dom-binding-protocol.ts listed). It passes with the fix.
  • CI's budget step node benchmarks/bundle-size/run-minimal.mjs --budgets root-static-local root-chained-jsx hooks-state prop-attributes context passes against the re-cut budgets on the rebased branch. suspense-transition passes the new assertion. The full suite passes with the assertion in place.
  • New test seen red:
    • adoptBindingText always returns null: fails in dev and prod. The server text is duplicated, server labelserver label.
    • Only the empty-range branch disabled: fails in dev and prod with a stray <!--]--> in <b>. The existing @try hydration test stays green here, which is why the new test exists.
  • vitest run --project octane packages/octane/tests/behavior-root.test.ts: 227/227 (on 6ea582e37c, before the rebase).
  • vitest run --project octane packages/octane/tests/hydration/independent-island.test.ts: 36/36 (same).
  • pnpm typecheck:files packages/octane/src/runtime.ts: clean. The test file reports only errors that already exist (older lines in behavior-root.test.ts plus .tsrx fixture noise under plain selection), none in the new test.
  • pnpm format:files:check on every changed file; pnpm sync leaves no generated changes.
  • pnpm format:check, pnpm typecheck, pnpm test (repo-wide): left to CI.

Risk / follow-ups

  • Risk is low: the moved body is byte-for-byte the old branch, and isBlockOpen still runs only when a hydration is active.
  • The budgets are tight. If another PR that changes these budgets lands first, update this branch, re-measure with run-minimal.mjs and re-cut root-chained-jsx / prop-attributes / context the same way.
  • Follow-up (optional, measured): a compiler-emitted bindSignalTextMarked for binding-view text would also drop bindingText's presentation path from plain apps. Stubbing that call out bounds the extra saving at −223 B gzip (root-chained-jsx) to −326 B (context), measured with an esbuild probe. It needs a compiler change plus the presentation interceptor that identifies bindSignalText by argument position.

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


Note

Low Risk
Hydration adoption logic is moved unchanged behind a capability method; risk is low with new reachability assertions and a dedicated hydrate test.

Overview
Client-only bundles no longer ship the binding range-marker validator (~580–650 B gzip per app with dynamic {x} text holes). The hydrating “adopt server text range” path moved out of inline bindingText logic into HydrationCapability.adoptBindingText, which bindingText invokes only when activeHydration() exists (i.e. after hydrateRoot). Apps that never hydrate can tree-shake dom-binding-protocol.ts; hydration apps pay a small method-dispatch cost.

CI adds markerFreeClientScenarios so bundles for scenarios like root-chained-jsx, prop-attributes, and context must not emit that module, and minimal bundle budgets are re-cut to match the measured savings. A new behavior-root test locks in adopting filled and empty binding-view text holes on hydrate, with later updates matching server markup.

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

… bundles

bindSignalText reaches bindingText for every dynamic text hole that may
hold a signal handle, and bindingText adopted a binding view's server
text range in an inline `hydration !== null && isBlockOpen(...)` branch.
That kept isBlockOpen, hydrationMarkerMultiplicity, and the whole
dom-binding-protocol validator in apps that never call hydrateRoot.

Move the branch into HydrationCapability.adoptBindingText, which only
hydrateRoot constructs, so client-only bundles drop it. The body moves
unchanged.

- run-minimal.mjs asserts that dom-binding-protocol.ts is absent from
  the non-hydrating renderer scenarios this cleans.
- Lower the root-chained-jsx, prop-attributes, and context budgets to
  bank the saving.
- behavior-root.test.ts pins hydration of a binding view's filled and
  empty text holes in dev and prod.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@github-actions github-actions Bot added agent-authored Diff or issue body substantially produced by an AI agent perf PR: performance work labels Oct 3, 2026
@github-actions
github-actions Bot marked this pull request as draft October 3, 2026 07:37
@github-actions

github-actions Bot commented Oct 3, 2026 •

Copy link
Copy Markdown
Contributor

Benchmark report

  • 🟡 js-framework: 1 timed operation(s) possibly slower
  • 🔴 bundle-size: 4 value(s) increased
  • 🔴 bundle-reachability: 6 value(s) increased

Compares 11a9da935 with 038bd09b6 on the same runner. Timing verdicts require a change beyond the combined margin of error (at least 5%) and one 0.1ms timer tick, with the fastest sample also moving beyond that margin. Workflow run

js-framework: 1k/10k row operations (ms, lower is better)

target operation base head Δ noise
octane-tsrx replace 6.70 7.56 +12.8% ±11% 🟡 slower
All 20 timed operations (19 within noise)
target operation base head Δ noise
octane-tsrx run 3.64 3.54 −2.7% ±28% ⚪ within noise
octane-tsrx replace 6.70 7.56 +12.8% ±11% 🟡 slower
octane-tsrx add 3.39 3.55 +4.7% ±10% ⚪ within noise
octane-tsrx update 0.33 0.32 −3.0% ±44% ⚪ within noise
octane-tsrx select 0.12 0.14 +16.7% ±123% ⚪ within noise
octane-tsrx swap 0.30 0.30 ±0.0% ±46% ⚪ within noise
octane-tsrx remove 0.27 0.29 +7.4% ±47% ⚪ within noise
octane-tsrx runlots 32.74 33.27 +1.6% ±17% ⚪ within noise
octane-tsrx select_lots 0.16 0.18 +12.5% ±73% ⚪ within noise
octane-tsrx clear 31.14 32.05 +2.9% ±24% ⚪ within noise
octane-jsx run 8.16 3.70 −54.7% ±108% ⚪ within noise
octane-jsx replace 11.51 6.94 −39.7% ±89% ⚪ within noise
octane-jsx add 6.40 3.26 −49.1% ±60% ⚪ within noise
octane-jsx update 0.75 0.47 −37.3% ±79% ⚪ within noise
octane-jsx select 0.49 0.32 −34.7% ±64% ⚪ within noise
octane-jsx swap 0.90 0.54 −40.0% ±92% ⚪ within noise
octane-jsx remove 0.59 0.54 −8.5% ±53% ⚪ within noise
octane-jsx runlots 32.30 28.75 −11.0% ±18% ⚪ within noise
octane-jsx select_lots 2.60 2.32 −10.8% ±26% ⚪ within noise
octane-jsx clear 35.26 33.60 −4.7% ±20% ⚪ within noise

Application bundle size (bytes)

target metric base head Δ
octane-tsrx js_raw 126,800 125,203 −1,597 (−1.3%) 🟢
octane-tsrx js_gzip 41,987 41,356 −631 (−1.5%) 🟢
octane-tsrx js_brotli 37,029 36,465 −564 (−1.5%) 🟢
octane-tsrx app_gzip 2,563 2,562 −1 (−0.0%) 🟢
octane-tsrx app_brotli 2,222 2,226 +4 (+0.2%) 🔴
octane-tsrx fw_raw 119,288 117,691 −1,597 (−1.3%) 🟢
octane-tsrx fw_gzip 39,424 38,794 −630 (−1.6%) 🟢
octane-tsrx fw_brotli 34,807 34,239 −568 (−1.6%) 🟢
octane-tsrx todo_js_raw 142,187 140,590 −1,597 (−1.1%) 🟢
octane-tsrx todo_js_gzip 47,000 46,407 −593 (−1.3%) 🟢
octane-tsrx todo_js_brotli 41,237 40,640 −597 (−1.4%) 🟢
octane-tsrx todo_app_gzip 2,476 2,477 +1 (+0.0%) 🔴
octane-tsrx todo_app_brotli 2,120 2,119 −1 (−0.0%) 🟢
octane-tsrx todo_fw_raw 137,077 135,480 −1,597 (−1.2%) 🟢
octane-tsrx todo_fw_gzip 44,524 43,930 −594 (−1.3%) 🟢
octane-tsrx todo_fw_brotli 39,117 38,521 −596 (−1.5%) 🟢
octane-tsrx chat_js_raw 141,396 139,799 −1,597 (−1.1%) 🟢
octane-tsrx chat_js_gzip 46,944 46,353 −591 (−1.3%) 🟢
octane-tsrx chat_js_brotli 41,289 40,785 −504 (−1.2%) 🟢
octane-tsrx chat_app_gzip 2,977 2,978 +1 (+0.0%) 🔴
octane-tsrx chat_app_brotli 2,641 2,639 −2 (−0.1%) 🟢
octane-tsrx chat_fw_raw 134,743 133,146 −1,597 (−1.2%) 🟢
octane-tsrx chat_fw_gzip 43,967 43,375 −592 (−1.3%) 🟢
octane-tsrx chat_fw_brotli 38,648 38,146 −502 (−1.3%) 🟢
octane-tsrx weather_js_raw 178,362 176,764 −1,598 (−0.9%) 🟢
octane-tsrx weather_js_gzip 58,358 57,763 −595 (−1.0%) 🟢
octane-tsrx weather_js_brotli 50,823 50,323 −500 (−1.0%) 🟢
octane-tsrx weather_app_gzip 9,044 9,045 +1 (+0.0%) 🔴
octane-tsrx weather_app_brotli 7,597 7,584 −13 (−0.2%) 🟢
octane-tsrx weather_fw_raw 151,627 150,029 −1,598 (−1.1%) 🟢
octane-tsrx weather_fw_gzip 49,314 48,718 −596 (−1.2%) 🟢
octane-tsrx weather_fw_brotli 43,226 42,739 −487 (−1.1%) 🟢

13 other measured values are unchanged.

Public-import reachability bundles (bytes)

target metric base head Δ
cli-spa-starter raw 116,492 114,895 −1,597 (−1.4%) 🟢
cli-spa-starter gzip 39,366 38,762 −604 (−1.5%) 🟢
cli-spa-starter brotli 34,383 33,916 −467 (−1.4%) 🟢
root-chained-jsx raw 85,941 84,344 −1,597 (−1.9%) 🟢
root-chained-jsx gzip 28,529 27,881 −648 (−2.3%) 🟢
root-chained-jsx brotli 25,334 24,833 −501 (−2.0%) 🟢
prop-attributes raw 97,393 95,796 −1,597 (−1.6%) 🟢
prop-attributes gzip 32,385 31,774 −611 (−1.9%) 🟢
prop-attributes brotli 28,676 28,217 −459 (−1.6%) 🟢
context raw 110,798 109,201 −1,597 (−1.4%) 🟢
context gzip 36,702 36,119 −583 (−1.6%) 🟢
context brotli 32,499 32,026 −473 (−1.5%) 🟢
hydrate-root raw 172,762 172,836 +74 (+0.0%) 🔴
hydrate-root gzip 54,761 54,795 +34 (+0.1%) 🔴
hydrate-root brotli 47,804 47,808 +4 (+0.0%) 🔴
deferred-hydration raw 236,147 236,221 +74 (+0.0%) 🔴
deferred-hydration gzip 74,660 74,695 +35 (+0.0%) 🔴
deferred-hydration brotli 64,515 64,439 −76 (−0.1%) 🟢
suspense-transition raw 166,742 165,145 −1,597 (−1.0%) 🟢
suspense-transition gzip 53,582 53,003 −579 (−1.1%) 🟢
suspense-transition brotli 46,878 46,418 −460 (−1.0%) 🟢
binding-mantine-hooks-vite raw 98,028 96,431 −1,597 (−1.6%) 🟢
binding-mantine-hooks-vite gzip 32,600 31,991 −609 (−1.9%) 🟢
binding-mantine-hooks-vite brotli 28,917 28,434 −483 (−1.7%) 🟢
binding-mantine-hooks-esbuild raw 97,622 96,030 −1,592 (−1.6%) 🟢
binding-mantine-hooks-esbuild gzip 32,786 32,165 −621 (−1.9%) 🟢
binding-mantine-hooks-esbuild brotli 29,112 28,613 −499 (−1.7%) 🟢
binding-apollo-client-esbuild gzip 114,460 114,461 +1 (+0.0%) 🔴
binding-apollo-client-esbuild brotli 99,732 99,684 −48 (−0.0%) 🟢
binding-usehooks-ts-vite raw 98,661 97,064 −1,597 (−1.6%) 🟢
binding-usehooks-ts-vite gzip 32,764 32,156 −608 (−1.9%) 🟢
binding-usehooks-ts-vite brotli 29,090 28,573 −517 (−1.8%) 🟢
binding-usehooks-ts-esbuild raw 98,244 96,652 −1,592 (−1.6%) 🟢
binding-usehooks-ts-esbuild gzip 32,930 32,316 −614 (−1.9%) 🟢
binding-usehooks-ts-esbuild brotli 29,231 28,719 −512 (−1.8%) 🟢

70 other measured values are unchanged.

@trueadm
trueadm marked this pull request as ready for review October 3, 2026 07:45
@trueadm
trueadm merged commit 4212874 into main Oct 3, 2026
46 of 60 checks passed
@trueadm
trueadm deleted the claude/elegant-poitras-e9e7f4 branch October 3, 2026 07:59
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