Repository navigation
Conversation
512 subscribers read one external store through a `with-selector`-shaped selector, then the parent re-renders 20 times with the store untouched — the workload a stable selector identity is supposed to make free. No existing suite could see it: `external-store-fanout` uses a raw `useSyncExternalStore` with an inline snapshot getter and has no selector layer, and `external-store-integrations` measures Zustand/Jotai/TanStack Query backends rather than isolating selector cost. The suite reuses the news per-target toolchains with its own page rather than extending the runtime-stress harness, whose shared App always renders 512 controlled form fields — those would have swamped the selection cost and perturbed nine existing suites' baselines. `selectorCallsDuringRerenders` is the deterministic signal, and it is read next to `subscriberRendersDuringRerenders` and `snapshotCallsDuringRerenders`: on a render-pass framework those stay at 512 x 20, so zero selector calls means the selection was reused, not that the renders were skipped. Real Chromium gates every subscriber's total after each broad write and again after the burst, plus a second write afterwards and exact subscription teardown. Co-Authored-By: Claude Opus 5 <[email protected]>
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
trueadm
merged commit Jul 28, 2026
1e960c5
into
perf/hoist-capture-free-hook-callbacks
2 checks passed
trueadm
added a commit
that referenced
this pull request
Jul 28, 2026
* perf(compiler): hoist capture-free hook callbacks to module scope A function passed to a hook call site is reallocated every render, so a hook that COMPARES it sees a fresh identity and redoes work whose inputs never moved. A store selector is the motivating case: an inline arrow defeats the identity-keyed memo it feeds, so an unrelated parent re-render re-runs the selection for every subscriber. A callback that captures nothing from the component cannot behave differently between renders or instances, so production compiles lift it to module scope and it keeps one identity for the module's lifetime. Measured on 512 subscribers over 20 unrelated re-renders, selector invocations fall from 512 per render to zero. Hooks whose contract is stated in terms of the callback are excluded: useCallback returns the argument and owes a fresh identity when deps change, useMemo/effects are defined by how often it runs, useState takes a once-only initialiser, and useEffectEvent deliberately hands back an unstable wrapper. Custom use[A-Z] hooks and useSyncExternalStore take the lift. Dev/HMR keeps the authored form, matching the inline hook-memo tier. Also fixes free-variable analysis for a classic `for (let i = 0; …)`, whose declaration sits in the loop's `init` rather than its `left`: `i` was reported free and read as a capture of a binding the loop shadows, which made any callback containing a counting loop look instance-specific. Co-Authored-By: Claude Opus 5 <[email protected]> * fix(compiler): treat pattern-expression reads as captures; gate lift on prod Addresses two review findings on the capture-free callback lift. A binding pattern's default initialisers and computed keys are expressions evaluated at binding time, but collectFreeIdentifiers only harvested the NAMES a pattern declares and never walked those positions. So `(s, scale = props.factor) => …` and `({ [props.field]: picked }) => …` reported no reference to `props` at all and read as capture-free — the lift then moved them to module scope where the name does not resolve. This was an unsafe lift, not a missed one, and it invalidated the claim that the over-approximation can only ever cost a lift. Pattern expressions are now walked for function params, variable declarators, and catch params, so the analysis is correct for every caller. The lift was also gated on `!hmrEnabled` alone while its own comment, the changeset, and the neighbouring inline hook-memo tier all describe a production-only gate, so dev and profile builds with HMR off were still lifting. It now uses the same `!hmrEnabled && !devEnabled && !profileEnabled` gate, which required moving the call below those flags. Co-Authored-By: Claude Opus 5 <[email protected]> * benchmarks: add selector-based external-store fan-out suite (#338) 512 subscribers read one external store through a `with-selector`-shaped selector, then the parent re-renders 20 times with the store untouched — the workload a stable selector identity is supposed to make free. No existing suite could see it: `external-store-fanout` uses a raw `useSyncExternalStore` with an inline snapshot getter and has no selector layer, and `external-store-integrations` measures Zustand/Jotai/TanStack Query backends rather than isolating selector cost. The suite reuses the news per-target toolchains with its own page rather than extending the runtime-stress harness, whose shared App always renders 512 controlled form fields — those would have swamped the selection cost and perturbed nine existing suites' baselines. `selectorCallsDuringRerenders` is the deterministic signal, and it is read next to `subscriberRendersDuringRerenders` and `snapshotCallsDuringRerenders`: on a render-pass framework those stay at 512 x 20, so zero selector calls means the selection was reused, not that the renders were skipped. Real Chromium gates every subscriber's total after each broad write and again after the burst, plus a second write afterwards and exact subscription teardown. Co-authored-by: Claude Opus 5 <[email protected]> --------- Co-authored-by: Claude Opus 5 <[email protected]>
4 tasks done
This was referenced Oct 5, 2026
trueadm
added a commit
that referenced
this pull request
Oct 5, 2026
…ng marker (#1753) * fix(octane): recover when server HTML loses a range's closing marker findMatchingClose assumed every server range closes in its parent and dereferenced null when a minifier or proxy had stripped the close. It now throws UnclosedHydrationRange, a native adoption miss: application boundaries pass it through and the root or a Hydrate boundary renders on the client and reports it as recoverable. A Suspense arm whose own range is intact renders on the client itself, so a hydration that finishes after the root commits recovers too. The binding-view root pair is matched inside the root attempt so its missing close recovers the same way. Co-Authored-By: Claude Opus 5.5 <[email protected]> * chore: sync generated CLI data for error #338 Co-Authored-By: Claude Opus 5.5 <[email protected]> --------- Co-authored-by: Claude Opus 5.5 <[email protected]>
3 of 6 tasks
This branch was previously deployed
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
store-selector-fanoutbenchmark suite: 512 subscribers read one external store through a selector, then the parent re-renders 20 times with the store untouched.parent_rerendersoctane-tsrx vs react atmaxRatio 0.95.Why
No existing suite could see a regression in selector identity.
external-store-fanoutuses a rawuseSyncExternalStorewith an inline snapshot getter and has no selector layer at all;external-store-integrationsgoes through selector paths but measures Zustand / Jotai / TanStack Query backends rather than isolating selector cost.The motivating shape is
useSelector(store, (s) => s.total): the selection is memoized on the selector's identity, so an inline arrow reallocated per render throws the cache away and an unrelated parent re-render re-runs the selection for every subscriber.Changes
benchmarks/store-selector-fanout/{shared.js,run.mjs,README.md}— snapshot store whose identity changes only on a write, a shared 2,000-element reduction, and the stats counters.benchmarks/news/store-selector-fanout.mjs— Playwright/vite harness (BENCH_JSON contract, correctness-gated).benchmarks/news/<target>/store-selector-fanout.html+src/store-selector-fanout/for octane-tsrx, react, preact, solid, svelte, vue-vapor.bench.mjsmanifest entry,benchmarks/README.mdsuite row,baselines/ratios.jsonguard,@octanejs/mcp-serversuite list.benchmarks/news/vue-vapor/src/vue-shim.jsgains acomputedre-export — vapor's default entry does not expose it, and the shim already re-exportsref/watch/etc. the same way.Design notes
Its own page inside the news target apps (the
hydration-interactivitypattern), not a new suite name on the runtime-stress harness: that harness's shared App always renders 512 controlled form fields, which would have swamped the selection cost and perturbed nine existing suites' baselines.Each subscriber takes a parent-owned
generationprop and renders it asdata-generation, so a parent re-render genuinely reaches all 512 subscribers instead of being absorbed by a memo boundary. Renders are driven and timed inside the page through a per-target synchronous flush, so neither a Playwright round trip nor a timer floor sits between them.Solid, Svelte and Vue have no render pass to redo, so their subscribers express the same thing as a
createMemo/$derived/computedover a snapshot signal.Measurements
Full 8-iteration runs,
parent_rerenders:Does it discriminate? Recompiling the fixture with the lift disabled, same machine, same run:
BREACH … 1.12x outside maxRatio 0.95(quick mode)Selector invocations go 0 → 10,240 with the lift removed, while
subscriberRendersDuringRerendersstays at 10,240 either way — the win is a reused selection, not skipped renders.Guard headroom. CI runs
--quick, and that is the stable case: 0.586 / 0.597 / 0.593 across three independent quick runs, 0.594 on the full run.0.95leaves roughly 60% headroom over the observed ratio while still failing on the 1.12–1.20x un-lifted ratio. Observed values are recorded in the guard'snote.Production compile confirmed directly:
hmr: falseemitsconst _fn$0 = (snapshot) => selectTotal(snapshot.values);at module scope;hmr: truekeeps it inline at the call site.Validation
pnpm format:checkpnpm typecheckpnpm test— 1428 files, 14,575 tests passednode benchmarks/bench.mjs --quick store-selector-fanout— 6/6 targets passnode benchmarks/bench.mjs store-selector-fanout— full run, 6/6 passnode benchmarks/bench.mjs --quick --ratios store-selector-fanout— guard checked, PASS (and BREACH with the lift disabled)node benchmarks/external-store-fanout/run.mjs vue-vapor 1— regression check on thevue-shim.jseditRisk / follow-ups
0.95guard assumes perf(compiler): hoist capture-free hook callbacks to module scope #337. Merging this tomainahead of perf(compiler): hoist capture-free hook callbacks to module scope #337 would break the weekly bench cron; that is why it is stacked. Re-target tomainonly after perf(compiler): hoist capture-free hook callbacks to module scope #337 lands.unmountis octane 33ms vs react 20ms on this fixture. Pre-existing and unrelated to the selector path — no guard added.🤖 Generated with Claude Code
Note
Cursor Bugbot is generating a summary for commit 0feb65e. Configure here.