Skip to content

perf: tree-shake unused transition hook queues - #1964

Merged
trueadm merged 5 commits into
octanejs:mainfrom
openai-oss-forks:codex/transition-hook-owner
Oct 10, 2026
Merged

trueadm merged 5 commits into
octanejs:mainfrom
openai-oss-forks:codex/transition-hook-owner

Conversation

@domgan-oai

@domgan-oai domgan-oai commented Oct 10, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Applications without transitions still retain state/reducer transition staging and replay through ordinary hook calls. Put the six existing functions on the existing TransitionRootDriver, installed before runTransition publishes any batch. Their implementations are unchanged. Hook setters read the live driver again after authored updaters, so an updater that starts the first async Action still stages its result correctly.

Against 4cc2a1ed700318846c8d93249550122bc86e3dfa, the complete production JavaScript gzip results are:

Fixture Baseline This change Delta
TSRX rows, canonical Oxc 32,140 B 31,581 B −559 B
JSX rows, canonical Oxc 54,702 B 54,161 B −541 B
TSRX rows, ordinary esbuild 37,614 B 37,082 B −532 B
JSX rows, ordinary esbuild 65,062 B 64,464 B −598 B

Canonical Todo, chat and weather also decrease by 585, 557 and 552 gzip bytes. Feature-retaining controls grow slightly: bindings +96 B, full framework +91 B, and the active transition-hooks fixture +73 B. There are six additional references on one existing cold driver object, with no new registry, slot field, per-render allocation, scheduling hop or wrapper function.

Broader reachability controls expose an additional tradeoff in this head: some stateless bindings retain transitions through generic framework paths, and the driver object then keeps hook helpers they never call. Base UI Separator grows by 556 B gzip with Oxc and 554 B with direct esbuild; Radix Separator by 536/547 B; ApolloProvider/useApolloClient by 554/529 B. The attempted independent-binding refinements were parked because their follow-up measurements did not resolve a potential small active-path performance cost. They are not included in this PR; the current published head retains the original implementation and the size tradeoffs above.

Validation

Signed c13f79735 integrates main 64c33de2f; GitHub reports it mergeable and current-head CI passes. The final integration passes 32 focused dev/prod executions, formatting and sync, with unchanged production hashes during validation and independent source review. The earlier performance measurements retain their stated source and limitations.

  • pnpm format:check — current-head CI passes; changed-file check also passes locally.
  • pnpm typecheck — current-head CI passes; scoped runtime and changed test programs also pass locally.
  • pnpm test — current-head full CI passes.
  • Targeted tests: 486 owning dev/prod executions across 20 file runs, plus 8 production bundle tests. Fresh production state and linked-state fixtures start the first async Action inside an updater and verify pending DOM/getter behavior. Three deliberate faults fail: a missing staging method, a driver cached before the updater, and eager retention of the six helpers.
  • Ordinary production rows: all 64 work metrics pass; all 20 function-call metrics decrease by four, with all DOM/insertion metrics unchanged. Existing transition-hooks creation/Map.get census is equal for all 63 full-suite and 27 fresh dormant metrics.
  • Chromium production work controls: all 24 clean/named flows preserve state, reducer, memo, getter, ordering and cleanup results. Dormant dispatch removes four calls per cycle; active dispatch and transition replay have equal calls and DOM work. The same-cell awaiting-Action fixture preserves getter observations 123 → 123456 and settles to 123456; all six owner functions are exercised. Its one ordinary prefix also removes four calls.
  • check-staged-dom, perf-review-scan and independent source/complexity review pass. concise-code: reuse the existing driver and remove redundant reducer/deferred absence checks; six separate global function bindings were unnecessary. All six implementation bodies and hot record shapes remain unchanged.
  • Paired Chromium timings on frozen production bundles: four operations, each with 16 fresh process/context groups per treatment and identical-baseline cohort, 10 warmup pairs and 12 retained pairs per group. Page creation and execution order are balanced. One common workload per operation was calibrated toward 20–40 ms windows; retained windows reach 17.5 ms after further warming. Every retained sample is included.
  • pnpm sync passes and generates no additional diff.

The timing estimate is the median head/base ratio of group arithmetic means, with a paired-bootstrap 95% interval. No slowdown was detected in the four warmed synchronous operations; the largest upper bound is +1.17%. Identical-code controls overlap parity. This does not establish a speedup.

Public-root operation Head/base (95% CI) Identical baseline (95% CI)
dormant-dispatch 0.992817 [0.988334, 0.998175] 0.998538 [0.987809, 1.014821]
active-dispatch 0.997451 [0.989762, 1.003566] 1.002114 [0.987703, 1.009097]
pair-transition 1.002566 [0.987394, 1.009484] 0.996760 [0.990492, 1.005737]
getter-transition 1.001272 [0.998115, 1.011669] 1.004156 [0.993212, 1.010550]

The local environment uses Node 24.20.0, Vite 8.1.5, esbuild 0.28.1 and Chromium 149.0.7827.55. Canonical bytes use the repository's Oxc/framework-split settings; ordinary work and the owning browser timings use production esbuild without framework splitting. The creation census is separately identified as its existing unminified production observer, not the timed browser artifact.

Risk / follow-ups

Active consumers and the stateless binding controls above pay the disclosed size increases; all access the same implementations through the existing driver. The targeted timings measure complete synchronous public-root hook operations; they do not establish application latency, first-activation cost, or universal/tail equivalence. Current-head CI is green and the benchmark report agrees with the local rows sizes. The experimental stateless-binding refinements are parked; this published implementation is unchanged and maintainer review is still required.

Provenance

  • An agent produced this diff (agent-authored)

Codex task · implementation host com-79386.


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
Refactors hot paths in state, reducer, linked state, and deferred updates; behavior is intended to be unchanged but transition/Action edge cases are sensitive.

Overview
Routes transition hook staging and replay (stagedTransitionValue, stageTransitionValue, readQueuedTransition, and related helpers) through TransitionRootDriver instead of calling them directly from useState, useReducer, useLinkedState, and deferred-value scheduling.

Apps that never install the transition driver can tree-shake those six implementations; when the driver is absent, setters fall back to ordinary slot values and skip transition queuing. Staging still runs after functional updaters execute, so an updater that calls startTransition for the first time can install the driver and queue the update correctly.

Bundle tests now treat those declarations as optional and add state/linked-state coverage for async transitions started inside an updater.

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

@github-actions github-actions Bot added agent-authored Diff or issue body substantially produced by an AI agent perf PR: performance work labels Oct 10, 2026
@domgan-oai
domgan-oai marked this pull request as ready for review October 10, 2026 03:09
@github-actions

github-actions Bot commented Oct 10, 2026 •

Copy link
Copy Markdown
Contributor

Benchmark report

  • 🟡 js-framework: 1 timed operation(s) slower beyond ±3%
  • 🔴 bundle-size: 14 value(s) increased
  • 🔴 bundle-reachability: 21 value(s) increased

Compares a0c7f0e59, the merge commit's first parent with 4fa1a332f on the same runner. Any increase in a js-framework work counter fails this check; byte changes are a report. Wall time is a report: base and head samples alternate in one browser, and an operation is called slower or faster only when the 95% confidence interval of its ratio excludes ±3%. Workflow run

js-framework: 1k/10k row operations

target operation base ms head ms head/base 95% CI
octane-jsx select_lots 1.407 1.498 +6.9% +5.2% … +8.0% 🟡 slower
All 20 timed operations (19 without a verdict)
target operation base ms head ms head/base 95% CI
octane-tsrx run 2.392 2.383 +0.0% ±0.0% … +3.7% ⚪ within noise
octane-tsrx replace 5.183 5.233 +0.0% −1.6% … +3.2% ⚪ within noise
octane-tsrx add 2.433 2.308 ±0.0% ±0.0% … +2.1% ⚪ within noise
octane-tsrx update 0.119 0.120 +3.2% +0.9% … +5.0% ⚪ within noise
octane-tsrx select 0.005 0.005 +1.1% +0.5% … +1.7% ⚪ within noise
octane-tsrx swap 0.016 0.016 +2.6% −0.3% … +5.0% ⚪ within noise
octane-tsrx remove 0.013 0.013 +0.5% −1.0% … +2.1% ⚪ within noise
octane-tsrx runlots 25.175 23.808 −0.6% −3.4% … +1.3% ⚪ within noise
octane-tsrx select_lots 0.006 0.006 ±0.0% −1.2% … +0.9% ⚪ within noise
octane-tsrx clear 41.992 42.033 +0.7% −1.2% … +1.9% ⚪ within noise
octane-jsx run 3.267 3.258 −1.2% −2.9% … +1.4% ⚪ within noise
octane-jsx replace 5.700 6.225 −1.6% −6.6% … +1.6% ⚪ within noise
octane-jsx add 2.842 2.842 ±0.0% −0.0% … +3.3% ⚪ within noise
octane-jsx update 0.241 0.245 +0.6% −1.0% … +2.0% ⚪ within noise
octane-jsx select 0.129 0.130 +0.6% −0.5% … +1.7% ⚪ within noise
octane-jsx swap 0.171 0.170 ±0.0% −0.6% … +1.1% ⚪ within noise
octane-jsx remove 0.168 0.168 −0.6% −2.0% … +1.4% ⚪ within noise
octane-jsx runlots 29.650 27.967 −2.8% −4.9% … +0.7% ⚪ within noise
octane-jsx select_lots 1.407 1.498 +6.9% +5.2% … +8.0% 🟡 slower
octane-jsx clear 45.183 45.325 −0.1% −1.8% … +1.4% ⚪ within noise

Work counters (an increase fails this check):

target metric base head Δ
octane-tsrx calls_run 25,085 25,081 −4 (−0.0%) 🟢
octane-tsrx calls_replace 32,098 32,094 −4 (−0.0%) 🟢
octane-tsrx calls_add 33,084 33,080 −4 (−0.0%) 🟢
octane-tsrx calls_update 3,481 3,477 −4 (−0.1%) 🟢
octane-tsrx calls_select 83 79 −4 (−4.8%) 🟢
octane-tsrx calls_swap 2,095 2,091 −4 (−0.2%) 🟢
octane-tsrx calls_remove 3,100 3,096 −4 (−0.1%) 🟢
octane-tsrx calls_runlots 250,082 250,078 −4 (−0.0%) 🟢
octane-tsrx calls_select_lots 83 79 −4 (−4.8%) 🟢
octane-tsrx calls_clear 95 91 −4 (−4.2%) 🟢
octane-jsx calls_run 35,161 35,157 −4 (−0.0%) 🟢
octane-jsx calls_replace 42,176 42,172 −4 (−0.0%) 🟢
octane-jsx calls_add 50,162 50,158 −4 (−0.0%) 🟢
octane-jsx calls_update 9,659 9,655 −4 (−0.0%) 🟢
octane-jsx calls_select 9,163 9,159 −4 (−0.0%) 🟢
octane-jsx calls_swap 9,171 9,167 −4 (−0.0%) 🟢
octane-jsx calls_remove 9,176 9,172 −4 (−0.0%) 🟢
octane-jsx calls_runlots 350,158 350,154 −4 (−0.0%) 🟢
octane-jsx calls_select_lots 90,163 90,159 −4 (−0.0%) 🟢
octane-jsx calls_clear 173 169 −4 (−2.3%) 🟢

44 other measured values are unchanged.

Application bundle size (bytes)

target metric base head Δ
octane-tsrx js_raw 90,803 89,026 −1,777 (−2.0%) 🟢
octane-tsrx js_gzip 30,116 29,587 −529 (−1.8%) 🟢
octane-tsrx js_brotli 26,934 26,451 −483 (−1.8%) 🟢
octane-tsrx app_gzip 2,335 2,334 −1 (−0.0%) 🟢
octane-tsrx app_brotli 2,041 2,043 +2 (+0.1%) 🔴
octane-tsrx fw_raw 83,849 82,072 −1,777 (−2.1%) 🟢
octane-tsrx fw_gzip 27,781 27,253 −528 (−1.9%) 🟢
octane-tsrx fw_brotli 24,893 24,408 −485 (−1.9%) 🟢
octane-tsrx todo_js_raw 103,557 101,781 −1,776 (−1.7%) 🟢
octane-tsrx todo_js_gzip 34,789 34,207 −582 (−1.7%) 🟢
octane-tsrx todo_js_brotli 30,882 30,408 −474 (−1.5%) 🟢
octane-tsrx todo_app_brotli 1,901 1,906 +5 (+0.3%) 🔴
octane-tsrx todo_fw_raw 98,916 97,140 −1,776 (−1.8%) 🟢
octane-tsrx todo_fw_gzip 32,551 31,969 −582 (−1.8%) 🟢
octane-tsrx todo_fw_brotli 28,981 28,502 −479 (−1.7%) 🟢
octane-tsrx chat_js_raw 102,897 101,121 −1,776 (−1.7%) 🟢
octane-tsrx chat_js_gzip 34,677 34,150 −527 (−1.5%) 🟢
octane-tsrx chat_js_brotli 30,920 30,397 −523 (−1.7%) 🟢
octane-tsrx chat_fw_raw 97,114 95,338 −1,776 (−1.8%) 🟢
octane-tsrx chat_fw_gzip 31,951 31,424 −527 (−1.6%) 🟢
octane-tsrx chat_fw_brotli 28,528 28,005 −523 (−1.8%) 🟢
octane-tsrx weather_js_raw 138,047 136,271 −1,776 (−1.3%) 🟢
octane-tsrx weather_js_gzip 45,670 45,136 −534 (−1.2%) 🟢
octane-tsrx weather_js_brotli 40,251 39,842 −409 (−1.0%) 🟢
octane-tsrx weather_app_brotli 6,654 6,679 +25 (+0.4%) 🔴
octane-tsrx weather_fw_raw 115,873 114,097 −1,776 (−1.5%) 🟢
octane-tsrx weather_fw_gzip 37,814 37,280 −534 (−1.4%) 🟢
octane-tsrx weather_fw_brotli 33,597 33,163 −434 (−1.3%) 🟢
octane-tsrx bindings_js_raw 680,254 680,546 +292 (+0.0%) 🔴
octane-tsrx bindings_js_gzip 224,010 224,110 +100 (+0.0%) 🔴
octane-tsrx bindings_js_brotli 190,708 190,617 −91 (−0.0%) 🟢
octane-tsrx bindings_app_gzip 115,670 115,673 +3 (+0.0%) 🔴
octane-tsrx bindings_app_brotli 96,173 96,103 −70 (−0.1%) 🟢
octane-tsrx bindings_fw_raw 332,512 332,804 +292 (+0.1%) 🔴
octane-tsrx bindings_fw_gzip 108,340 108,437 +97 (+0.1%) 🔴
octane-tsrx bindings_fw_brotli 94,535 94,514 −21 (−0.0%) 🟢
octane-tsrx full_fw_raw 575,042 575,360 +318 (+0.1%) 🔴
octane-tsrx full_fw_gzip 173,761 173,868 +107 (+0.1%) 🔴
octane-tsrx full_fw_brotli 146,235 146,316 +81 (+0.1%) 🔴
octane-jsx js_raw 168,824 167,048 −1,776 (−1.1%) 🟢
octane-jsx js_gzip 54,685 54,147 −538 (−1.0%) 🟢
octane-jsx js_brotli 47,935 47,471 −464 (−1.0%) 🟢
octane-jsx app_gzip 2,861 2,860 −1 (−0.0%) 🟢
octane-jsx fw_raw 160,545 158,769 −1,776 (−1.1%) 🟢
octane-jsx fw_gzip 51,824 51,287 −537 (−1.0%) 🟢
octane-jsx fw_brotli 45,525 45,061 −464 (−1.0%) 🟢
octane-jsx full_fw_raw 575,042 575,360 +318 (+0.1%) 🔴
octane-jsx full_fw_gzip 173,761 173,868 +107 (+0.1%) 🔴
octane-jsx full_fw_brotli 146,235 146,316 +81 (+0.1%) 🔴

11 other measured values are unchanged.

Public-import reachability bundles (bytes)

target metric base head Δ
hooks-state raw 66,414 64,635 −1,779 (−2.7%) 🟢
hooks-state gzip 22,147 21,637 −510 (−2.3%) 🟢
hooks-state brotli 20,045 19,579 −466 (−2.3%) 🟢
prop-attributes raw 63,526 61,747 −1,779 (−2.8%) 🟢
prop-attributes gzip 21,292 20,782 −510 (−2.4%) 🟢
prop-attributes brotli 19,247 18,839 −408 (−2.1%) 🟢
context raw 72,490 70,711 −1,779 (−2.5%) 🟢
context gzip 24,109 23,570 −539 (−2.2%) 🟢
context brotli 21,759 21,240 −519 (−2.4%) 🟢
deferred-hydration raw 201,456 199,680 −1,776 (−0.9%) 🟢
deferred-hydration gzip 64,180 63,610 −570 (−0.9%) 🟢
deferred-hydration brotli 55,679 55,167 −512 (−0.9%) 🟢
hydrate-frame raw 350,689 348,913 −1,776 (−0.5%) 🟢
hydrate-frame gzip 110,522 109,963 −559 (−0.5%) 🟢
hydrate-frame brotli 94,734 94,402 −332 (−0.4%) 🟢
suspense-transition raw 124,561 124,736 +175 (+0.1%) 🔴
suspense-transition gzip 39,879 39,961 +82 (+0.2%) 🔴
suspense-transition brotli 35,332 35,374 +42 (+0.1%) 🔴
binding-base-ui-vite raw 188,030 189,755 +1,725 (+0.9%) 🔴
binding-base-ui-vite gzip 60,497 61,053 +556 (+0.9%) 🔴
binding-base-ui-vite brotli 52,988 53,417 +429 (+0.8%) 🔴
binding-base-ui-esbuild raw 215,375 217,047 +1,672 (+0.8%) 🔴
binding-base-ui-esbuild gzip 70,089 70,624 +535 (+0.8%) 🔴
binding-base-ui-esbuild brotli 60,952 61,362 +410 (+0.7%) 🔴
binding-radix-vite raw 188,392 190,117 +1,725 (+0.9%) 🔴
binding-radix-vite gzip 60,376 60,928 +552 (+0.9%) 🔴
binding-radix-vite brotli 52,813 53,292 +479 (+0.9%) 🔴
binding-radix-esbuild raw 215,521 217,193 +1,672 (+0.8%) 🔴
binding-radix-esbuild gzip 70,025 70,506 +481 (+0.7%) 🔴
binding-radix-esbuild brotli 60,876 61,261 +385 (+0.6%) 🔴
binding-mantine-hooks-vite raw 67,070 65,291 −1,779 (−2.7%) 🟢
binding-mantine-hooks-vite gzip 22,600 22,066 −534 (−2.4%) 🟢
binding-mantine-hooks-vite brotli 20,408 20,002 −406 (−2.0%) 🟢
binding-mantine-hooks-esbuild raw 78,952 77,190 −1,762 (−2.2%) 🟢
binding-mantine-hooks-esbuild gzip 27,293 26,733 −560 (−2.1%) 🟢
binding-mantine-hooks-esbuild brotli 24,410 23,936 −474 (−1.9%) 🟢
binding-apollo-client-vite raw 330,191 331,918 +1,727 (+0.5%) 🔴
binding-apollo-client-vite gzip 102,728 103,289 +561 (+0.5%) 🔴
binding-apollo-client-vite brotli 90,071 90,544 +473 (+0.5%) 🔴
binding-apollo-client-esbuild raw 365,547 367,219 +1,672 (+0.5%) 🔴
binding-apollo-client-esbuild gzip 116,510 117,031 +521 (+0.4%) 🔴
binding-apollo-client-esbuild brotli 101,808 102,147 +339 (+0.3%) 🔴
binding-usehooks-ts-vite raw 67,852 66,073 −1,779 (−2.6%) 🟢
binding-usehooks-ts-vite gzip 22,834 22,301 −533 (−2.3%) 🟢
binding-usehooks-ts-vite brotli 20,646 20,161 −485 (−2.3%) 🟢
binding-usehooks-ts-esbuild raw 79,726 77,964 −1,762 (−2.2%) 🟢
binding-usehooks-ts-esbuild gzip 27,513 26,960 −553 (−2.0%) 🟢
binding-usehooks-ts-esbuild brotli 24,667 24,157 −510 (−2.1%) 🟢

63 other measured values are unchanged.

@trueadm

trueadm commented Oct 10, 2026

Copy link
Copy Markdown
Collaborator

Good to go, with two non-blocking notes.

  1. Guards that can't fail. stagedTransitionValue and captureTransitionHookQueue are now reached only through the installed driver. Their TRANSITION_ROOT_DRIVER ? … : undefined checks can become direct heldUpdate(…) calls: L3240-L3243, L14526-L14528.
  2. Stateless probes (disclosed in the PR body). Base UI Separator, Radix Separator and ApolloProvider gain about 530–556 B gzip. They keep runTransition without any state hook, so the driver literal now brings all six helpers with it. The trade-off is fine for real apps, but why these stateless bindings reach runTransition at all is worth a follow-up issue.

Merge note: the conflicts with #1963, #1966, #1969 and #1970 in optional-driver-bundle.test.ts are append collisions. Whichever PR lands later must union the *_DECLARATIONS spreads in both resolveDeclarationRanges and the plain-app absence assertion. Otherwise one PR's absence check silently disappears and the test still passes. #1969 doesn't touch transition staging, so there's no semantic interaction.

Verified:

  • Every ! driver site depends on pendingActionBatch, renderTransition or a batch's updates. All of these come from batches that runTransition creates after ensureTransitionSwapDriver().
  • Reducer staging needs a live batch, and deferred values stage inside their own startTransition.
  • With no driver, the replaced calls returned slot.value or null anyway, so dormant behavior is unchanged.
  • The fresh-bundle tests discriminate: a driver cached before the updater would render 1 while pending.
  • Driver reads are truthiness-only and declared above every reader. perf-review-scan is clean.
  • The bot rows match the PR body (rows −559 B gzip TSRX, −541 B JSX).

@domgan-oai

Copy link
Copy Markdown
Contributor Author

Traced the stateless retention: public createElement enables descriptor form actions, which retain setFormAction → handleFormSubmit → startTransition → runTransition and the installed transition driver. Base UI and Radix call createElement; ApolloProvider does so internally even when its outer root is void-specialized.

The published head's Base UI Oxc/esbuild source maps confirm the whole chain. The available Radix/Apollo maps are baseline artifacts, so those support the unchanged source path rather than a new published-head measurement. The size increases remain disclosed in the description. Removing form-action capability from the general descriptor path would need a separate proof that preserves arbitrary props.

The two guard removals are safe optional follow-ups. I am leaving the qualified transition implementation unchanged in this feedback pass; the broader independent-binding experiments remain parked. The sibling declaration spreads are all retained in the combined validation fixture.

…ansition-owner-conflicts

# Conflicts:
#	packages/octane/tests/optional-driver-bundle.test.ts
…ansition-owner-conflicts

# Conflicts:
#	packages/octane/tests/optional-driver-bundle.test.ts
@trueadm
trueadm merged commit 8c09d81 into octanejs:main Oct 10, 2026
30 checks passed
@github-actions github-actions Bot mentioned this pull request Oct 10, 2026
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