Skip to content

perf(octane): mark a root slot's snapshot instead of keeping a structures Map - #1897

Merged
trueadm merged 2 commits into
mainfrom
fix/root-journal-slot-snapshot
Oct 8, 2026
Merged

trueadm merged 2 commits into
mainfrom
fix/root-journal-slot-snapshot

Conversation

@trueadm

@trueadm trueadm commented Oct 8, 2026 •

Copy link
Copy Markdown
Collaborator

Summary

Before a root render restructures a slot (@if, @switch, a component slot, a child hole), journalRootSlot snapshots the slot and its DOM range, so a suspension can roll the change back. It used to dedupe that capture through a separate per-transaction structures Map, and it logged an undo closure to clear the Map entry on replay. The slot snapshot it also takes already lives in seen (TRANSITION_JOURNAL_BAGS), whose entry the bag replay clears.

This PR records the snapshot's log index plus one in seen, so an odd index means the range was captured with it. A plain snapshot from journalObjectOnce (a revealed boundary, for example) holds no range. When one exists, the slot is snapshotted again with its range, and replay restores the older snapshot last. Capture semantics are unchanged; the closure, its log entry and the Map's per-transaction growth go away.

Why

Part of the portal-swarm work on top of #1892's profile. journalRootSlot was about 5.3% of a portal-swarm open/close cycle, nearly all self time, with GC at about 8%. Each tooltip open and close of a committed item's @if paid for two structures Map operations, an undo closure with its context, and an extra log entry.

Changes

  • packages/octane/src/runtime.ts, journalRootSlot only: dedupe through the snapshot entry in seen (odd index = range taken) instead of transaction.structures plus a structures.delete closure. journalRootChildren still uses structures for de-opt parents.
  • packages/octane/tests/suspense-preserves-dom.test.ts: in one root attempt, a pending boundary is revealed, rendered again via a render-phase update so it suspends again, and then a later sibling suspends the root. The test asserts the committed DOM (hidden primary plus fallback) comes back byte-identical with node identity kept, and that the next update reveals that same primary. Dev and prod compiles. It reaches the plain-snapshot-then-structure interleaving (confirmed with an instrumented runtime).
  • Changeset (octane patch).

Performance

Chromium headless, production builds of benchmarks/portal-swarm/octane-tsrx, served with COOP/COEP. Base is main 2f81266018; candidate is this head.

Measure Base Candidate Δ
Allocation per open+close cycle (sampling heap profiler, 2 runs each) 3,111 KB 2,906 KB −6.6%
open_close_cycle, paired median ratio [95% bootstrap CI], run 1 0.976 [0.970, 0.998] A/A 0.999 [0.992, 1.008]
open_close_cycle, run 2 0.988 [0.976, 1.002] A/A 1.000 [0.988, 1.015]
open_all, run 1 0.989 [0.980, 1.000] A/A 1.002 [0.989, 1.016]
open_all, run 2 0.992 [0.981, 1.002] A/A 0.998 [0.990, 1.010]

Method: 60 rounds × min-of-3 samples per target. Pages are recreated every 6 rounds in rotated order, because one long-lived page per target showed up to a 3% A/A bias. The A/A control is a second, byte-identical build of base. Net effect: about −1–2% on open_close_cycle and under 1% on open_all (that interval includes A/A). The allocation drop is deterministic.

Journal entries per 200-item section A toggle drop by 200 closures and 200 log entries each way (an open was BAG 200, UNDO×3 ×200, …).

Bytes

Local run-minimal.mjs --budgets and run.mjs --budgets octane-tsrx octane-jsx both pass against this head's committed budgets.

Scenarios raw gzip
root-static, context, deferred-hydration, hydrate-frame, suspense-transition, binding-{base-ui,radix,apollo-client}-{vite,esbuild} −16 to −22 −20 to +17
every other minimal scenario 0 0
app framework rows (todomvc / chat / weather / bindings) (not reported) +5 to +10

Budget-ratchet note: main currently carries #1891, a budget-only raise made ahead of #1875. Its 70 raised ceilings sit above measured + 32 until #1875 lands, so the tight-ratchet step can flag scenarios regardless of this diff. I did not lower those ceilings. After #1875 merges, this PR's own raw savings may need --write-budgets for the scenarios above.

Validation

  • pnpm format:check: not run repo-wide; pnpm format:files on the 3 changed files (no changes).
  • pnpm typecheck: not run repo-wide. pnpm typecheck:files on the 2 changed files reports the same 311 pre-existing TS17004/TS7006 errors in untouched .tsrx fixtures as main does; none are in the changed files.
  • pnpm test: left to CI.
  • Targeted tests, --project octane: 18 rollback/transition/suspense/portal files (suspense-preserves-dom, transitions, transition-*, portal, try-catch, root-snapshot-values, fresh-root-scope-hold, parked-two-windows, keyed-rollback-links, empty-refill-rollback, style-transaction-rollback, behavior-root, transition-held-audit): 642/642 pass. A wider pass over 51 suspense/try/transition/hydration/activity files ran on the pre-rebase candidate: 965/965.
  • The new test fails when the change is broken:
    • dropping journalRootSlot's range capture: the new test fails (dev + prod), plus 4 existing tests;
    • overwriting the earlier plain snapshot instead of adding a newer one (the replay-order invariant): the new test fails (dev + prod);
    • it passes on main.
  • pnpm sync clean.
  • perf-review: node scripts/perf-review-scan.mjs → 0 candidates. Hot path: journalRootSlot, once per restructured slot per root-render window (per toggle). The diff only removes allocation: one closure, its context, one log entry and a Map set/get per call. Entry shape is the same JOURNAL_BAG 4-tuple as journalObjectOnce, the slot clone is unchanged, and seen values stay Smis. No new references (reachability), DOM, or scheduling. No must-fix or needs-evidence findings.

Risk / follow-ups

  • Unproven guard: I could not build a flow where the odd-index check is load-bearing. Removing it (skipping the range whenever any snapshot exists in the window) passes every test I ran, because in the reachable plain-then-structure flows (a revealed or held TrySlot), other entries already restore that DOM. The check keeps capture semantics identical to main.
  • Evaluated and not included:
    • Typed range entries instead of the journalRootRange closure: no measurable gain. Naming restoreRootRange from the replay switch made it reachable in bundles without the root journal (+190 raw in some).
    • Skipping deferRootRange's cancel closure in the root window: an aborted transaction never runs its commit list. This saves about 22 KB per cycle but costs +6 raw / +9 gzip in every bundle, which the current budgets cannot absorb.
    • Skipping journalRootProperty(parentScope.slots…) in portal() for discard-stamped scopes: saves one 4-slot push per compiled portal mount, which is unmeasurable, and adds bytes to compiled-portal apps.
  • Found, owned elsewhere:
    • unregisterPortalEventRange allocates about 137 KB per cycle (delete on comment-node expandos). That is the portal teardown path.
    • Section B's descriptor portals journal attributes (journalAttr, a DOM read each) on freshly created de-opt elements, about 0.7%.

Provenance

  • An agent produced this diff (agent-authored)

🤖 Generated with Claude Code


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
Allocation-only change on the root-render rollback journal path with unchanged capture semantics and targeted regression coverage; no auth, data, or API surface changes.

Overview
journalRootSlot no longer dedupes structural slot captures via a per-transaction structures Map and a journalUndo closure. It reuses TRANSITION_JOURNAL_BAGS (seen): the stored index is the snapshot’s log position plus one when the DOM range was journaled with it (odd = already captured with range). A plain snapshot without a range can still get a follow-up bag + range; replay order keeps rollback behavior the same while dropping Map work, an undo log entry, and a closure per capture.

Adds RevealAgainApp and a test where one root attempt reveals a @try boundary, re-enters via a render-phase update so it suspends again, then a sibling gate suspends the root—the rolled-back attempt must restore byte-identical committed DOM and reuse the same primary node on the next update.

octane patch changeset; portal-swarm sees ~6.6% less allocation per open/close and modest open_close_cycle speedup; root-journal bundles shrink slightly in raw bytes.

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

…ures Map

journalRootSlot kept a per-transaction `structures` Map to capture each
restructured slot once per window, and logged an undo closure to clear that
entry on replay. The slot snapshot it also takes already lives in `seen`,
whose entry the bag replay clears. Record the snapshot's log index plus one
there instead: an odd index means the range was taken with it. A plain
snapshot from journalObjectOnce holds no range, so the slot is snapshotted
again with one, and replay restores the older snapshot last.

Per portal-swarm open/close cycle this removes 1,200 closures, their log
entries and two Map growths: 3,111 KB -> 2,906 KB allocated (-6.6%), and
open_close_cycle runs 1-2% faster in paired, A/A-controlled runs.

Adds a rollback test where one root attempt reveals a pending boundary,
renders it again so it suspends, and then suspends at a later sibling.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@github-actions github-actions Bot added agent-authored Diff or issue body substantially produced by an AI agent perf PR: performance work labels Oct 8, 2026
@trueadm
trueadm marked this pull request as ready for review October 8, 2026 13:51
@github-actions

github-actions Bot commented Oct 8, 2026 •

Copy link
Copy Markdown
Contributor

Benchmark report

  • ❌ bundle-size: 8 value(s) exceed their committed budget
  • ❌ bundle-reachability: 21 value(s) exceed their committed budget
  • 🔴 bundle-size: 19 value(s) increased within budget
  • 🔴 bundle-reachability: 6 value(s) increased within budget

Compares 90a57d820, the merge commit's first parent with f1b82018c on the same runner. A byte value over its committed budget or any increase in a js-framework work counter fails this check. 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 3.092 2.917 −3.2% −7.7% … +1.5% ⚪ within noise
octane-tsrx replace 7.383 8.117 +4.8% −3.8% … +9.8% ⚪ within noise
octane-tsrx add 2.900 2.942 ±0.0% −6.4% … +1.8% ⚪ within noise
octane-tsrx update 0.142 0.143 +0.2% −3.8% … +4.6% ⚪ within noise
octane-tsrx select 0.006 0.006 +1.0% −0.7% … +3.3% ⚪ within noise
octane-tsrx swap 0.035 0.036 +1.2% −1.9% … +3.3% ⚪ within noise
octane-tsrx remove 0.017 0.017 −0.4% −2.6% … +5.3% ⚪ within noise
octane-tsrx runlots 28.175 28.958 −0.0% −3.8% … +1.8% ⚪ within noise
octane-tsrx select_lots 0.006 0.006 +1.6% −0.8% … +3.0% ⚪ within noise
octane-tsrx clear 41.933 42.975 +2.5% −1.4% … +4.4% ⚪ within noise
octane-jsx run 4.133 4.300 +6.3% ±0.0% … +10.8% ⚪ within noise
octane-jsx replace 10.308 9.700 −0.2% −14.4% … +13.5% ⚪ within noise
octane-jsx add 3.458 3.400 ±0.0% −3.2% … +3.2% ⚪ within noise
octane-jsx update 0.289 0.278 −2.0% −5.7% … +2.6% ⚪ within noise
octane-jsx select 0.138 0.141 −0.6% −1.7% … +1.9% ⚪ within noise
octane-jsx swap 0.229 0.232 +1.5% +0.6% … +2.3% ⚪ within noise
octane-jsx remove 0.179 0.178 −1.7% −3.0% … +1.2% ⚪ within noise
octane-jsx runlots 31.425 31.717 +0.7% −3.0% … +3.6% ⚪ within noise
octane-jsx select_lots 1.679 1.803 +5.8% +0.6% … +10.9% ⚪ within noise
octane-jsx clear 60.675 59.667 −3.0% −9.2% … +3.1% ⚪ within noise

All 64 work counters are unchanged.

Application bundle size (bytes)

❌ 8 value(s) exceed their committed budget. Reduce the growth, or raise the budget in a separate pull request that names the bytes and the reason (CONTRIBUTING.md, "Size budgets").

target metric head budget over
octane-tsrx chat_fw_gzip 36,805 36,791 +14
octane-tsrx chat_js_gzip 39,520 39,506 +14
octane-tsrx bindings_fw_raw 341,173 339,858 +1,315
octane-tsrx bindings_fw_gzip 109,343 109,005 +338
octane-tsrx bindings_fw_brotli 94,902 94,788 +114
octane-tsrx bindings_js_raw 688,811 687,496 +1,315
octane-tsrx bindings_js_gzip 225,010 224,671 +339
octane-tsrx bindings_js_brotli 191,177 191,021 +156
target metric base head Δ
octane-tsrx todo_js_raw 121,538 121,516 −22 (−0.0%) 🟢
octane-tsrx todo_js_gzip 39,674 39,678 +4 (+0.0%) 🔴
octane-tsrx todo_js_brotli 34,923 34,893 −30 (−0.1%) 🟢
octane-tsrx todo_app_gzip 2,221 2,219 −2 (−0.1%) 🟢
octane-tsrx todo_app_brotli 1,886 1,881 −5 (−0.3%) 🟢
octane-tsrx todo_fw_raw 116,920 116,898 −22 (−0.0%) 🟢
octane-tsrx todo_fw_gzip 37,453 37,459 +6 (+0.0%) 🔴
octane-tsrx todo_fw_brotli 33,037 33,012 −25 (−0.1%) 🟢
octane-tsrx chat_js_raw 120,287 120,265 −22 (−0.0%) 🟢
octane-tsrx chat_js_gzip 39,512 39,520 +8 (+0.0%) 🔴
octane-tsrx chat_js_brotli 34,858 34,855 −3 (−0.0%) 🟢
octane-tsrx chat_app_gzip 2,714 2,715 +1 (+0.0%) 🔴
octane-tsrx chat_app_brotli 2,386 2,389 +3 (+0.1%) 🔴
octane-tsrx chat_fw_raw 114,522 114,500 −22 (−0.0%) 🟢
octane-tsrx chat_fw_gzip 36,798 36,805 +7 (+0.0%) 🔴
octane-tsrx chat_fw_brotli 32,472 32,466 −6 (−0.0%) 🟢
octane-tsrx weather_js_raw 156,842 156,820 −22 (−0.0%) 🟢
octane-tsrx weather_js_gzip 50,886 50,896 +10 (+0.0%) 🔴
octane-tsrx weather_js_brotli 44,407 44,414 +7 (+0.0%) 🔴
octane-tsrx weather_app_gzip 7,871 7,872 +1 (+0.0%) 🔴
octane-tsrx weather_app_brotli 6,663 6,657 −6 (−0.1%) 🟢
octane-tsrx weather_fw_raw 134,688 134,666 −22 (−0.0%) 🟢
octane-tsrx weather_fw_gzip 43,015 43,024 +9 (+0.0%) 🔴
octane-tsrx weather_fw_brotli 37,744 37,757 +13 (+0.0%) 🔴
octane-tsrx bindings_js_raw 688,832 688,811 −21 (−0.0%) 🟢
octane-tsrx bindings_js_gzip 225,006 225,010 +4 (+0.0%) 🔴
octane-tsrx bindings_js_brotli 191,175 191,177 +2 (+0.0%) 🔴
octane-tsrx bindings_app_brotli 96,214 96,275 +61 (+0.1%) 🔴
octane-tsrx bindings_fw_raw 341,194 341,173 −21 (−0.0%) 🟢
octane-tsrx bindings_fw_gzip 109,339 109,343 +4 (+0.0%) 🔴
octane-tsrx bindings_fw_brotli 94,961 94,902 −59 (−0.1%) 🟢
octane-tsrx full_fw_raw 568,620 568,600 −20 (−0.0%) 🟢
octane-tsrx full_fw_gzip 171,214 171,218 +4 (+0.0%) 🔴
octane-tsrx full_fw_brotli 143,953 144,040 +87 (+0.1%) 🔴
octane-jsx js_raw 187,729 187,707 −22 (−0.0%) 🟢
octane-jsx js_gzip 59,529 59,537 +8 (+0.0%) 🔴
octane-jsx js_brotli 51,727 51,732 +5 (+0.0%) 🔴
octane-jsx app_gzip 2,856 2,859 +3 (+0.1%) 🔴
octane-jsx app_brotli 2,408 2,403 −5 (−0.2%) 🟢
octane-jsx fw_raw 179,464 179,442 −22 (−0.0%) 🟢
octane-jsx fw_gzip 56,673 56,678 +5 (+0.0%) 🔴
octane-jsx fw_brotli 49,319 49,329 +10 (+0.0%) 🔴
octane-jsx full_fw_raw 568,620 568,600 −20 (−0.0%) 🟢
octane-jsx full_fw_gzip 171,214 171,218 +4 (+0.0%) 🔴
octane-jsx full_fw_brotli 143,953 144,040 +87 (+0.1%) 🔴

15 other measured values are unchanged.

Public-import reachability bundles (bytes)

❌ 21 value(s) exceed their committed budget. Reduce the growth, or raise the budget in a separate pull request that names the bytes and the reason (CONTRIBUTING.md, "Size budgets").

target metric head budget over
suspense-transition raw 141,528 140,222 +1,306
suspense-transition gzip 44,725 44,401 +324
suspense-transition brotli 39,224 39,132 +92
binding-base-ui-vite raw 199,726 198,414 +1,312
binding-base-ui-vite gzip 62,776 62,427 +349
binding-base-ui-vite brotli 54,490 54,383 +107
binding-base-ui-esbuild raw 215,252 213,931 +1,321
binding-base-ui-esbuild gzip 69,719 69,370 +349
binding-base-ui-esbuild brotli 60,550 60,247 +303
binding-radix-vite raw 201,757 200,448 +1,309
binding-radix-vite gzip 63,347 63,043 +304
binding-radix-vite brotli 55,021 54,923 +98
binding-radix-esbuild raw 217,076 215,755 +1,321
binding-radix-esbuild gzip 70,274 69,893 +381
binding-radix-esbuild brotli 61,018 60,813 +205
binding-apollo-client-vite raw 342,177 340,859 +1,318
binding-apollo-client-vite gzip 105,060 104,741 +319
binding-apollo-client-vite brotli 91,624 91,544 +80
binding-apollo-client-esbuild raw 365,395 364,070 +1,325
binding-apollo-client-esbuild gzip 116,051 115,728 +323
binding-apollo-client-esbuild brotli 101,189 101,084 +105
target metric base head Δ
root-static raw 165,545 165,523 −22 (−0.0%) 🟢
root-static gzip 52,270 52,283 +13 (+0.0%) 🔴
root-static brotli 45,520 45,523 +3 (+0.0%) 🔴
context raw 96,621 96,599 −22 (−0.0%) 🟢
context gzip 31,475 31,473 −2 (−0.0%) 🟢
context brotli 27,955 27,871 −84 (−0.3%) 🟢
deferred-hydration raw 221,365 221,343 −22 (−0.0%) 🟢
deferred-hydration gzip 69,679 69,685 +6 (+0.0%) 🔴
deferred-hydration brotli 60,118 60,151 +33 (+0.1%) 🔴
hydrate-frame raw 364,520 364,499 −21 (−0.0%) 🟢
hydrate-frame gzip 112,947 112,957 +10 (+0.0%) 🔴
hydrate-frame brotli 96,534 96,552 +18 (+0.0%) 🔴
suspense-transition raw 141,550 141,528 −22 (−0.0%) 🟢
suspense-transition gzip 44,727 44,725 −2 (−0.0%) 🟢
suspense-transition brotli 39,252 39,224 −28 (−0.1%) 🟢
binding-base-ui-vite raw 199,748 199,726 −22 (−0.0%) 🟢
binding-base-ui-vite gzip 62,770 62,776 +6 (+0.0%) 🔴
binding-base-ui-vite brotli 54,452 54,490 +38 (+0.1%) 🔴
binding-base-ui-esbuild raw 215,268 215,252 −16 (−0.0%) 🟢
binding-base-ui-esbuild gzip 69,720 69,719 −1 (−0.0%) 🟢
binding-base-ui-esbuild brotli 60,516 60,550 +34 (+0.1%) 🔴
binding-aria-esbuild brotli 2,982 2,979 −3 (−0.1%) 🟢
binding-radix-vite raw 201,779 201,757 −22 (−0.0%) 🟢
binding-radix-vite gzip 63,341 63,347 +6 (+0.0%) 🔴
binding-radix-vite brotli 54,997 55,021 +24 (+0.0%) 🔴
binding-radix-esbuild raw 217,092 217,076 −16 (−0.0%) 🟢
binding-radix-esbuild gzip 70,262 70,274 +12 (+0.0%) 🔴
binding-radix-esbuild brotli 61,037 61,018 −19 (−0.0%) 🟢
binding-apollo-client-vite raw 342,199 342,177 −22 (−0.0%) 🟢
binding-apollo-client-vite gzip 105,054 105,060 +6 (+0.0%) 🔴
binding-apollo-client-vite brotli 91,622 91,624 +2 (+0.0%) 🔴
binding-apollo-client-esbuild raw 365,411 365,395 −16 (−0.0%) 🟢
binding-apollo-client-esbuild gzip 116,033 116,051 +18 (+0.0%) 🔴
binding-apollo-client-esbuild brotli 101,228 101,189 −39 (−0.0%) 🟢

77 other measured values are unchanged.

@trueadm

trueadm commented Oct 8, 2026

Copy link
Copy Markdown
Collaborator Author

bundle size / bundle size checks fails with cli-spa-starter: ratchet raw budget 102235 to 102190. This diff doesn't change that scenario: its bytes are identical to main's, because the root journal isn't reachable there.

Main fails the same step on its own push: 90a57d8 reports cli-spa-starter: ratchet raw budget 102235 to 102211. The cause is #1891, a budget-only raise made ahead of #1875, so its ceilings sit above measured + 32 until #1875 lands. Lowering them here would remove #1875's raise, so this PR leaves the budget files alone.

Once main's ratchet is consistent again, this PR may need --write-budgets for the scenarios where it saves 16–22 raw bytes (listed in the description).

@trueadm

trueadm commented Oct 8, 2026

Copy link
Copy Markdown
Collaborator Author

The benchmark report's over-budget rows are already over on the base commit, main 90a57d8, before this diff:

Row Base Budget
suspense-transition raw 141,550 140,222
binding-base-ui-vite raw 199,748 198,414
bindings_fw_raw 341,194 339,858
chat_fw_gzip 36,798 36,791

This PR's own deltas: raw −16 to −22 in every bundle with the root journal, gzip −2 to +13, brotli −84 to +87. All 64 js-framework work counters are unchanged. The cli-spa-starter ratchet failure is the #1891 window described above. Both checks should clear once main's budgets match its measurements again. This PR doesn't raise or lower any budget.

@trueadm
trueadm merged commit f183be7 into main Oct 8, 2026
28 of 32 checks passed
@trueadm
trueadm deleted the fix/root-journal-slot-snapshot branch October 8, 2026 14:39
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.

1 participant