Skip to content

perf: install event and store commit drains when used - #1969

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

trueadm merged 4 commits into
octanejs:mainfrom
openai-oss-forks:codex/commit-hook-owner

Conversation

@domgan-oai

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

Copy link
Copy Markdown
Contributor

Summary

Let apps that do not use useEffectEvent or useSyncExternalStore omit the corresponding commit drains. Each hook installs its existing drain when it first creates a cell. Queue ownership, capture/replay, call positions and both drain implementations are unchanged.

The runtime change adds two module bindings and two assignments in existing first-cell branches. It adds no per-update guard, call, allocation, record field or public API. A patch changeset is included.

Validation

Signed 01dcfba0f 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. An additional 65 targeted incoming-main regression executions pass on this branch using the repository’s dev/prod, signal and profiling projects. The earlier performance measurements retain their stated source and limitations.

  • pnpm format:check (repository-wide; scoped formatting passed)
  • pnpm typecheck (repository-wide; both changed TypeScript files passed)
  • pnpm test (repository-wide; left to CI)
  • pnpm sync; generated source unchanged.
  • Targeted tests: 8 fresh-production bundle cases and 160 owning dev/prod cases passed. Covers Effect Events, external-store tearing/shared state, aborted transitions, hydration and adjacent native staged publication.
  • Negative controls: omitting either hook's install fails on stale public values; eagerly retaining both drains fails the source-map absence gate.
  • check-staged-dom and scoped perf-review-scan pass; the scan reports no candidates. Both original drain bodies are unchanged.
  • Ordinary production TSRX/JSX: all 64 function-call, DOM and direct-list work counters match exactly, using the unchanged esbuild fixture configurations.
  • Matched complete production bundle gzip against fixed 4cc2a1: Oxc rows 32,140→31,901 (−239 B), JSX 54,702→54,452 (−250 B), Todo −227 B, chat −225 B and weather −239 B. Ordinary esbuild rows 37,614→37,408 (−206 B), JSX 65,062→64,793 (−269 B).
  • Additional Oxc/esbuild feature controls: minimal Base UI −232/−274 B and active Suspense −236/−240 B. The unused drain bodies are absent; full-API controls retain both.
  • Owning production work: complete-flow calls match exactly (Effect Event 68,961; store 72,127), with equal DOM/semantics and zero asset calls in each final quiet observation. Separate named diagnostics verify 1001 default calls before activation and matching concrete-drain calls afterward.
  • Owning Chromium 149 timing: 16 fresh-process groups per candidate/identical cohort, 10 warmup and 12 retained windows per group, after unrelated layout commits warm the default targets. Event candidate/base 0.99800[0.98935,1.00541]; store 0.99287[0.98512,1.00745]. Both primary 95% intervals span 1. Identical controls and first-use uncertainty are retained below.
  • perf-review: runtime.ts:11356/11386 remain hot commit calls; runtime.ts:16056/16151 add only first-cell assignments. Shapes, DOM operations, scheduling and queue records are unchanged. Ordinary and complete owning deterministic work are equal. Both steady owning timings show no detected slowdown; first-use and identical-control limitations are disclosed below. Independent source and evidence review found no must-fix issue; all timing controls and uncertainty are retained.
  • concise-code: runtime +8/−2 lines, tests +88/−2, one release changeset; no module or export added. Reuses the existing noop and queue consumers. A capability object, consumer guards, or an extra action-drain gate add machinery without earning this change's scope.

Risk / follow-ups

CI recorded JSX clear +0.78% (nominal 95% CI +0.22–1.48%) in one paired browser run; retained as an unconfirmed timing difference. No slowdown was detected in the independently grouped owning workloads; no universal parity claim.

Feature-retaining controls pay small gzip overhead: +20 B in the canonical bindings app, +69 B in the canonical full-framework ceiling, and +69/+12 B in the Oxc/esbuild full-API IIFE controls. The event first-owned-commit interval is broad: 1.00449[0.96684,1.07692]; store 0.99683[0.97371,1.02649]. The store identical-code control is positive, 1.00843[1.00117,1.02466], so it indicates measurement variation and is not subtracted from the candidate. This does not establish tight cold-path equivalence.

Phase profiling saw post-paint transport cross CDP capture boundaries. Complete-flow work includes every call through cleanup and a fixed foreground 300ms delivery observation plus 50ms with no asset calls; it is not a universal scheduler-quiescence claim. Original phase failures are preserved, including one earlier unminified four-call discrepancy without historical function attribution.

The adjacent native staged-publication suite is not direct proof of first activation from a native replay. Original queue/capture bodies and producer ownership are preserved; late activation is tested in fresh production realms.

Provenance

  • An agent produced this diff (agent-authored)

Codex task, implementation subtask retention_audit; 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

Low Risk
Small runtime wiring change with existing drain bodies unchanged; risk is mainly missing late activation if first-cell install were wrong, which new bundle and behavioral tests cover.

Overview
Lazy-installs Effect Event and external-store commit drains so production bundles that never use useEffectEvent or useSyncExternalStore can drop the drain implementations.

The runtime adds module bindings drainEffectEventUpdates and drainStoreSyncs that default to noop; the real logic moves to drainQueuedEffectEventUpdates and drainQueuedStoreSyncs, which are wired on first cell creation in each hook. Commit still calls the same indirection—no new per-update guards or API changes. A patch changeset documents the tree-shake win.

Bundle tests treat those queued drain declarations like other optional commit code: plain apps must omit them; apps that mount the hooks after a plain root must retain them and keep commit semantics (stable effect events, store tearing checks).

Reviewed by Cursor Bugbot for commit 01dcfba. 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 05:32
@github-actions

github-actions Bot commented Oct 10, 2026 •

Copy link
Copy Markdown
Contributor

Benchmark report

  • 🔴 bundle-size: 15 value(s) increased

Compares 64c33de2f, the merge commit's first parent with 8d193b138 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

All 20 timed operations (20 without a verdict)
target operation base ms head ms head/base 95% CI
octane-tsrx run 2.725 2.642 ±0.0% −3.6% … +1.7% ⚪ within noise
octane-tsrx replace 5.825 5.725 −0.8% −1.7% … +2.6% ⚪ within noise
octane-tsrx add 2.475 2.450 ±0.0% −0.0% … +4.0% ⚪ within noise
octane-tsrx update 0.126 0.124 −0.3% −4.4% … +1.1% ⚪ within noise
octane-tsrx select 0.006 0.006 +1.5% +1.4% … +2.2% ⚪ within noise
octane-tsrx swap 0.017 0.017 −1.4% −5.3% … −0.3% ⚪ within noise
octane-tsrx remove 0.014 0.015 ±0.0% −1.8% … +0.4% ⚪ within noise
octane-tsrx runlots 25.508 25.592 +0.8% −1.0% … +2.4% ⚪ within noise
octane-tsrx select_lots 0.006 0.006 −0.0% −2.0% … +0.6% ⚪ within noise
octane-tsrx clear 37.917 38.008 −0.4% −2.5% … +2.8% ⚪ within noise
octane-jsx run 3.400 3.408 ±0.0% −2.7% … +2.7% ⚪ within noise
octane-jsx replace 6.767 6.992 −0.0% −1.4% … +1.5% ⚪ within noise
octane-jsx add 3.225 3.258 −0.0% −3.0% … ±0.0% ⚪ within noise
octane-jsx update 0.259 0.260 −0.7% −2.4% … +1.2% ⚪ within noise
octane-jsx select 0.135 0.135 −0.6% −1.8% … +1.2% ⚪ within noise
octane-jsx swap 0.173 0.175 −0.0% −1.8% … +1.8% ⚪ within noise
octane-jsx remove 0.164 0.165 +0.7% −1.3% … +1.4% ⚪ within noise
octane-jsx runlots 29.342 30.050 −1.0% −2.8% … +0.8% ⚪ within noise
octane-jsx select_lots 1.661 1.701 +0.9% −1.2% … +4.4% ⚪ within noise
octane-jsx clear 36.700 38.558 +5.2% +1.1% … +10.0% ⚪ within noise

All 64 work counters are unchanged.

Application bundle size (bytes)

target metric base head Δ
octane-tsrx js_raw 91,668 90,730 −938 (−1.0%) 🟢
octane-tsrx js_gzip 30,348 30,094 −254 (−0.8%) 🟢
octane-tsrx js_brotli 27,160 26,891 −269 (−1.0%) 🟢
octane-tsrx app_gzip 2,334 2,335 +1 (+0.0%) 🔴
octane-tsrx app_brotli 2,034 2,033 −1 (−0.0%) 🟢
octane-tsrx fw_raw 84,714 83,776 −938 (−1.1%) 🟢
octane-tsrx fw_gzip 28,014 27,759 −255 (−0.9%) 🟢
octane-tsrx fw_brotli 25,126 24,858 −268 (−1.1%) 🟢
octane-tsrx todo_js_raw 103,223 102,285 −938 (−0.9%) 🟢
octane-tsrx todo_js_gzip 34,614 34,353 −261 (−0.8%) 🟢
octane-tsrx todo_js_brotli 30,778 30,505 −273 (−0.9%) 🟢
octane-tsrx todo_app_gzip 2,237 2,236 −1 (−0.0%) 🟢
octane-tsrx todo_app_brotli 1,900 1,901 +1 (+0.1%) 🔴
octane-tsrx todo_fw_raw 98,582 97,644 −938 (−1.0%) 🟢
octane-tsrx todo_fw_gzip 32,377 32,117 −260 (−0.8%) 🟢
octane-tsrx todo_fw_brotli 28,878 28,604 −274 (−0.9%) 🟢
octane-tsrx chat_js_raw 102,563 101,625 −938 (−0.9%) 🟢
octane-tsrx chat_js_gzip 34,526 34,280 −246 (−0.7%) 🟢
octane-tsrx chat_js_brotli 30,775 30,557 −218 (−0.7%) 🟢
octane-tsrx chat_app_gzip 2,725 2,724 −1 (−0.0%) 🟢
octane-tsrx chat_app_brotli 2,401 2,390 −11 (−0.5%) 🟢
octane-tsrx chat_fw_raw 96,780 95,842 −938 (−1.0%) 🟢
octane-tsrx chat_fw_gzip 31,801 31,556 −245 (−0.8%) 🟢
octane-tsrx chat_fw_brotli 28,374 28,167 −207 (−0.7%) 🟢
octane-tsrx weather_js_raw 138,758 137,995 −763 (−0.5%) 🟢
octane-tsrx weather_js_gzip 45,886 45,664 −222 (−0.5%) 🟢
octane-tsrx weather_js_brotli 40,409 40,273 −136 (−0.3%) 🟢
octane-tsrx weather_app_gzip 7,858 7,857 −1 (−0.0%) 🟢
octane-tsrx weather_app_brotli 6,658 6,681 +23 (+0.3%) 🔴
octane-tsrx weather_fw_raw 116,584 115,821 −763 (−0.7%) 🟢
octane-tsrx weather_fw_gzip 38,028 37,807 −221 (−0.6%) 🟢
octane-tsrx weather_fw_brotli 33,751 33,592 −159 (−0.5%) 🟢
octane-tsrx bindings_js_raw 678,953 678,975 +22 (+0.0%) 🔴
octane-tsrx bindings_js_gzip 223,605 223,607 +2 (+0.0%) 🔴
octane-tsrx bindings_js_brotli 190,315 190,322 +7 (+0.0%) 🔴
octane-tsrx bindings_app_gzip 115,672 115,670 −2 (−0.0%) 🟢
octane-tsrx bindings_app_brotli 96,215 96,231 +16 (+0.0%) 🔴
octane-tsrx bindings_fw_raw 331,211 331,233 +22 (+0.0%) 🔴
octane-tsrx bindings_fw_gzip 107,933 107,937 +4 (+0.0%) 🔴
octane-tsrx bindings_fw_brotli 94,100 94,091 −9 (−0.0%) 🟢
octane-tsrx full_fw_raw 573,673 573,697 +24 (+0.0%) 🔴
octane-tsrx full_fw_gzip 173,344 173,364 +20 (+0.0%) 🔴
octane-tsrx full_fw_brotli 145,821 145,879 +58 (+0.0%) 🔴
octane-jsx js_raw 168,403 167,550 −853 (−0.5%) 🟢
octane-jsx js_gzip 54,552 54,322 −230 (−0.4%) 🟢
octane-jsx js_brotli 47,818 47,666 −152 (−0.3%) 🟢
octane-jsx app_gzip 2,862 2,860 −2 (−0.1%) 🟢
octane-jsx app_brotli 2,414 2,411 −3 (−0.1%) 🟢
octane-jsx fw_raw 160,124 159,271 −853 (−0.5%) 🟢
octane-jsx fw_gzip 51,690 51,462 −228 (−0.4%) 🟢
octane-jsx fw_brotli 45,404 45,255 −149 (−0.3%) 🟢
octane-jsx full_fw_raw 573,673 573,697 +24 (+0.0%) 🔴
octane-jsx full_fw_gzip 173,344 173,364 +20 (+0.0%) 🔴
octane-jsx full_fw_brotli 145,821 145,879 +58 (+0.0%) 🔴

6 other measured values are unchanged.

Public-import reachability bundles (bytes)

target metric base head Δ
cli-spa-starter raw 83,280 82,342 −938 (−1.1%) 🟢
cli-spa-starter gzip 28,530 28,256 −274 (−1.0%) 🟢
cli-spa-starter brotli 25,350 25,151 −199 (−0.8%) 🟢
root-static-specialized raw 55,064 54,126 −938 (−1.7%) 🟢
root-static-specialized gzip 18,626 18,370 −256 (−1.4%) 🟢
root-static-specialized brotli 16,880 16,658 −222 (−1.3%) 🟢
root-chained-jsx raw 57,417 56,478 −939 (−1.6%) 🟢
root-chained-jsx gzip 19,328 19,061 −267 (−1.4%) 🟢
root-chained-jsx brotli 17,508 17,269 −239 (−1.4%) 🟢
root-static raw 148,149 147,298 −851 (−0.6%) 🟢
root-static gzip 48,004 47,783 −221 (−0.5%) 🟢
root-static brotli 42,271 42,088 −183 (−0.4%) 🟢
root-static-local raw 55,063 54,125 −938 (−1.7%) 🟢
root-static-local gzip 18,613 18,358 −255 (−1.4%) 🟢
root-static-local brotli 16,886 16,661 −225 (−1.3%) 🟢
root-callback-local raw 57,876 56,939 −937 (−1.6%) 🟢
root-callback-local gzip 19,437 19,185 −252 (−1.3%) 🟢
root-callback-local brotli 17,599 17,382 −217 (−1.2%) 🟢
hooks-state raw 67,212 66,362 −850 (−1.3%) 🟢
hooks-state gzip 22,364 22,123 −241 (−1.1%) 🟢
hooks-state brotli 20,211 20,021 −190 (−0.9%) 🟢
prop-attributes raw 64,412 63,474 −938 (−1.5%) 🟢
prop-attributes gzip 21,545 21,271 −274 (−1.3%) 🟢
prop-attributes brotli 19,476 19,243 −233 (−1.2%) 🟢
context raw 73,376 72,438 −938 (−1.3%) 🟢
context gzip 24,365 24,103 −262 (−1.1%) 🟢
context brotli 21,954 21,721 −233 (−1.1%) 🟢
hydrate-root raw 118,628 117,690 −938 (−0.8%) 🟢
hydrate-root gzip 38,595 38,316 −279 (−0.7%) 🟢
hydrate-root brotli 34,071 33,817 −254 (−0.7%) 🟢
deferred-hydration raw 202,146 201,383 −763 (−0.4%) 🟢
deferred-hydration gzip 64,368 64,147 −221 (−0.3%) 🟢
deferred-hydration brotli 55,770 55,566 −204 (−0.4%) 🟢
hydrate-frame raw 350,289 349,409 −880 (−0.3%) 🟢
hydrate-frame gzip 110,343 110,090 −253 (−0.2%) 🟢
hydrate-frame brotli 94,582 94,519 −63 (−0.1%) 🟢
suspense-transition raw 125,360 124,509 −851 (−0.7%) 🟢
suspense-transition gzip 40,079 39,867 −212 (−0.5%) 🟢
suspense-transition brotli 35,504 35,323 −181 (−0.5%) 🟢
component-owned-effects raw 57,881 56,943 −938 (−1.6%) 🟢
component-owned-effects gzip 19,493 19,239 −254 (−1.3%) 🟢
component-owned-effects brotli 17,668 17,443 −225 (−1.3%) 🟢
binding-hooks raw 67,794 67,236 −558 (−0.8%) 🟢
binding-hooks gzip 22,923 22,784 −139 (−0.6%) 🟢
binding-hooks brotli 20,730 20,627 −103 (−0.5%) 🟢
binding-base-ui-vite raw 187,606 186,755 −851 (−0.5%) 🟢
binding-base-ui-vite gzip 60,315 60,076 −239 (−0.4%) 🟢
binding-base-ui-vite brotli 52,723 52,597 −126 (−0.2%) 🟢
binding-base-ui-esbuild raw 214,932 214,058 −874 (−0.4%) 🟢
binding-base-ui-esbuild gzip 69,905 69,638 −267 (−0.4%) 🟢
binding-base-ui-esbuild brotli 60,733 60,558 −175 (−0.3%) 🟢
binding-radix-vite raw 187,968 187,117 −851 (−0.5%) 🟢
binding-radix-vite gzip 60,222 59,969 −253 (−0.4%) 🟢
binding-radix-vite brotli 52,628 52,467 −161 (−0.3%) 🟢
binding-radix-esbuild raw 215,078 214,204 −874 (−0.4%) 🟢
binding-radix-esbuild gzip 69,811 69,581 −230 (−0.3%) 🟢
binding-radix-esbuild brotli 60,611 60,463 −148 (−0.2%) 🟢
binding-mantine-hooks-vite raw 67,956 67,018 −938 (−1.4%) 🟢
binding-mantine-hooks-vite gzip 22,834 22,582 −252 (−1.1%) 🟢
binding-mantine-hooks-vite brotli 20,651 20,406 −245 (−1.2%) 🟢
binding-mantine-hooks-esbuild raw 79,715 78,752 −963 (−1.2%) 🟢
binding-mantine-hooks-esbuild gzip 27,491 27,226 −265 (−1.0%) 🟢
binding-mantine-hooks-esbuild brotli 24,596 24,352 −244 (−1.0%) 🟢
binding-apollo-client-vite raw 329,763 328,912 −851 (−0.3%) 🟢
binding-apollo-client-vite gzip 102,534 102,292 −242 (−0.2%) 🟢
binding-apollo-client-vite brotli 89,882 89,744 −138 (−0.2%) 🟢
binding-apollo-client-esbuild raw 365,103 364,229 −874 (−0.2%) 🟢
binding-apollo-client-esbuild gzip 116,306 116,085 −221 (−0.2%) 🟢
binding-apollo-client-esbuild brotli 101,424 101,231 −193 (−0.2%) 🟢
binding-usehooks-ts-vite raw 68,738 67,800 −938 (−1.4%) 🟢
binding-usehooks-ts-vite gzip 23,062 22,809 −253 (−1.1%) 🟢
binding-usehooks-ts-vite brotli 20,896 20,619 −277 (−1.3%) 🟢
binding-usehooks-ts-esbuild raw 80,489 79,526 −963 (−1.2%) 🟢
binding-usehooks-ts-esbuild gzip 27,731 27,458 −273 (−1.0%) 🟢
binding-usehooks-ts-esbuild brotli 24,818 24,587 −231 (−0.9%) 🟢

36 other measured values are unchanged.

@trueadm

trueadm commented Oct 10, 2026

Copy link
Copy Markdown
Collaborator

Good to go. Both drains are installed before any entry can reach their queues, and the sibling-PR conflicts are append-only.

Correctness

  • enqueueStoreSync is reached only from useSyncExternalStore's mount branch, right after the install at L16056, or from the update branch, which needs an existing cell. enqueueEffectEventUpdate is reached only from the else branch at L16159, after the install at L16151.
  • The WIP, staged-commit and deferred-layout captures only move entries those producers created. The install is never undone, and L11250, L11356 and L11386 call the live binding. So nested flushSync, rollback, hydration, Activity and multiple roots can't leave an entry behind.

Merge note: the conflicts with #1963, #1964, #1966 and #1970 all sit at the same three anchors in optional-driver-bundle.test.ts (L43, L370, L401). Keep both sides, including every *_DECLARATIONS spread in the plain-app absence assertion. runtime.ts auto-merges, and none of those PRs gate anything these drains call.

Verified:

  • The bot report matches the PR body: Oxc −239 B gzip, JSX −250 B, feature-retaining rows +21/+69 B. All 64 work counters are unchanged and timings are within noise.
  • perf-review-scan is clean. The noop default follows the existing runLayoutEffects pattern and is declared above every reader, with no identity comparison and no new field or per-commit branch.
  • The late-install it.each checks values, not only bytes: without the install it fails on a stale effect-event callback or a torn store under flushSync.

…mmit-hook-owner

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

# Conflicts:
#	packages/octane/tests/optional-driver-bundle.test.ts
@trueadm
trueadm merged commit a0c7f0e into octanejs:main Oct 10, 2026
31 checks passed
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