Skip to content

perf(octane): tree-shake unused controlled event restoration - #1946

Merged
trueadm merged 3 commits into
octanejs:mainfrom
openai-oss-forks:codex/bundle-size-normalization
Oct 9, 2026
Merged

trueadm merged 3 commits into
octanejs:mainfrom
openai-oss-forks:codex/bundle-size-normalization

Conversation

@domgan-oai

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

Copy link
Copy Markdown
Contributor

Summary

Applications that never mount a controlled input can now tree-shake the controlled-event enqueue and dispatch-finish paths. The first controlled binding installs the existing enqueue and dispatch-finish functions; controlled inputs retain their current behavior even when first mounted during a native event.

This isolates event restoration only. Capture fallback scheduling remains active before the first control is armed, and reads the capability when it runs. Controlled commit drains, autofocus, scheduling, and element/Block/Scope shapes are unchanged. No public API or compiler output changes.

Validation

  • pnpm format:check: not run repo-wide; node scripts/format-files.mjs --check -- on every changed file passes with the pinned formatter.
  • pnpm typecheck: not run repo-wide; node scripts/typecheck-files.mjs -- packages/octane/src/runtime.ts packages/octane/tests/form-action-bundle.test.ts passes with the pinned native TypeScript and admitted content mapper.
  • pnpm test: full suite left to CI.
  • Repository synchronization (pnpm run sync) passes and produces no generated changes.
  • Targeted correctness: 362 tests across 20 dev/production project-file executions. Includes controlled input/textarea/select/restoration, native checkable events, descriptor controls, hydration mismatch recovery, ViewTransition staging, and delegated event behavior.
  • Production bundle tests exercise event-only exclusion, first controlled activation inside a native target listener after capture with stopped propagation, nested edits across roots, and unmount/remount. Mutating capture finalization to return before the first capability installs fails both dev/prod late-activation executions; restoring the implementation passes.
  • Exact js-framework work comparison: all 40 call/DOM metrics pass for both dialects. Each canonical operation makes two fewer production calls; DOM mutation counts are unchanged.
  • Installed-control workload: 512-field production fixtures; exact 128-input windows keep 16,003 calls with capture and 13,059 without, 128 attribute writes and 128 text writes, and no node replacement in both builds. Native event counts, synchronous values/output, and input identity are asserted.
  • Final paired controlled-event timing against main 77571d9, candidate 0f667b7: 30 alternating pairs after six warmups, eight valid 512-event bursts per window, Node 24.20.0 and Chromium 149.0.7827.55. Capture paired ratio 0.978 (95% 0.954–0.994; median windows 25.0/24.5 ms), no capture 1.002 (0.976–1.028; 20.2/20.4 ms). Neither indicates a slowdown beyond the repository’s 3% threshold; no speedup claim. Exact call/DOM counts and all semantic checks above also passed against this base.
  • perf-review: scoped diff scan reports no candidates. Event call sites replace existing direct calls with guarded capability calls, with no wrapper calls, allocations per event, DOM operations, or scheduling changes. One driver object is allocated when the first controlled record is created. Work and timing evidence above cover absent and installed capabilities.
  • concise-code: runtime +23/−7; tests +103/−1 and extend the existing production-bundle harness; only new file is the patch changeset. No new exports. A boolean guard was rejected because esbuild would retain concrete function references; the two-method capability places those references at their existing owner. Broader signal-owner extraction was deferred because explicit root owners and late-imported signal authority need a separate design.

Current-head PR benchmark report, comparing base 114e3b83d with PR merge 19a35f4fc for published head 14a1d4ef3, on the same CI runner. Framework bytes:

Fixture Raw Gzip Brotli
Rows (TSRX) 107,027 → 104,688 (−2,339 (−2.2%)) 34,945 → 34,277 (−668 (−1.9%)) 30,998 → 30,480 (−518 (−1.7%))
Rows (JSX) 180,557 → 180,670 (+113 (+0.1%)) 57,195 → 57,230 (+35 (+0.1%)) 49,836 → 49,956 (+120 (+0.2%))
TodoMVC 119,059 → 119,171 (+112 (+0.1%)) 38,330 → 38,380 (+50 (+0.1%)) 33,812 → 33,836 (+24 (+0.1%))
Chat stream 116,662 → 116,773 (+111 (+0.1%)) 37,669 → 37,730 (+61 (+0.2%)) 33,276 → 33,301 (+25 (+0.1%))
Weather 136,987 → 134,153 (−2,834 (−2.1%)) 43,880 → 43,109 (−771 (−1.8%)) 38,576 → 37,854 (−722 (−1.9%))
Bindings 345,456 → 345,569 (+113 (+0.0%)) 110,921 → 110,955 (+34 (+0.0%)) 96,386 → 96,395 (+9 (+0.0%))
Full API ceiling 573,504 → 573,617 (+113 (+0.0%)) 173,198 → 173,216 (+18 (+0.0%)) 145,626 → 145,661 (+35 (+0.0%))

Complete-app gzip saves 668 bytes in rows and 771 in weather. TodoMVC grows 49 bytes, chat 61, JSX rows 33, and bindings 35. These are incremental savings, not a 40% reduction. All 20 function-call counters fall by two, with the remaining 44 work counters unchanged. Of 20 timing comparisons, 19 have no verdict and JSX swap is reported faster; none is reported slower.

A separate byte-only composition check over #1942 at d0fa09f1e94b4f67c8999c67e27a940a096845f5 still saves 617 bytes framework gzip in rows and 705 in weather. This confirms the savings are incremental to its optional-driver folding changes; it is not correctness qualification of that other PR.

Risk / follow-ups

  • Control-capable fixtures retain the driver and grow by 33–61 bytes total gzip; the full-API ceiling grows 18 bytes gzip. This is the cost of the optional boundary.
  • Local validation uses Node 24.20.0 and cached build dependencies matching the source baseline. Synchronization, scoped typechecking, and scoped formatting were rerun successfully with the repository-selected pnpm 12.9.1, formatter 0.6.3, and content mapper 0.1.2 after registry admission.
  • Full test/typecheck/lint and benchmark CI runs on the published head; see the PR checks for current status.

Provenance

  • An agent produced this diff (agent-authored)

Origin: 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
Touches core delegated event dispatch and React-style controlled value restoration; incorrect tree-shaking or guard logic could break inputs or leave stale DOM values, though the PR adds targeted bundle and behavioral tests.

Overview
Controlled-input event restoration (maybeEnqueueRestore / maybeFlushDiscrete) is no longer wired unconditionally into delegated event dispatch. A lazy CONTROLLED_RESTORE_DRIVER is installed the first time a control is armed in armControlledBase; dispatch paths only enqueue/finish restores when that driver exists, so production bundles that never use controlled bindings can drop the restore graph.

Behavior is unchanged once any controlled binding exists: the same functions are registered on the driver, including when a control is first made controlled inside a native listener after capture stops bubbling. Production bundle tests now assert restore helpers are absent from click-only apps, present when value bindings are used, and still correct for nested roots and unmount/remount.

Reviewed by Cursor Bugbot for commit 14a1d4e. 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 9, 2026
@trueadm
trueadm marked this pull request as ready for review October 9, 2026 17:41
@github-actions

github-actions Bot commented Oct 9, 2026

Copy link
Copy Markdown
Contributor

Benchmark report

  • 🔴 bundle-size: 34 value(s) increased
  • 🔴 bundle-reachability: 23 value(s) increased

Compares 114e3b83d, the merge commit's first parent with 19a35f4fc 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 swap 0.460 0.325 −16.3% −37.6% … −11.3% 🟢 faster
All 20 timed operations (19 without a verdict)
target operation base ms head ms head/base 95% CI
octane-tsrx run 5.875 5.592 +3.7% −4.8% … +10.7% ⚪ within noise
octane-tsrx replace 10.492 11.083 +2.2% −12.4% … +10.6% ⚪ within noise
octane-tsrx add 6.067 5.908 +4.5% ±0.0% … +42.5% ⚪ within noise
octane-tsrx update 0.271 0.273 +1.0% −10.2% … +44.5% ⚪ within noise
octane-tsrx select 0.014 0.017 +2.9% −1.6% … +10.9% ⚪ within noise
octane-tsrx swap 0.037 0.050 +4.6% −0.7% … +49.5% ⚪ within noise
octane-tsrx remove 0.028 0.027 +1.0% −7.6% … +4.5% ⚪ within noise
octane-tsrx runlots 63.742 49.267 −8.4% −42.0% … +5.8% ⚪ within noise
octane-tsrx select_lots 0.014 0.012 −3.3% −61.8% … +44.6% ⚪ within noise
octane-tsrx clear 63.558 67.975 +10.5% −0.8% … +56.8% ⚪ within noise
octane-jsx run 6.308 7.858 +5.2% −9.1% … +36.3% ⚪ within noise
octane-jsx replace 11.667 13.025 +6.2% −7.0% … +20.0% ⚪ within noise
octane-jsx add 7.425 6.983 +1.9% −6.0% … +52.2% ⚪ within noise
octane-jsx update 0.519 0.468 −6.3% −9.6% … +4.9% ⚪ within noise
octane-jsx select 0.246 0.271 +3.5% −0.8% … +11.8% ⚪ within noise
octane-jsx swap 0.460 0.325 −16.3% −37.6% … −11.3% 🟢 faster
octane-jsx remove 0.378 0.362 −2.7% −11.4% … +37.6% ⚪ within noise
octane-jsx runlots 78.692 85.608 +0.8% −10.1% … +18.2% ⚪ within noise
octane-jsx select_lots 5.619 6.171 −5.2% −22.9% … +17.1% ⚪ within noise
octane-jsx clear 86.400 72.775 −8.2% −15.1% … +6.4% ⚪ within noise

Work counters (an increase fails this check):

target metric base head Δ
octane-tsrx calls_run 25,087 25,085 −2 (−0.0%) 🟢
octane-tsrx calls_replace 32,100 32,098 −2 (−0.0%) 🟢
octane-tsrx calls_add 33,086 33,084 −2 (−0.0%) 🟢
octane-tsrx calls_update 3,583 3,581 −2 (−0.1%) 🟢
octane-tsrx calls_select 86 84 −2 (−2.3%) 🟢
octane-tsrx calls_swap 2,097 2,095 −2 (−0.1%) 🟢
octane-tsrx calls_remove 3,102 3,100 −2 (−0.1%) 🟢
octane-tsrx calls_runlots 250,084 250,082 −2 (−0.0%) 🟢
octane-tsrx calls_select_lots 86 84 −2 (−2.3%) 🟢
octane-tsrx calls_clear 97 95 −2 (−2.1%) 🟢
octane-jsx calls_run 35,163 35,161 −2 (−0.0%) 🟢
octane-jsx calls_replace 42,178 42,176 −2 (−0.0%) 🟢
octane-jsx calls_add 50,164 50,162 −2 (−0.0%) 🟢
octane-jsx calls_update 9,761 9,759 −2 (−0.0%) 🟢
octane-jsx calls_select 9,166 9,164 −2 (−0.0%) 🟢
octane-jsx calls_swap 9,173 9,171 −2 (−0.0%) 🟢
octane-jsx calls_remove 9,178 9,176 −2 (−0.0%) 🟢
octane-jsx calls_runlots 350,160 350,158 −2 (−0.0%) 🟢
octane-jsx calls_select_lots 90,166 90,164 −2 (−0.0%) 🟢
octane-jsx calls_clear 175 173 −2 (−1.1%) 🟢

44 other measured values are unchanged.

Application bundle size (bytes)

target metric base head Δ
octane-tsrx js_raw 113,975 111,636 −2,339 (−2.1%) 🟢
octane-tsrx js_gzip 37,281 36,613 −668 (−1.8%) 🟢
octane-tsrx js_brotli 33,033 32,518 −515 (−1.6%) 🟢
octane-tsrx app_brotli 2,035 2,038 +3 (+0.1%) 🔴
octane-tsrx fw_raw 107,027 104,688 −2,339 (−2.2%) 🟢
octane-tsrx fw_gzip 34,945 34,277 −668 (−1.9%) 🟢
octane-tsrx fw_brotli 30,998 30,480 −518 (−1.7%) 🟢
octane-tsrx todo_js_raw 123,685 123,797 +112 (+0.1%) 🔴
octane-tsrx todo_js_gzip 40,553 40,602 +49 (+0.1%) 🔴
octane-tsrx todo_js_brotli 35,699 35,726 +27 (+0.1%) 🔴
octane-tsrx todo_app_gzip 2,223 2,222 −1 (−0.0%) 🟢
octane-tsrx todo_app_brotli 1,887 1,890 +3 (+0.2%) 🔴
octane-tsrx todo_fw_raw 119,059 119,171 +112 (+0.1%) 🔴
octane-tsrx todo_fw_gzip 38,330 38,380 +50 (+0.1%) 🔴
octane-tsrx todo_fw_brotli 33,812 33,836 +24 (+0.1%) 🔴
octane-tsrx chat_js_raw 122,433 122,544 +111 (+0.1%) 🔴
octane-tsrx chat_js_gzip 40,385 40,446 +61 (+0.2%) 🔴
octane-tsrx chat_js_brotli 35,662 35,687 +25 (+0.1%) 🔴
octane-tsrx chat_fw_raw 116,662 116,773 +111 (+0.1%) 🔴
octane-tsrx chat_fw_gzip 37,669 37,730 +61 (+0.2%) 🔴
octane-tsrx chat_fw_brotli 33,276 33,301 +25 (+0.1%) 🔴
octane-tsrx weather_js_raw 159,148 156,314 −2,834 (−1.8%) 🟢
octane-tsrx weather_js_gzip 51,724 50,953 −771 (−1.5%) 🟢
octane-tsrx weather_js_brotli 45,241 44,525 −716 (−1.6%) 🟢
octane-tsrx weather_app_brotli 6,665 6,671 +6 (+0.1%) 🔴
octane-tsrx weather_fw_raw 136,987 134,153 −2,834 (−2.1%) 🟢
octane-tsrx weather_fw_gzip 43,880 43,109 −771 (−1.8%) 🟢
octane-tsrx weather_fw_brotli 38,576 37,854 −722 (−1.9%) 🟢
octane-tsrx bindings_js_raw 693,109 693,222 +113 (+0.0%) 🔴
octane-tsrx bindings_js_gzip 226,603 226,638 +35 (+0.0%) 🔴
octane-tsrx bindings_js_brotli 192,651 192,552 −99 (−0.1%) 🟢
octane-tsrx bindings_app_gzip 115,682 115,683 +1 (+0.0%) 🔴
octane-tsrx bindings_app_brotli 96,265 96,157 −108 (−0.1%) 🟢
octane-tsrx bindings_fw_raw 345,456 345,569 +113 (+0.0%) 🔴
octane-tsrx bindings_fw_gzip 110,921 110,955 +34 (+0.0%) 🔴
octane-tsrx bindings_fw_brotli 96,386 96,395 +9 (+0.0%) 🔴
octane-tsrx full_fw_raw 573,504 573,617 +113 (+0.0%) 🔴
octane-tsrx full_fw_gzip 173,198 173,216 +18 (+0.0%) 🔴
octane-tsrx full_fw_brotli 145,626 145,661 +35 (+0.0%) 🔴
octane-jsx js_raw 188,830 188,943 +113 (+0.1%) 🔴
octane-jsx js_gzip 60,055 60,088 +33 (+0.1%) 🔴
octane-jsx js_brotli 52,247 52,368 +121 (+0.2%) 🔴
octane-jsx app_gzip 2,860 2,858 −2 (−0.1%) 🟢
octane-jsx app_brotli 2,411 2,412 +1 (+0.0%) 🔴
octane-jsx fw_raw 180,557 180,670 +113 (+0.1%) 🔴
octane-jsx fw_gzip 57,195 57,230 +35 (+0.1%) 🔴
octane-jsx fw_brotli 49,836 49,956 +120 (+0.2%) 🔴
octane-jsx full_fw_raw 573,504 573,617 +113 (+0.0%) 🔴
octane-jsx full_fw_gzip 173,198 173,216 +18 (+0.0%) 🔴
octane-jsx full_fw_brotli 145,626 145,661 +35 (+0.0%) 🔴

10 other measured values are unchanged.

Public-import reachability bundles (bytes)

target metric base head Δ
cli-spa-starter raw 103,025 100,204 −2,821 (−2.7%) 🟢
cli-spa-starter gzip 34,438 33,599 −839 (−2.4%) 🟢
cli-spa-starter brotli 30,298 29,565 −733 (−2.4%) 🟢
root-static-specialized raw 73,089 70,275 −2,814 (−3.9%) 🟢
root-static-specialized gzip 24,085 23,269 −816 (−3.4%) 🟢
root-static-specialized brotli 21,532 20,875 −657 (−3.1%) 🟢
root-chained-jsx raw 76,110 73,296 −2,814 (−3.7%) 🟢
root-chained-jsx gzip 24,893 24,106 −787 (−3.2%) 🟢
root-chained-jsx brotli 22,261 21,629 −632 (−2.8%) 🟢
root-static raw 166,575 166,688 +113 (+0.1%) 🔴
root-static gzip 52,763 52,810 +47 (+0.1%) 🔴
root-static brotli 45,935 45,989 +54 (+0.1%) 🔴
root-static-local raw 73,088 70,274 −2,814 (−3.9%) 🟢
root-static-local gzip 24,071 23,254 −817 (−3.4%) 🟢
root-static-local brotli 21,538 20,879 −659 (−3.1%) 🟢
root-callback-local raw 76,136 73,798 −2,338 (−3.1%) 🟢
root-callback-local gzip 24,901 24,253 −648 (−2.6%) 🟢
root-callback-local brotli 22,285 21,708 −577 (−2.6%) 🟢
hooks-state raw 85,954 83,133 −2,821 (−3.3%) 🟢
hooks-state gzip 28,313 27,519 −794 (−2.8%) 🟢
hooks-state brotli 25,284 24,618 −666 (−2.6%) 🟢
prop-attributes raw 86,210 83,389 −2,821 (−3.3%) 🟢
prop-attributes gzip 28,387 27,580 −807 (−2.8%) 🟢
prop-attributes brotli 25,363 24,644 −719 (−2.8%) 🟢
context raw 97,296 94,475 −2,821 (−2.9%) 🟢
context gzip 31,778 30,997 −781 (−2.5%) 🟢
context brotli 28,254 27,579 −675 (−2.4%) 🟢
hydrate-root raw 138,763 135,937 −2,826 (−2.0%) 🟢
hydrate-root gzip 44,500 43,705 −795 (−1.8%) 🟢
hydrate-root brotli 38,989 38,314 −675 (−1.7%) 🟢
deferred-hydration raw 222,120 219,781 −2,339 (−1.1%) 🟢
deferred-hydration gzip 70,094 69,462 −632 (−0.9%) 🟢
deferred-hydration brotli 60,445 59,933 −512 (−0.8%) 🟢
hydrate-frame raw 368,548 368,661 +113 (+0.0%) 🔴
hydrate-frame gzip 114,587 114,588 +1 (+0.0%) 🔴
hydrate-frame brotli 97,982 97,968 −14 (−0.0%) 🟢
suspense-transition raw 143,942 141,498 −2,444 (−1.7%) 🟢
suspense-transition gzip 45,649 44,985 −664 (−1.5%) 🟢
suspense-transition brotli 40,054 39,496 −558 (−1.4%) 🟢
component-owned-effects raw 77,449 74,633 −2,816 (−3.6%) 🟢
component-owned-effects gzip 25,394 24,605 −789 (−3.1%) 🟢
component-owned-effects brotli 22,748 22,095 −653 (−2.9%) 🟢
binding-hooks raw 84,456 81,640 −2,816 (−3.3%) 🟢
binding-hooks gzip 27,976 27,211 −765 (−2.7%) 🟢
binding-hooks brotli 25,014 24,317 −697 (−2.8%) 🟢
binding-base-ui-vite raw 202,432 202,547 +115 (+0.1%) 🔴
binding-base-ui-vite gzip 63,842 63,878 +36 (+0.1%) 🔴
binding-base-ui-vite brotli 55,482 55,551 +69 (+0.1%) 🔴
binding-base-ui-esbuild raw 217,973 218,086 +113 (+0.1%) 🔴
binding-base-ui-esbuild gzip 70,833 70,851 +18 (+0.0%) 🔴
binding-base-ui-esbuild brotli 61,452 61,484 +32 (+0.1%) 🔴
binding-radix-vite raw 204,504 204,619 +115 (+0.1%) 🔴
binding-radix-vite gzip 64,452 64,483 +31 (+0.0%) 🔴
binding-radix-vite brotli 56,064 56,168 +104 (+0.2%) 🔴
binding-radix-esbuild raw 219,834 219,947 +113 (+0.1%) 🔴
binding-radix-esbuild gzip 71,410 71,434 +24 (+0.0%) 🔴
binding-radix-esbuild brotli 62,019 62,050 +31 (+0.0%) 🔴
binding-mantine-hooks-vite raw 88,051 85,231 −2,820 (−3.2%) 🟢
binding-mantine-hooks-vite gzip 28,967 28,170 −797 (−2.8%) 🟢
binding-mantine-hooks-vite brotli 25,863 25,215 −648 (−2.5%) 🟢
binding-mantine-hooks-esbuild raw 92,434 89,811 −2,623 (−2.8%) 🟢
binding-mantine-hooks-esbuild gzip 31,174 30,435 −739 (−2.4%) 🟢
binding-mantine-hooks-esbuild brotli 27,813 27,154 −659 (−2.4%) 🟢
binding-apollo-client-vite raw 344,925 345,038 +113 (+0.0%) 🔴
binding-apollo-client-vite gzip 106,143 106,175 +32 (+0.0%) 🔴
binding-apollo-client-vite brotli 92,729 92,733 +4 (+0.0%) 🔴
binding-apollo-client-esbuild raw 368,150 368,263 +113 (+0.0%) 🔴
binding-apollo-client-esbuild gzip 117,173 117,204 +31 (+0.0%) 🔴
binding-apollo-client-esbuild brotli 102,156 102,319 +163 (+0.2%) 🔴
binding-usehooks-ts-vite raw 88,821 86,000 −2,821 (−3.2%) 🟢
binding-usehooks-ts-vite gzip 29,190 28,392 −798 (−2.7%) 🟢
binding-usehooks-ts-vite brotli 26,087 25,361 −726 (−2.8%) 🟢
binding-usehooks-ts-esbuild raw 93,208 90,585 −2,623 (−2.8%) 🟢
binding-usehooks-ts-esbuild gzip 31,408 30,658 −750 (−2.4%) 🟢
binding-usehooks-ts-esbuild brotli 28,020 27,402 −618 (−2.2%) 🟢

36 other measured values are unchanged.

@trueadm
trueadm merged commit 9728968 into octanejs:main Oct 9, 2026
31 checks passed
@github-actions github-actions Bot mentioned this pull request Oct 9, 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