Skip to content

perf(octane): signal-instance identity + dormant-owner fast paths - #1216

Merged
domgan-oai merged 1 commit into
mainfrom
perf/signal-identity-dormant
Sep 21, 2026
Merged

domgan-oai merged 1 commit into
mainfrom
perf/signal-identity-dormant

Conversation

@jonkwheeler

@jonkwheeler jonkwheeler commented Sep 21, 2026 •

Copy link
Copy Markdown
Contributor

Part of #1202. Split from #1188.

Summary

  • Signal-instance identity moves off the SCOPE_SIGNAL_INSTANCE_KEYS WeakMap onto five fields on Scope/Block/LiteBlockImpl (signalInstanceParent, signalInstanceSite, signalInstanceValue, signalInstanceHasKey, signalInstanceResolved); stampSignalInstanceKey/stampSignalInstance write them, and resolveSignalInstanceKey resolves the recipe lazily with last-writer-wins semantics.
  • componentSlotLite now resolves the scope's signal owner inline and only allocates the runWithSignalOwner closure when the owner actually changes — the common same-owner mount calls the component body directly.
  • renderBlockInner skips bookkeeping whose own predicate would early-return anyway on dormant blocks: recordCapturedRender is skipped unless the capture is a non-root-transaction capture, and finishEffectRender only runs once effectSlots is populated.
  • drainEffectEventUpdates replaces the hidden-subtree drop with parked publication: an Effect Event update queued under a hidden Suspense boundary defers to the boundary's reveal action (version-guarded), while a rolled-back render's payload still never publishes.

Why

  • Stamping a component scope previously allocated a recipe record plus a WeakMap entry on every mount; the field form costs five stores and keeps the recipe lifetime-stable with the scope itself. Scalar-only components still never pay ancestor walks, visited sets, key coercion, or JSON strings — resolution stays lazy.
  • componentSlotLite is the lite-component mount path; wrapping every signal-document mount in a closure just to switch owners taxed the most common case (owner unchanged) with an allocation per mount.
  • Dormant blocks — no registered effects, no root-transaction capture — are the dominant scheduled-update case; both skipped calls early-returned on exactly the predicates now checked inline.
  • Dropping a queued Effect Event impl under a hidden boundary lost the update entirely: the reveal republishes retained DOM without re-invoking the bodies that queued it, so parking on the boundary is the only path that ever applies it.

Changes

  • packages/octane/src/runtime.ts: Scope interface + ScopeImpl/BlockImpl/LiteBlockImpl gain the signalInstance* fields (LiteBlockImpl carries them null for the polymorphic scope.block walk); SCOPE_SIGNAL_INSTANCE_KEYS deleted; stampSignalInstanceKey added; resolveSignalInstanceKey, stampSignalInstance, componentSlotLite, renderBlockInner, drainEffectEventUpdates rewritten as above; componentSlotImpl (×2), renderOffscreen, childSlot (×2) stamp via stampSignalInstanceKey.
  • packages/octane/tests/render-block-dormant.test.ts (new): pins the dormant-path contract from the consumer side — a state-only component re-renders correctly, and a block that arms mid-lifecycle (first useEffect, first use() suspension, first context read, first transition) takes the full path from that render on.
  • .changeset/proud-scopes-drift.md: 'octane': patch.

Validation

  • pnpm format:files:check on touched paths — clean.
  • pnpm typecheck:files on touched paths — clean.
  • targeted tests: vitest run packages/octane/tests/render-block-dormant.test.ts — 10 tests pass across the octane and octane-prod projects.
  • regression sanity: vitest run packages/octane/tests/signals-dom-bindings.test.ts packages/octane/tests/components.test.ts — 125 tests pass across all signal/component project shards.
  • pnpm sync leaves the tree clean (no generated output).
  • pnpm format:check, pnpm typecheck, pnpm test — deferred to CI per repo convention.
  • spa-navigation delta at this branch's HEAD: octane-tsrx geomean 0.881x vs main@8a4a2e087 (20 iters; <1 = faster) — nav_teardown 0.9→0.7 ms (0.78x), nav_mount 2.2→2.0 (0.83x), nav_deep 2.7→2.4 (0.88x), nav_deep_6x 17.3→14.6 (0.89x); nav_nested ~flat. DOM census identical (2052/1025/1); reuse ratio 0.104 vs main 0.087 (both far above the ~0.03 ideal, unchanged in kind)
  • Framework bytes at HEAD (octane fw gz): app/tsrx 38163 (+150 vs base 38013), jsx 66946 (+159), todomvc 42603 (+177), chat-stream 42064 (+199), weather-app 52082 (+185). Minimal-reachability scenarios move +104 to +194 gz where the runtime ships; signal-free scenarios are unchanged. run-minimal.mjs captured all listed scenario sizes before stopping at the pre-existing binding-aria-esbuild failure (known unrelated esbuild issue flagged on perf(runtime): beat React 19 + Compiler across the timing benchmark portfolio #1188).

Risk / follow-ups

  • Identity semantics are unchanged — same resolution order, same last-writer-wins rule; the fields are monomorphic on every Scope/Block shape so the structural walk stays polymorphic-safe.
  • The hidden-boundary parking path keeps the render/completed version guard at reveal time, so a newer committed impl still wins over a parked one.

Provenance

  • An agent produced this diff (agent-authored)

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
Changes core render, signal identity, and Suspense Effect Event commit paths; semantics are intended to be equivalent but the hidden-boundary parking and dormant guards are subtle.

Overview
Octane runtime performance and correctness tweaks around signal identity, lite mounts, dormant renders, and Effect Events under hidden Suspense.

Signal-instance identity no longer uses a per-scope WeakMap; recipe and resolved keys live on five signalInstance* fields on Scope, Block, and LiteBlockImpl, with stampSignalInstanceKey / lazy resolveSignalInstanceKey preserving last-writer-wins semantics.

Lite component mounts (componentSlotLite) inline signal-owner resolution and only wrap the body in runWithSignalOwner when the owner differs from the current one, avoiding a per-mount closure on the common path.

Dormant block renders skip work that would no-op anyway: recordCapturedRender is omitted for root-transaction captures, and finishEffectRender runs only after effectSlots is non-null so the first useEffect on a render still arms the full path.

Effect Event draining no longer drops updates for subtrees hidden by Suspense; they are parked on the boundary via deferHiddenRevealAction and applied at reveal (with version guards), while rolled-back renders still cannot publish stale impls. New tests in render-block-dormant.test.ts lock dormant vs mid-lifecycle arming behavior for state, effects, use(), context, and transitions.

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

@jonkwheeler

Copy link
Copy Markdown
Contributor Author

Suggested review order for the #1188 split (tracking: #1202):

  1. fix(benchmarks): restore effectful-list workload honesty and enable React Compiler in spa-navigation #1205 — fixtures/harness honesty; everything downstream is measured against the baselines it fixes
  2. ci(benchmarks): recommit bundle budgets to measured main reality #1207 — budgets + guards re-measured on main; gives the perf PRs headroom to land green
  3. feat(compiler): admit host-only conditional item bodies to forBlock PURE #1213 — forBlock PURE, compiler-only; smallest and most contained
  4. feat(octane): $$stable — compiler-proven props-snapshot bailout for components #1214 — $$stable, compiler+runtime; introduces blockBailUnsafe (the shared hazard veto)
  5. perf(octane): signal-instance identity + dormant-owner fast paths #1216 — signal identity + dormant paths; moderate runtime diff
  6. perf(octane): changed-commit write path — sources plan, fused scan, journal replay #1215 — write path; largest diff, easiest once feat(octane): $$stable — compiler-proven props-snapshot bailout for components #1214 and perf(octane): signal-instance identity + dormant-owner fast paths #1216's machinery is familiar

Wave 2 (#1213–#1216) is any-order for merging — this sequence front-loads the concepts later diffs build on.

@domgan-oai
domgan-oai merged commit dbcabb2 into main Sep 21, 2026
50 checks passed
@domgan-oai
domgan-oai deleted the perf/signal-identity-dormant branch September 21, 2026 20:09
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.

2 participants