Skip to content

perf(octane): inline fixed-arity snapshot clones - #1971

Merged
trueadm merged 3 commits into
octanejs:mainfrom
openai-oss-forks:codex/clone-arm-bundle
Oct 10, 2026
Merged

trueadm merged 3 commits into
octanejs:mainfrom
openai-oss-forks:codex/clone-arm-bundle

Conversation

@domgan-oai

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

Copy link
Copy Markdown
Contributor

Summary

Inline each fixed-arity binding snapshot into its existing dispatcher arm, removing 17 private wrapper functions while preserving a separate object-spread site for every arity and the unchanged default. A fixed snapshot now makes one fewer helper call; its copied values, object allocation, journal window and rollback behavior are unchanged.

Matched complete-production-JavaScript gzip bytes against fixed base 4cc2a1ed, with Node 24.20.0:

Fixture Canonical Oxc Ordinary/direct esbuild
TSRX rows 32,140 → 32,027 (−113 B) 37,614 → 37,502 (−112 B)
JSX rows 54,702 → 54,609 (−93 B) 65,062 → 64,958 (−104 B)
Full API namespace 173,436 → 173,363 (−73 B) 181,372 → 181,259 (−113 B)

Rows raw output drops 476 bytes in both minifiers. All six emitted dispatchers preserve 18 distinct spread sites. These are measured standalone totals; broader composed-bundle probes are not added to them.

Why

The wrappers exist to keep the spread feedback for distinct bag arities separate. Distinct dispatcher arms preserve those sites without retaining separate wrapper functions. This is a small bundle reduction, not completion of the wider bundle target.

Changes

  • Replace the 17 wrapper calls with the same shallow spread expressions in their existing arms; preserve all 18 spread sites including default.
  • Keep the existing regression scenarios and benchmark operations. No public API, hot-record field, cache, scheduler work or per-node allocation is added.
  • Add an Octane patch changeset.

Validation

  • pnpm format:check — authored-file formatting and current-head CI lint/format checks pass.
  • pnpm typecheck — runtime/index scoped typechecks pass without diagnostics; full current-head CI typechecks also pass.
  • pnpm test — all four Node 24 test shards and aggregate gate pass on current head; React parity, Chromium integration, package validation and example builds also pass.
  • Targeted tests: 22 selected dev/prod executions pass: first-thenable/root-input holds, generic snapshot values, and accepted row inputs including SSR/hydration. The two filtered hold cases intentionally skip unrelated scenarios.
  • Regression sensitivity: returning the original bag instead of a copy in fixed arms fails all four public retry assertions, leaving original/external text instead of the replacement. Restoring the change passes all four again. The default generic clone remains unchanged in this control.
  • Exact inverse proof reconstructs the complete baseline runtime. All 255 package files are pinned; only runtime differs. Separate source review is clean.
  • Original ordinary production work: all 64 metrics pass on matched esbuild/no-split fixtures. 58 are equal and six call metrics decrease, with no increase: TSRX/JSX update each remove 100 calls, and each dialect's select/select_lots removes one call. DOM and direct-insertion counts are unchanged.
  • perf-review: mechanical scan reports zero candidates. One shallow object allocation and one spread site per arity remain; the existing arity switch and journal publication order are unchanged. The mixed-shape owning work and timings below qualify this boundary change with finite uncertainty.
  • concise-code: runtime +19/−36; removes 17 private functions, adds no module/export/type/option/field. A single shared spread would lose the existing arity-specific feedback and is not used. The only new file is the patch changeset.
  • Matched rows/JSX/full-API byte checks and 18 emitted spread-site guards pass in both minifiers.
  • Mixed-shape owning work: five fixed bag arities (5/7/9/11/13) in one dispatcher, plus a reached arity 2 on retry. Both minifiers preserve output, title, native handler, input, effect/cleanup and node identity. Clean production calls fall by 320 across 64 updates and 16 across held attempts+retry, exactly matching fixed snapshot counts; no DOM or snapshot increase, quiet checks zero.
  • Final independent source and evidence review is clean.
  • pnpm sync passed before signed publication; all 255 frozen package files remain unchanged.

Risk / follow-ups

The owning browser timing uses Node 24.20.0, bundled Chromium 149.0.7827.55 and clean production esbuild artifacts. Each operation has 16 independent fresh browser-process groups per actual and identical-baseline cohort, 10 warmup and 12 retained pairs per group, balanced order and group arithmetic means as the primary bootstrap unit. All 64 groups and 1,408 pairs are retained, with no errors or exclusions.

Owning workload Candidate/baseline [95% interval] Identical-code control
Five-arity changing updates 0.9947 [0.9656, 1.0191] 1.0022 [0.9901, 1.0219]
Five-arity held rollback 0.9927 [0.9828, 1.0041] 1.0036 [0.9817, 1.0193]

No slowdown was detected in these prespecified warmed workloads; the primary intervals permit up to +1.91% and+0.41%. Actual held-request resolution and retry correctness are verified outside the timer. First affected calls are recorded separately and less precise, with candidate upper bounds +3.45%/+6.58%. An identical-update execution-order partition is positive (1.0329 [1.0100, 1.0452]); it is retained without normalizing candidate results. These measurements do not establish a speedup, universal parity or tail latency. Independent final evidence review is clean.

The current-head CI benchmark report confirms the rows/JSX reductions and all 64 work-counter results above. Its synthetic merge dd39d85cc has the exact same Git tree as published head ee6ee4749. Other complete-bundle gzip changes are Todo −113 B, chat −129 B, weather −111 B and bindings −57 B.

CI labels all 20 timings within its ±3% verdict threshold, but two 95% intervals are strictly positive: TSRX clear +2.6% [+1.4%, +3.9%] and JSX large-list selection +1.3% [+0.3%, +3.8%]. These observations remain recorded; the direct mixed-arity snapshot measurements do not establish universal ordinary-row neutrality. One prespecified local follow-up measured TSRX clear only. JSX large-list selection remains a separate, unconfirmed CI observation; no broad CI or benchmark rerun was performed.

The clear follow-up reuses the exact ordinary esbuild artifacts and original 10,000-row prepare/clear operation with one click per window. It retains 12 independent fresh browser-process groups per actual and identical-baseline cohort, six warmup and ten retained pairs per group, plus a separate first-clear pair. All 24 groups, 384 warmup/retained pairs and 24 first-clear pairs are preserved, with balanced order, matching serialized inputs, empty-table checks and no retained deleted-node arrays. All 843 source/config pins and eight artifacts, styles/clocks and error gates pass; independent review reproduced the statistics.

No statistically resolved slowdown was detected in this local fresh-clear cohort: candidate/baseline 1.0054 [0.9930, 1.0227], identical-code control 1.0016 [0.9891, 1.0235]. The candidate interval permits +2.27% and overlaps part of the original CI interval; it does not disprove that observation or prove unchanged performance. First-clear uncertainty is broader, permitting +4.62%. Retained clears take 19.24–33.94 ms without timing-based repetition or exclusions. This is a fresh-operation host/history, not a replay of the complete preceding CI sequence. Both original CI observations and the owning cold/order limitations remain disclosed.

Current head ee6ee4749 has green CI and no open review threads. Independent source and local evidence review are complete for this focused scope with the uncertainty above; maintainer approval remains required. No merge is requested.

Provenance

  • An agent produced this diff (agent-authored)

Codex task · implementation subtask duplication_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
Mechanical refactor inside private runtime cloning; extensive regression and bundle-size checks reported, with no public API changes.

Overview
Shrinks the Octane production bundle by removing seventeen private cloneBagN helpers and inlining { ...bag } in each cloneBindingBag switch arm.

Behavior is unchanged: every arity (including default) still has its own object-spread site for monomorphic cloning, and binding snapshot copy / journal rollback semantics stay the same. An Octane patch changeset documents the size win.

Reviewed by Cursor Bugbot for commit 329f5bc. 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 07:30
@github-actions

github-actions Bot commented Oct 10, 2026 •

Copy link
Copy Markdown
Contributor

Benchmark report

  • 🔴 bundle-size: 4 value(s) increased
  • 🔴 bundle-reachability: 1 value(s) increased

Compares 5d6d02c8b, the merge commit's first parent with 49b54f569 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.417 2.383 −0.0% −3.8% … +1.9% ⚪ within noise
octane-tsrx replace 5.317 5.175 −1.0% −4.8% … +3.5% ⚪ within noise
octane-tsrx add 2.333 2.317 ±0.0% −4.2% … +0.0% ⚪ within noise
octane-tsrx update 0.124 0.129 +2.3% −0.0% … +4.4% ⚪ within noise
octane-tsrx select 0.005 0.005 +0.6% −0.6% … +1.2% ⚪ within noise
octane-tsrx swap 0.017 0.017 +1.2% −1.0% … +5.7% ⚪ within noise
octane-tsrx remove 0.014 0.014 ±0.0% −2.8% … +3.0% ⚪ within noise
octane-tsrx runlots 23.150 22.825 −1.0% −2.9% … +0.4% ⚪ within noise
octane-tsrx select_lots 0.005 0.006 +1.6% +0.6% … +1.9% ⚪ within noise
octane-tsrx clear 38.583 39.000 +1.2% +0.3% … +2.6% ⚪ within noise
octane-jsx run 3.092 3.033 −2.9% −5.6% … ±0.0% ⚪ within noise
octane-jsx replace 5.683 5.700 ±0.0% −1.8% … +1.7% ⚪ within noise
octane-jsx add 2.983 2.933 −3.3% −3.4% … ±0.0% ⚪ within noise
octane-jsx update 0.232 0.234 +1.1% −2.0% … +2.8% ⚪ within noise
octane-jsx select 0.124 0.122 −0.8% −1.5% … ±0.0% ⚪ within noise
octane-jsx swap 0.169 0.164 +0.3% −1.1% … +1.8% ⚪ within noise
octane-jsx remove 0.159 0.158 −1.3% −3.0% … +0.9% ⚪ within noise
octane-jsx runlots 26.500 26.292 +0.4% −1.7% … +1.7% ⚪ within noise
octane-jsx select_lots 1.379 1.369 −1.8% −3.6% … −0.6% ⚪ within noise
octane-jsx clear 39.983 43.058 +3.9% +1.8% … +5.6% ⚪ within noise

Work counters (an increase fails this check):

target metric base head Δ
octane-tsrx calls_update 3,581 3,481 −100 (−2.8%) 🟢
octane-tsrx calls_select 84 83 −1 (−1.2%) 🟢
octane-tsrx calls_select_lots 84 83 −1 (−1.2%) 🟢
octane-jsx calls_update 9,759 9,659 −100 (−1.0%) 🟢
octane-jsx calls_select 9,164 9,163 −1 (−0.0%) 🟢
octane-jsx calls_select_lots 90,164 90,163 −1 (−0.0%) 🟢

58 other measured values are unchanged.

Application bundle size (bytes)

target metric base head Δ
octane-tsrx js_raw 97,028 96,552 −476 (−0.5%) 🟢
octane-tsrx js_gzip 32,140 32,027 −113 (−0.4%) 🟢
octane-tsrx js_brotli 28,691 28,683 −8 (−0.0%) 🟢
octane-tsrx app_gzip 2,336 2,337 +1 (+0.0%) 🔴
octane-tsrx fw_raw 90,080 89,604 −476 (−0.5%) 🟢
octane-tsrx fw_gzip 29,804 29,690 −114 (−0.4%) 🟢
octane-tsrx fw_brotli 26,656 26,648 −8 (−0.0%) 🟢
octane-tsrx todo_js_raw 106,549 106,073 −476 (−0.4%) 🟢
octane-tsrx todo_js_gzip 35,661 35,548 −113 (−0.3%) 🟢
octane-tsrx todo_js_brotli 31,675 31,581 −94 (−0.3%) 🟢
octane-tsrx todo_app_brotli 1,890 1,885 −5 (−0.3%) 🟢
octane-tsrx todo_fw_raw 101,923 101,447 −476 (−0.5%) 🟢
octane-tsrx todo_fw_gzip 33,438 33,325 −113 (−0.3%) 🟢
octane-tsrx todo_fw_brotli 29,785 29,696 −89 (−0.3%) 🟢
octane-tsrx chat_js_raw 105,890 105,414 −476 (−0.4%) 🟢
octane-tsrx chat_js_gzip 35,532 35,403 −129 (−0.4%) 🟢
octane-tsrx chat_js_brotli 31,662 31,627 −35 (−0.1%) 🟢
octane-tsrx chat_app_gzip 2,719 2,716 −3 (−0.1%) 🟢
octane-tsrx chat_app_brotli 2,387 2,382 −5 (−0.2%) 🟢
octane-tsrx chat_fw_raw 100,119 99,643 −476 (−0.5%) 🟢
octane-tsrx chat_fw_gzip 32,813 32,687 −126 (−0.4%) 🟢
octane-tsrx chat_fw_brotli 29,275 29,245 −30 (−0.1%) 🟢
octane-tsrx weather_js_raw 141,657 141,181 −476 (−0.3%) 🟢
octane-tsrx weather_js_gzip 46,924 46,813 −111 (−0.2%) 🟢
octane-tsrx weather_js_brotli 41,372 41,296 −76 (−0.2%) 🟢
octane-tsrx weather_app_gzip 7,843 7,844 +1 (+0.0%) 🔴
octane-tsrx weather_app_brotli 6,668 6,693 +25 (+0.4%) 🔴
octane-tsrx weather_fw_raw 119,496 119,020 −476 (−0.4%) 🟢
octane-tsrx weather_fw_gzip 39,081 38,969 −112 (−0.3%) 🟢
octane-tsrx weather_fw_brotli 34,704 34,603 −101 (−0.3%) 🟢
octane-tsrx bindings_js_raw 678,782 678,306 −476 (−0.1%) 🟢
octane-tsrx bindings_js_gzip 223,608 223,551 −57 (−0.0%) 🟢
octane-tsrx bindings_js_brotli 190,412 190,297 −115 (−0.1%) 🟢
octane-tsrx bindings_app_brotli 96,316 96,337 +21 (+0.0%) 🔴
octane-tsrx bindings_fw_raw 331,129 330,653 −476 (−0.1%) 🟢
octane-tsrx bindings_fw_gzip 107,925 107,868 −57 (−0.1%) 🟢
octane-tsrx bindings_fw_brotli 94,096 93,960 −136 (−0.1%) 🟢
octane-tsrx full_fw_raw 573,378 572,896 −482 (−0.1%) 🟢
octane-tsrx full_fw_gzip 173,333 173,260 −73 (−0.0%) 🟢
octane-tsrx full_fw_brotli 145,784 145,616 −168 (−0.1%) 🟢
octane-jsx js_raw 168,819 168,345 −474 (−0.3%) 🟢
octane-jsx js_gzip 54,702 54,609 −93 (−0.2%) 🟢
octane-jsx js_brotli 47,981 47,808 −173 (−0.4%) 🟢
octane-jsx app_gzip 2,859 2,858 −1 (−0.0%) 🟢
octane-jsx app_brotli 2,410 2,408 −2 (−0.1%) 🟢
octane-jsx fw_raw 160,546 160,072 −474 (−0.3%) 🟢
octane-jsx fw_gzip 51,843 51,751 −92 (−0.2%) 🟢
octane-jsx fw_brotli 45,571 45,400 −171 (−0.4%) 🟢
octane-jsx full_fw_raw 573,378 572,896 −482 (−0.1%) 🟢
octane-jsx full_fw_gzip 173,333 173,260 −73 (−0.0%) 🟢
octane-jsx full_fw_brotli 145,784 145,616 −168 (−0.1%) 🟢

9 other measured values are unchanged.

Public-import reachability bundles (bytes)

target metric base head Δ
cli-spa-starter raw 87,807 87,331 −476 (−0.5%) 🟢
cli-spa-starter gzip 30,045 29,944 −101 (−0.3%) 🟢
cli-spa-starter brotli 26,651 26,600 −51 (−0.2%) 🟢
root-chained-jsx raw 61,939 61,463 −476 (−0.8%) 🟢
root-chained-jsx gzip 20,772 20,672 −100 (−0.5%) 🟢
root-chained-jsx brotli 18,762 18,752 −10 (−0.1%) 🟢
root-static raw 148,734 148,258 −476 (−0.3%) 🟢
root-static gzip 48,172 48,102 −70 (−0.1%) 🟢
root-static brotli 42,461 42,369 −92 (−0.2%) 🟢
root-callback-local raw 62,399 61,923 −476 (−0.8%) 🟢
root-callback-local gzip 20,889 20,808 −81 (−0.4%) 🟢
root-callback-local brotli 18,862 18,801 −61 (−0.3%) 🟢
hooks-state raw 72,301 71,825 −476 (−0.7%) 🟢
hooks-state gzip 24,072 23,942 −130 (−0.5%) 🟢
hooks-state brotli 21,682 21,587 −95 (−0.4%) 🟢
prop-attributes raw 69,765 69,289 −476 (−0.7%) 🟢
prop-attributes gzip 23,289 23,183 −106 (−0.5%) 🟢
prop-attributes brotli 21,037 21,011 −26 (−0.1%) 🟢
context raw 78,729 78,253 −476 (−0.6%) 🟢
context gzip 26,152 26,030 −122 (−0.5%) 🟢
context brotli 23,459 23,399 −60 (−0.3%) 🟢
hydrate-root raw 123,153 122,677 −476 (−0.4%) 🟢
hydrate-root gzip 40,124 40,015 −109 (−0.3%) 🟢
hydrate-root brotli 35,329 35,243 −86 (−0.2%) 🟢
deferred-hydration raw 205,437 204,961 −476 (−0.2%) 🟢
deferred-hydration gzip 65,541 65,416 −125 (−0.2%) 🟢
deferred-hydration brotli 56,758 56,631 −127 (−0.2%) 🟢
hydrate-frame raw 350,700 350,224 −476 (−0.1%) 🟢
hydrate-frame gzip 110,487 110,436 −51 (−0.0%) 🟢
hydrate-frame brotli 94,838 94,704 −134 (−0.1%) 🟢
suspense-transition raw 127,624 127,148 −476 (−0.4%) 🟢
suspense-transition gzip 40,894 40,783 −111 (−0.3%) 🟢
suspense-transition brotli 36,210 36,124 −86 (−0.2%) 🟢
component-owned-effects raw 63,229 62,753 −476 (−0.8%) 🟢
component-owned-effects gzip 21,258 21,166 −92 (−0.4%) 🟢
component-owned-effects brotli 19,198 19,148 −50 (−0.3%) 🟢
binding-hooks raw 72,884 72,408 −476 (−0.7%) 🟢
binding-hooks gzip 24,659 24,537 −122 (−0.5%) 🟢
binding-hooks brotli 22,225 22,131 −94 (−0.4%) 🟢
binding-base-ui-vite raw 187,750 187,274 −476 (−0.3%) 🟢
binding-base-ui-vite gzip 60,394 60,270 −124 (−0.2%) 🟢
binding-base-ui-vite brotli 52,820 52,731 −89 (−0.2%) 🟢
binding-base-ui-esbuild raw 214,912 214,436 −476 (−0.2%) 🟢
binding-base-ui-esbuild gzip 69,901 69,807 −94 (−0.1%) 🟢
binding-base-ui-esbuild brotli 60,729 60,664 −65 (−0.1%) 🟢
binding-radix-vite raw 188,112 187,636 −476 (−0.3%) 🟢
binding-radix-vite gzip 60,273 60,179 −94 (−0.2%) 🟢
binding-radix-vite brotli 52,751 52,657 −94 (−0.2%) 🟢
binding-radix-esbuild raw 215,058 214,582 −476 (−0.2%) 🟢
binding-radix-esbuild gzip 69,809 69,724 −85 (−0.1%) 🟢
binding-radix-esbuild brotli 60,601 60,611 +10 (+0.0%) 🔴
binding-mantine-hooks-vite raw 73,309 72,833 −476 (−0.6%) 🟢
binding-mantine-hooks-vite gzip 24,630 24,516 −114 (−0.5%) 🟢
binding-mantine-hooks-vite brotli 22,182 22,083 −99 (−0.4%) 🟢
binding-mantine-hooks-esbuild raw 84,968 84,492 −476 (−0.6%) 🟢
binding-mantine-hooks-esbuild gzip 29,038 28,935 −103 (−0.4%) 🟢
binding-mantine-hooks-esbuild brotli 25,906 25,836 −70 (−0.3%) 🟢
binding-apollo-client-vite raw 329,904 329,428 −476 (−0.1%) 🟢
binding-apollo-client-vite gzip 102,619 102,519 −100 (−0.1%) 🟢
binding-apollo-client-vite brotli 89,944 89,836 −108 (−0.1%) 🟢
binding-apollo-client-esbuild raw 365,083 364,607 −476 (−0.1%) 🟢
binding-apollo-client-esbuild gzip 116,306 116,200 −106 (−0.1%) 🟢
binding-apollo-client-esbuild brotli 101,458 101,350 −108 (−0.1%) 🟢
binding-usehooks-ts-vite raw 74,091 73,615 −476 (−0.6%) 🟢
binding-usehooks-ts-vite gzip 24,865 24,743 −122 (−0.5%) 🟢
binding-usehooks-ts-vite brotli 22,464 22,361 −103 (−0.5%) 🟢
binding-usehooks-ts-esbuild raw 85,742 85,266 −476 (−0.6%) 🟢
binding-usehooks-ts-esbuild gzip 29,268 29,162 −106 (−0.4%) 🟢
binding-usehooks-ts-esbuild brotli 26,117 26,047 −70 (−0.3%) 🟢

42 other measured values are unchanged.

@trueadm

trueadm commented Oct 10, 2026

Copy link
Copy Markdown
Collaborator

Good to go. Two non-blocking notes, nothing to fix before merge.

  1. Optional nit: the default arm can't be reached. BINDING_BAG_ARITY is module-private and only bag0–bag16 set it. Letting default cover arity 16 drops one arm and still leaves 17 distinct spread sites.
  2. Follow-up, already true before this PR: the per-arity spread sites survive only esbuild and Oxc. In a minimal probe, Terser 5.49 and SWC 1.15 already collapse them to one or two shared sites, both before and after this change. So webpack and Next.js builds share one CloneObject feedback site across every arity. This isn't a regression here; it's just a limit on the "monomorphic per arity" comment for those consumers.

Verified:

  • Each arm is the same { ...bag } expression as the removed cloneBagN helper, for arities 0–16 plus default. No cloneBag* references remain.
  • Snapshot keys are unchanged, including __journalWindow and the brand symbol, and the rollback loop is untouched.
  • Bot report:
    • −476 B raw on every rows and reachability bundle, gzip −51 to −130 B.
    • calls_update −100 confirms the path is hot and the call is gone.
    • Timings are within noise. The two intervals above zero (TSRX clear, JSX select_lots) are on paths with no bag writes, and the PR body discloses them.
  • Coverage: suspense-preserves-dom L189–L280 hits the arity-6 and arity-2 arms through held-root restores, in both octane and octane-prod.

@domgan-oai

domgan-oai commented Oct 10, 2026 •

Copy link
Copy Markdown
Contributor Author

Clarified the source comment in 14e7c9e: per-arity cloning remains monomorphic only when the downstream minifier preserves the separate spread sites. The optional arity-16/default cleanup is deferred, so the measured executable code remains unchanged. Sync and scoped formatting pass; the signed base integration is 329f5bc, with all 30 current-head checks passing.

@trueadm
trueadm merged commit 7dcbc75 into octanejs:main Oct 10, 2026
30 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