Repository navigation
perf(octane): keep the fresh-hydration closure out of componentSlotImpl - #1571
Merged
Merged
Conversation
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]>
trueadm
marked this pull request as ready for review
October 2, 2026 15:09
Contributor
Benchmark report
Compares js-framework: 1k/10k row operations (ms, lower is better)All 20 timed operations (20 within noise)
Application bundle size (bytes)
30 other measured values are unchanged. Public-import reachability bundles (bytes)
73 other measured values are unchanged. CI job durations
Compares the CI run for
All 26 timed jobs
|
2 of 5 tasks
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
componentSlotImplhad 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. EverycomponentSlotImplcall therefore began withCreateFunctionContextand read its parameters from that context. That covers every component mount and update throughcomponentSlotandcomponentSlotVoid. The callback now lives in a module-levelsuspendFreshComponent(hydration, ...same 14 args)helper, mirroring the existingsuspendFreshLiteComponent.The fresh check runs before
componentSlotImplreassigns any parameter. The helper therefore forwards exactly the values the closure captured, so behavior is unchanged.Performance audit
Target:
componentSlotImplentry 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, withCLIENT_RUNTIME_FILEset to theorigin/mainruntime for the baseline. The output digest is identical (e809b737f8f9).componentSlotImplCreateFunctionContexton entrysuspendFreshComponentis 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.componentSlotVoidcall. An instrumented build confirmed that all 1,000 leaves and 110 parents re-render on every update.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.tsgains 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
RootCaughtBodycase inroot-suspended-value-mismatch.test.ts:RootCaughtBodyfails in both compiles, crashing withNotFoundError.props/renderProps, swappingbody/identity, or passing a nulloutputHandlerfails both compiles.key/hasKey/singleRoot/invocationSite, or swappinginherit/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:checkon the changed files passes.pnpm typecheck: not run repo-wide.pnpm typecheck:fileson the changed files, including the.tsrxfixture, passes.pnpm test: not run as a whole.octaneandoctane-prodprojects on the pre-rebase head (main 25017f3): 36,691 passed, 2 failed. Both failures were 5 s timeouts inhydration-ssr-diagnostics.test.tsunder host load; the file passes 16/16 in isolation on both baseline and candidate.octane+octane-prod:rebuilt-clone-blocks,root-suspended-value-mismatch,split-template-consumers,trycatch-client-error,adopted-host-component-cloneandbranch-arm-tailon head 4effb98 (main 3994e1e merged in), 500/500 passing.split-template-consumerscases. They pass with--testTimeout=30000.pnpm syncleaves no changes.Risk / follow-ups
childSlotstill begins withCreateFunctionContextfrom the same closure pattern. It is deliberately left alone, since this change showed no timing win.functions.mjsharness can lose V8 trace records under host load: the worker's stdout pipe becomes non-blocking. That fix, and the same fix forbenchmarks/ssr-final-replay/diagnostics.mjs, ship separately in fix(bench): keep V8 trace harness stdout off a non-blocking pipe #1569.Provenance
agent-authored)🤖 Generated with Claude Code
Need help on this PR? Tag
@codesmith-botwith 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
componentSlotImplso 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-levelsuspendFreshComponent, matching the existingsuspendFreshLiteComponentpattern; 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.