Skip to content

perf(octane): keep the fresh-hydration closure out of componentSlotImpl - #1571

Merged
trueadm merged 2 commits into
mainfrom
perf/component-slot-fresh-closure
Oct 2, 2026
Merged

trueadm merged 2 commits into
mainfrom
perf/component-slot-fresh-closure

Conversation

@trueadm

@trueadm trueadm commented Oct 2, 2026 •

Copy link
Copy Markdown
Collaborator

Summary

componentSlotImpl had exactly one inner closure: the hydration callback for a component inside a client-rebuilt subtree, hydration.suspend(() => componentSlotImpl(...14 args)). Because that arrow captured all 14 parameters, V8 context-allocated them. Every componentSlotImpl call therefore began with CreateFunctionContext and read its parameters from that context. That covers every component mount and update through componentSlot and componentSlotVoid. The callback now lives in a module-level suspendFreshComponent(hydration, ...same 14 args) helper, mirroring the existing suspendFreshLiteComponent.

The fresh check runs before componentSlotImpl reassigns any parameter. The helper therefore forwards exactly the values the closure captured, so behavior is unchanged.

Performance audit

  • Target: componentSlotImpl entry cost on component mount and update.

  • Bytecode: Node 24.18 / V8 13.6. Measured with CLIENT_FUNCTION_SET=slots node benchmarks/client-hot-paths/functions.mjs, with CLIENT_RUNTIME_FILE set to the origin/main runtime for the baseline. The output digest is identical (e809b737f8f9).

    componentSlotImpl main (a50b846) this PR
    Bytecode bytes 5,177 4,670
    Registers / frame bytes 67 / 536 69 / 552
    CreateFunctionContext on entry yes no

    suspendFreshComponent is never compiled by this workload, because it only runs during hydration.

  • Bundle: the harness's clean minified fixture bundle grows by 77 bytes minified and 19 bytes gzip (216,154 → 216,231 minified; 69,671 → 69,690 gzip).

  • Timing: Chromium 149, production builds that differ only in runtime.ts.

    • Workload: a fixture of 1,111 stateful components, each reached through a static componentSlotVoid call. An instrumented build confirmed that all 1,000 leaves and 110 parents re-render on every update.
    • Method: 60 paired samples per run, with variant order rotated and reversed. An identical second copy of the baseline was timed alongside as a noise control.
    • Semantic controls: DOM identity, text, delegated events, state and unmount cleanup.
    Run Update: this PR vs main Update: main copy vs main Mount: this PR Mount: main copy
    1 −1.1% −1.1% −0.6% +1.1%
    2 −1.3% −1.7% −1.2% +0.3%

    The update delta equals the identical-bundle delta, and mount noise is about ±10%. No latency improvement is claimed. This removes per-call context allocation and bytecode, not measured time.

  • Not measured: Node/happy-dom timing. On this host (load average 30–60), happy-dom ran out of memory in mount loops, and identical bundles differed by up to ±70%. Other engines, startup and GC were also not measured.

Tests

rebuilt-clone-blocks.test.ts gains a case where hydration rebuilds a mismatched element on the client. Inside it, a framed two-root component, a keyed component, a dynamic host tag and a value-returning component must mount as live client DOM. The server component after the rebuilt element must keep its original nodes. The case also checks event handling, state across a same-key re-render, and remounting on a key change.

Mutations checked against this case and the existing RootCaughtBody case in root-suspended-value-mismatch.test.ts:

  • Removing the fresh branch: the new case fails under the development compile, with a false second mismatch diagnostic. RootCaughtBody fails in both compiles, crashing with NotFoundError.
  • Miswiring the helper: swapping props/renderProps, swapping body/identity, or passing a null outputHandler fails both compiles.
  • Not observable on this path: dropping key/hasKey/singleRoot/invocationSite, or swapping inherit/hasKey. These only affect the marker regime or signal-instance identity here. A slot first mounted without a key also adopts its first later key without remounting.

Validation

  • pnpm format:check: not run repo-wide. pnpm format:files:check on the changed files passes.
  • pnpm typecheck: not run repo-wide. pnpm typecheck:files on the changed files, including the .tsrx fixture, passes.
  • pnpm test: not run as a whole.
    • The octane and octane-prod projects on the pre-rebase head (main 25017f3): 36,691 passed, 2 failed. Both failures were 5 s timeouts in hydration-ssr-diagnostics.test.ts under host load; the file passes 16/16 in isolation on both baseline and candidate.
  • Targeted tests after the rebase, octane + octane-prod: rebuilt-clone-blocks, root-suspended-value-mismatch, split-template-consumers, trycatch-client-error, adopted-host-component-clone and branch-arm-tail on head 4effb98 (main 3994e1e merged in), 500/500 passing.
    • With the default 5 s timeout, the host (load average about 60) timed out a few split-template-consumers cases. They pass with --testTimeout=30000.
  • pnpm sync leaves no changes.

Risk / follow-ups

  • childSlot still begins with CreateFunctionContext from the same closure pattern. It is deliberately left alone, since this change showed no timing win.
  • The functions.mjs harness can lose V8 trace records under host load: the worker's stdout pipe becomes non-blocking. That fix, and the same fix for benchmarks/ssr-final-replay/diagnostics.mjs, ship separately in fix(bench): keep V8 trace harness stdout off a non-blocking pipe #1569.

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

Medium Risk
Touches the hot-path component slot implementation and fresh-subtree hydration suspend wiring; behavior is intended to be identical but mistakes in argument forwarding could break hydration after structural rebuilds.

Overview
Moves the fresh-subtree hydration callback out of componentSlotImpl so normal component mounts and updates no longer pay for an inner closure that captured all slot parameters (and triggered per-call context allocation in V8). The fresh-anchor path now delegates to a module-level suspendFreshComponent, matching the existing suspendFreshLiteComponent pattern; semantics are unchanged because the helper forwards the same arguments the old closure captured.

Adds hydration coverage for a client-rebuilt branch that mounts nested live components (multi-root, keyed, dynamic tag, value-returning child) while adopting the server-rendered component that follows, including clicks, same-key updates, and key remounts.

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

trueadm and others added 2 commits October 2, 2026 15:55
componentSlotImpl's only inner closure, the fresh-anchor hydration path,
captured all 14 parameters, so V8 context-allocated them and every
component mount and update began with CreateFunctionContext. Move the
callback into a module-level suspendFreshComponent helper, mirroring
suspendFreshLiteComponent.

Cover a rebuilt template clone whose components (framed, keyed, dynamic
host tag, value-returning) must mount as live client DOM while the server
component after the clone is still adopted.

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 2, 2026
@trueadm
trueadm marked this pull request as ready for review October 2, 2026 15:09
@github-actions

github-actions Bot commented Oct 2, 2026 •

Copy link
Copy Markdown
Contributor

Benchmark report

  • 🔴 bundle-size: 11 value(s) increased
  • 🔴 bundle-reachability: 25 value(s) increased

Compares 3994e1ea0 with a6f967e51 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)

All 20 timed operations (20 within noise)
target operation base head Δ noise
octane-tsrx run 5.23 7.52 +43.8% ±99% ⚪ within noise
octane-tsrx replace 7.98 11.18 +40.1% ±69% ⚪ within noise
octane-tsrx add 3.67 7.38 +101.1% ±62% ⚪ within noise
octane-tsrx update 0.47 0.66 +40.4% ±85% ⚪ within noise
octane-tsrx select 0.16 0.24 +50.0% ±91% ⚪ within noise
octane-tsrx swap 0.46 0.51 +10.9% ±70% ⚪ within noise
octane-tsrx remove 0.42 0.41 −2.4% ±91% ⚪ within noise
octane-tsrx runlots 37.08 42.09 +13.5% ±35% ⚪ within noise
octane-tsrx select_lots 0.16 0.26 +62.5% ±76% ⚪ within noise
octane-tsrx clear 33.48 42.77 +27.7% ±28% ⚪ within noise
octane-jsx run 4.40 5.84 +32.7% ±75% ⚪ within noise
octane-jsx replace 7.64 7.75 +1.4% ±23% ⚪ within noise
octane-jsx add 4.37 5.82 +33.2% ±103% ⚪ within noise
octane-jsx update 0.73 0.59 −19.2% ±77% ⚪ within noise
octane-jsx select 0.53 0.41 −22.6% ±64% ⚪ within noise
octane-jsx swap 1.00 0.93 −7.0% ±75% ⚪ within noise
octane-jsx remove 0.67 0.73 +9.0% ±91% ⚪ within noise
octane-jsx runlots 42.16 36.64 −13.1% ±68% ⚪ within noise
octane-jsx select_lots 3.12 3.71 +18.9% ±82% ⚪ within noise
octane-jsx clear 38.33 44.99 +17.4% ±34% ⚪ within noise

Application bundle size (bytes)

target metric base head Δ
octane-tsrx weather_js_raw 176,733 176,810 +77 (+0.0%) 🔴
octane-tsrx weather_js_gzip 57,765 57,791 +26 (+0.0%) 🔴
octane-tsrx weather_js_brotli 50,168 50,152 −16 (−0.0%) 🟢
octane-tsrx weather_app_gzip 9,044 9,043 −1 (−0.0%) 🟢
octane-tsrx weather_app_brotli 7,605 7,563 −42 (−0.6%) 🟢
octane-tsrx weather_fw_raw 149,998 150,075 +77 (+0.1%) 🔴
octane-tsrx weather_fw_gzip 48,721 48,748 +27 (+0.1%) 🔴
octane-tsrx weather_fw_brotli 42,563 42,589 +26 (+0.1%) 🔴
octane-jsx js_raw 225,289 225,366 +77 (+0.0%) 🔴
octane-jsx js_gzip 71,838 71,867 +29 (+0.0%) 🔴
octane-jsx js_brotli 62,192 62,289 +97 (+0.2%) 🔴
octane-jsx app_brotli 2,502 2,501 −1 (−0.0%) 🟢
octane-jsx fw_raw 216,822 216,899 +77 (+0.0%) 🔴
octane-jsx fw_gzip 68,895 68,924 +29 (+0.0%) 🔴
octane-jsx fw_brotli 59,690 59,788 +98 (+0.2%) 🔴

30 other measured values are unchanged.

Public-import reachability bundles (bytes)

target metric base head Δ
root-static raw 201,612 201,689 +77 (+0.0%) 🔴
root-static gzip 63,985 64,006 +21 (+0.0%) 🔴
root-static brotli 55,478 55,506 +28 (+0.1%) 🔴
context raw 109,986 110,063 +77 (+0.1%) 🔴
context gzip 36,379 36,393 +14 (+0.0%) 🔴
context brotli 32,167 32,175 +8 (+0.0%) 🔴
deferred-hydration raw 223,967 224,044 +77 (+0.0%) 🔴
deferred-hydration gzip 71,234 71,253 +19 (+0.0%) 🔴
deferred-hydration brotli 61,465 61,404 −61 (−0.1%) 🟢
suspense-transition raw 166,494 166,571 +77 (+0.0%) 🔴
suspense-transition gzip 53,485 53,503 +18 (+0.0%) 🔴
suspense-transition brotli 46,736 46,686 −50 (−0.1%) 🟢
binding-base-ui-vite raw 211,806 211,883 +77 (+0.0%) 🔴
binding-base-ui-vite gzip 67,565 67,582 +17 (+0.0%) 🔴
binding-base-ui-vite brotli 58,565 58,594 +29 (+0.0%) 🔴
binding-base-ui-esbuild raw 209,779 209,856 +77 (+0.0%) 🔴
binding-base-ui-esbuild gzip 67,566 67,585 +19 (+0.0%) 🔴
binding-base-ui-esbuild brotli 58,648 58,640 −8 (−0.0%) 🟢
binding-aria-esbuild gzip 3,363 3,361 −2 (−0.1%) 🟢
binding-aria-esbuild brotli 3,013 3,012 −1 (−0.0%) 🟢
binding-radix-vite raw 213,735 213,812 +77 (+0.0%) 🔴
binding-radix-vite gzip 68,121 68,137 +16 (+0.0%) 🔴
binding-radix-vite brotli 59,135 59,155 +20 (+0.0%) 🔴
binding-radix-esbuild raw 211,667 211,744 +77 (+0.0%) 🔴
binding-radix-esbuild gzip 68,121 68,140 +19 (+0.0%) 🔴
binding-radix-esbuild brotli 59,058 59,023 −35 (−0.1%) 🟢
binding-apollo-client-vite raw 356,858 356,935 +77 (+0.0%) 🔴
binding-apollo-client-vite gzip 111,703 111,738 +35 (+0.0%) 🔴
binding-apollo-client-vite brotli 97,582 97,507 −75 (−0.1%) 🟢
binding-apollo-client-esbuild raw 359,836 359,913 +77 (+0.0%) 🔴
binding-apollo-client-esbuild gzip 113,935 113,954 +19 (+0.0%) 🔴
binding-apollo-client-esbuild brotli 99,262 99,295 +33 (+0.0%) 🔴

73 other measured values are unchanged.

CI job durations

  • 🟡 4 job(s) slower than every recent main run: React parity shard (3/4), heavy integration (package builds, eval corpus, runtime loaders, Astro), example apps (1/3), Lynx compatibility

Compares the CI run for 4effb98bb (run) with the last 5 successful main push runs. A job is only slower or faster outside the whole main range, by at least 10% and 15s. Job time excludes runner setup.

job main median main range this PR Δ
wall clock (first job start to last job end) 13m 00s 11m 55s–14m 59s 13m 29s +29s (+4%) ⚪ within noise
total job time 140m 58s 134m 18s–157m 45s 149m 50s +8m 52s (+6%) ⚪ within noise
React parity shard (3/4) 10m 25s 10m 07s–11m 31s 12m 32s +2m 07s (+20%) 🟡 slower
heavy integration (package builds, eval corpus, runtime loaders, Astro) 5m 23s 5m 21s–5m 53s 5m 58s +35s (+11%) 🟡 slower
example apps (1/3) 3m 13s 3m 04s–3m 31s 3m 48s +35s (+18%) 🟡 slower
Lynx compatibility 1m 32s 1m 29s–1m 36s 1m 51s +19s (+21%) 🟡 slower
All 26 timed jobs
job main median main range this PR Δ
React parity shard (3/4) 10m 25s 10m 07s–11m 31s 12m 32s +2m 07s (+20%) 🟡 slower
React parity shard (4/4) 10m 53s 10m 08s–13m 14s 12m 25s +1m 32s (+14%) ⚪ within noise
test shard (Node 24, 3/4) 9m 33s 9m 29s–10m 46s 10m 34s +1m 01s (+11%) ⚪ within noise
heavy integration (browser - chromium) 11m 40s 11m 03s–14m 20s 12m 22s +42s (+6%) ⚪ within noise
test shard (Node 24, 4/4) 10m 26s 10m 21s–11m 11s 11m 03s +37s (+6%) ⚪ within noise
heavy integration (package builds, eval corpus, runtime loaders, Astro) 5m 23s 5m 21s–5m 53s 5m 58s +35s (+11%) 🟡 slower
example apps (1/3) 3m 13s 3m 04s–3m 31s 3m 48s +35s (+18%) 🟡 slower
validate publishable packages 3m 58s 3m 51s–4m 54s 4m 31s +33s (+14%) ⚪ within noise
test shard (Node 24, 1/4) 11m 40s 11m 19s–12m 22s 12m 01s +21s (+3%) ⚪ within noise
Lynx compatibility 1m 32s 1m 29s–1m 36s 1m 51s +19s (+21%) 🟡 slower
React parity shard (1/4) 11m 18s 10m 23s–11m 27s 11m 36s +18s (+3%) ⚪ within noise
React parity shard (2/4) 10m 08s 10m 04s–11m 23s 10m 24s +16s (+3%) ⚪ within noise
example apps (3/3) 3m 30s 3m 22s–3m 49s 3m 46s +16s (+8%) ⚪ within noise
example apps (2/3) 3m 44s 3m 42s–3m 55s 3m 59s +15s (+7%) ⚪ within noise
lint checks 8m 51s 7m 43s–12m 03s 9m 04s +13s (+2%) ⚪ within noise
Three compatibility 2m 43s 2m 42s–3m 16s 2m 49s +6s (+4%) ⚪ within noise
test shard (Node 24, 2/4) 11m 55s 10m 38s–13m 38s 12m 01s +6s (+1%) ⚪ within noise
classify changeset release 13s 12s–15s 16s +3s (+23%) ⚪ within noise
website integration suite 6m 06s 5m 43s–6m 49s 6m 08s +2s (+1%) ⚪ within noise
typecheck checks 2m 13s 1m 56s–2m 40s 2m 15s +2s (+2%) ⚪ within noise
typecheck 3s 3s–4s 4s +1s (+33%) ⚪ within noise
examples 3s 3s–4s 3s ±0s (±0%) ⚪ within noise
test (24) 3s 2s–5s 3s ±0s (±0%) ⚪ within noise
CI provenance 3s 3s–4s 3s ±0s (±0%) ⚪ within noise
lint 4s 3s–4s 3s −1s (−25%) ⚪ within noise
React parity checks 12s 10s–14s 11s −1s (−8%) ⚪ within noise

@trueadm
trueadm merged commit ab2798e into main Oct 2, 2026
31 checks passed
@trueadm
trueadm deleted the perf/component-slot-fresh-closure branch October 2, 2026 15:29
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