Skip to content

benchmarks: add selector-based external-store fan-out suite - #338

Merged
trueadm merged 1 commit into
perf/hoist-capture-free-hook-callbacksfrom
test/store-selector-fanout-bench
Jul 28, 2026
Merged

trueadm merged 1 commit into
perf/hoist-capture-free-hook-callbacksfrom
test/store-selector-fanout-bench

Conversation

@trueadm

@trueadm trueadm commented Jul 28, 2026 •

Copy link
Copy Markdown
Collaborator

Summary

  • New store-selector-fanout benchmark suite: 512 subscribers read one external store through a selector, then the parent re-renders 20 times with the store untouched.
  • Ratio guard parent_rerenders octane-tsrx vs react at maxRatio 0.95.
  • Stacked on perf(compiler): hoist capture-free hook callbacks to module scope #337 — the guard is calibrated to the capture-free hook-callback lift and only holds with it.

Why

No existing suite could see a regression in selector identity. external-store-fanout uses a raw useSyncExternalStore with an inline snapshot getter and has no selector layer at all; external-store-integrations goes 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.mjs manifest entry, benchmarks/README.md suite row, baselines/ratios.json guard, @octanejs/mcp-server suite list.
  • benchmarks/news/vue-vapor/src/vue-shim.js gains a computed re-export — vapor's default entry does not expose it, and the shim already re-exports ref/watch/etc. the same way.

Design notes

Its own page inside the news target apps (the hydration-interactivity pattern), 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 generation prop and renders it as data-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 / computed over a snapshot signal.

Measurements

Full 8-iteration runs, parent_rerenders:

target score (ms) selector calls during 20 re-renders subscriber renders
octane-tsrx 10.08 0 10,240
react 16.98 10,240 10,240
preact 24.30 10,240 10,240
solid 3.88 0 0
svelte 4.52 0 0
vue-vapor 5.56 0 0

Does it discriminate? Recompiling the fixture with the lift disabled, same machine, same run:

octane react ratio guard
lift on 10.08 16.98 0.59x PASS
lift off 18.12 15.16 1.20x BREACH … 1.12x outside maxRatio 0.95 (quick mode)

Selector invocations go 0 → 10,240 with the lift removed, while subscriberRendersDuringRerenders stays 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.95 leaves 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's note.

Production compile confirmed directly: hmr: false emits const _fn$0 = (snapshot) => selectTotal(snapshot.values); at module scope; hmr: true keeps it inline at the call site.

Validation

  • pnpm format:check
  • pnpm typecheck
  • pnpm test — 1428 files, 14,575 tests passed
  • node benchmarks/bench.mjs --quick store-selector-fanout — 6/6 targets pass
  • node benchmarks/bench.mjs store-selector-fanout — full run, 6/6 pass
  • node 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 the vue-shim.js edit

Risk / follow-ups

🤖 Generated with Claude Code


Note

Cursor Bugbot is generating a summary for commit 0feb65e. Configure here.

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]>
@vercel

vercel Bot commented Jul 28, 2026 •

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
octane-website Ready Ready Preview, Comment Jul 28, 2026 12:23pm
octane-website-mcp Ready Ready Preview, Comment Jul 28, 2026 12:23pm

Request Review

@vercel
vercel Bot temporarily deployed to Preview – octane-website-mcp July 28, 2026 12:22 Inactive
@vercel
vercel Bot temporarily deployed to Preview – octane-website July 28, 2026 12:23 Inactive
@trueadm
trueadm merged commit 1e960c5 into perf/hoist-capture-free-hook-callbacks Jul 28, 2026
2 checks passed
@trueadm
trueadm deleted the test/store-selector-fanout-bench branch July 28, 2026 12:38
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]>
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]>

This branch was previously deployed

2 inactive deployments
Preview – octane-website — 0feb65e5 Deployed Jul 28, 2026 by vercel[bot]
Preview – octane-website-mcp — 0feb65e5 Deployed Jul 28, 2026 by vercel[bot]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant