Repository navigation
perf: recover transition hook hot-path cost from the audit fixes - #949
Merged
Merged
Conversation
Add the deterministic benchmarks/transition-hooks suite (render and creation-event counts with semantic controls, 35 ratio guards) covering useTransition cycles, functional updaters, a suspended hold + release, urgent dispatch and bailout, delegated clicks, and an urgent update beside a queued transition. Track useTransition pending ownership without a Set per transition: a batch keeps its first starting hook in a field and each hook counts its pending batches, so a cycle allocates the pre-audit three collections again while every corrected behavior stays pinned. Extend the hook-memo observer with opt-in object and constructor counting, and record the attribution, counts, timing caveats, and the manual-provider adapter measurement in the audit document. Co-Authored-By: Claude Fable 5.1 <[email protected]>
trueadm
marked this pull request as ready for review
September 3, 2026 21:17
5 tasks done
1 task done
14 of 21 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
benchmarks/transition-hooks, a deterministic Node-only suite for the transition and state-hook hot paths that fix: address React behavioral audit defects #943 touched:useTransitionstart → pending render → settle cycles with a replacement value and a functional updater, a suspended hold + release, an urgent functional dispatch and its same-value bailout, a delegated click, and an urgent update beside a queued transition. Each scenario checks its render sequence and DOM, and the observed bundle counts runtime function/array/object/constructor creation events against awork-modeltarget; 35 ratio guards enforce them.Setallocations fix: address React behavioral audit defects #943 added for hook pending tracking. A batch stores its first starting hook in a field (a second distinct hook allocates a small list) and each hook counts its pending batches, with a per-batch flag so a re-held batch is counted once. Every fixed behavior is unchanged: nested starts from another hook share the pending window, a hook starting nested transitions inside its own Action is counted once, and a finished batch that a later round re-holds becomes pending again.hook-memocreation observer an opt-in extended mode (object literals and non-Arraynewexpressions);hook-memoitself keeps its default counts.docs/divergence-audit-2026-09-03.md.Why
The audit recorded a 2.8 → 3.6 µs (+29%) hook-transition cycle from an uncommitted fixture and about 5.7–9.5 ns per manual-provider call. There was no committed benchmark and no guard. This suite makes the transition-cycle cost a deterministic count with semantic controls, so the regression it protects against is visible in CI's ratio run and cannot be argued away as timing noise.
Attribution on
33720d8ef(pre-#943) vs44d50dbc0(main) with the new suite: the only per-cycle allocation the audit added on a non-suspending cycle was theSetallocated foractionBatch.hooks(+1 constructor per transition, plus oneSetper hook); CPU profiles of 300k cycles put the rest of the delta in the new hook bookkeeping (runTransition/finishTransitionHookBatchSet traffic), the render-time queue replay inuseState, and the setter's held-update lookups. The replay, the staged update record, the retained flush list, and the lookups are the corrected semantics and stay; the audit paragraph documents them as such.Measurements
Same command, same machine, same installed dependencies (
node benchmarks/transition-hooks/run.mjs, Node 24.18.0). Runtime creation events per 64 cycles; every other counter and every render count is identical betweenmainand this branch:33720d8efmain(44d50dbc0)cycleupdaterheldheldurgentnode benchmarks/bench.mjs --ratios transition-hooks: this branch passes all 35 guards; themainruntime (OCTANE_TRANSITION_ROOTpointed at a pristine44d50dbc0checkout) breachescycle_runtime_constructors(1.33x),updater_runtime_constructors(1.33x),held_runtime_constructors(1.07x), andurgent_runtime_constructors(1.17x). The remainingheldallocation over the baseline is the hook-holder registration a suspended transition creates when it holds; it stays on that cold path.Timing (secondary, no guard). Three alternating rounds of
run.mjsper runtime at a steady load average near 5.5 (another session's test jobs were running throughout), median of per-round medians in µs per cycle, baseline /main/ this branch:33720d8efmaincycleupdaterhelddispatchbailclickurgentThe same rounds taken while the machine's load average was above 20 doubled every figure, so the audit's absolute 2.8 → 3.6 µs is not comparable with this fixture and the PR claims only what the count guards see; the direction of the timing deltas matches the constructor counts.
Manual-provider adapter (isolated, fifteen alternating million-call samples after six warmups): prior module-initialization closure provider 6.85 ns per bound call, current hoisted declaration adapter 9.93 ns, two call-site-specialized variants that pass
arguments.lengthplus named parameters instead ofarguments9.75–9.93 ns, direct call 6.01 ns. The remaining cost is the second call frame a hoisted declaration needs to reach the shared driver, notargumentsforwarding, so the adapter is unchanged and the audit keeps documenting that cost.Changes
benchmarks/transition-hooks/{cases.tsrx,entry.mjs,run.mjs,README.md}: new suite;benchmarks/bench.mjsmanifest entry;benchmarks/README.mdtable row; 35 guards inbenchmarks/baselines/ratios.json.benchmarks/hook-memo/instrument.mjs: opt-inobjectscounting (objectLiterals,constructors); README note.packages/octane/src/runtime.ts:TransitionActionBatch.hook/hooks/hooksPending,TransitionHookSlot.pendingBatches,addTransitionHookToBatch,publishTransitionHookBatch;finishTransitionHookBatch/holdTransitionHookBatchuse them; the per-hook Set and its unmount cleanup are gone (an in-flight batch releases its hook reference when the Action settles;publishalready ignores a disposed block).packages/octane/tests/transition-hook-pending.test.ts(+ fixture): pending ownership across overlapping and nested Actions and an unmounted starting hook. The nested-second-hook case fails when a newcomer to an already-counted batch is not counted; the others pin the contract.packages/octane-mcp-server/src/index.js+ README: the hand-maintained suite list gainstransition-hooks(its manifest-sync test enforces this)..changeset/quick-transition-hooks.md(octanepatch);docs/divergence-audit-2026-09-03.mdrow and follow-up section.Validation
pnpm format:checkpnpm typecheckpnpm test(2,599 files, 28,723 tests; the orchestrator neededNODE_OPTIONS=--max-old-space-size=8192to survive the shared machine's memory pressure, after a default-heap run died in the runner process before reporting)audit-hook-behavior,transitions,transition-held-audit,transition-held-urgent-resuspend,transition-urgent-equality,transition-nested-action,transition-action-order,transition-descendant-suspend,transition-timeout,transition-replacements,conformance/update-reconciliation,conformance/eager-bailout,scheduler-commit,external-store-behavior(236 tests), plus the newtransition-hook-pending(4) — all pass on this branch.node --test benchmarks/hook-memo/instrument.test.mjs;node benchmarks/bench.mjs --ratios transition-hooks(35/35 pass;mainruntime breaches 4).pnpm syncproduced no generated changes.Risk / follow-ups
heldpath still allocates one holder registrationSetper suspended hold (cold path);readQueuedStatestays O(1) on the common path and was not changed.Provenance
agent-authored)🤖 Generated with Claude Code
Note
Medium Risk
Changes core
useTransitionpending bookkeeping inruntime.tswith broad transition test coverage and new regression guards; behavior is intended to be parity-preserving but touches scheduler-adjacent hot paths.Overview
Replaces per-transition
Setallocations inuseTransitionpending tracking with a batch field for the first starting hook, an optional array only when a second distinct hook joins, and per-hookpendingBatchescounts—restoring the pre-audit three-constructor budget per cycle while preserving audit semantics (nested hooks, single count for repeated starts in one Action, re-held batches go pending again).Adds a
transition-hooksNode benchmark with seven scenarios (cycle, functional updater, suspended hold/release, urgent dispatch, same-value bailout, delegated click, urgent beside queued transition), render/DOM controls, extended hook-memo allocation instrumentation, 35 CI ratio guards, and audit doc updates.Adds
transition-hook-pendingtests for overlapping Actions, nested second-hook pending, and unmount-before-settle; removes per-hookSetunmount cleanup in favor of batch lifetime holding the hook reference.Reviewed by Cursor Bugbot for commit 2bab6c0. Bugbot is set up for automated code reviews on this repo. Configure here.
Need help on this PR? Tag
@codesmith-botwith what you need. Autofix is disabled.