Repository navigation
perf(octane): mark a root slot's snapshot instead of keeping a structures Map - #1897
Conversation
…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]>
Benchmark report
Compares js-framework: 1k/10k row operationsAll 20 timed operations (20 without a verdict)
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").
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").
77 other measured values are unchanged. |
|
Main fails the same step on its own push: 90a57d8 reports Once main's ratchet is consistent again, this PR may need |
|
The benchmark report's over-budget rows are already over on the base commit, main 90a57d8, before this diff:
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 |
Summary
Before a root render restructures a slot (
@if,@switch, a component slot, a child hole),journalRootSlotsnapshots the slot and its DOM range, so a suspension can roll the change back. It used to dedupe that capture through a separate per-transactionstructuresMap, and it logged an undo closure to clear the Map entry on replay. The slot snapshot it also takes already lives inseen(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 fromjournalObjectOnce(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.
journalRootSlotwas 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@ifpaid for twostructuresMap operations, an undo closure with its context, and an extra log entry.Changes
packages/octane/src/runtime.ts,journalRootSlotonly: dedupe through the snapshot entry inseen(odd index = range taken) instead oftransaction.structuresplus astructures.deleteclosure.journalRootChildrenstill usesstructuresfor 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).octanepatch).Performance
Chromium headless, production builds of
benchmarks/portal-swarm/octane-tsrx, served with COOP/COEP. Base is main2f81266018; candidate is this head.open_close_cycle, paired median ratio [95% bootstrap CI], run 1open_close_cycle, run 2open_all, run 1open_all, run 2Method: 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_cycleand under 1% onopen_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 --budgetsandrun.mjs --budgets octane-tsrx octane-jsxboth pass against this head's committed budgets.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-budgetsfor the scenarios above.Validation
pnpm format:check: not run repo-wide;pnpm format:fileson the 3 changed files (no changes).pnpm typecheck: not run repo-wide.pnpm typecheck:fileson the 2 changed files reports the same 311 pre-existing TS17004/TS7006 errors in untouched.tsrxfixtures as main does; none are in the changed files.pnpm test: left to CI.--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.journalRootSlot's range capture: the new test fails (dev + prod), plus 4 existing tests;pnpm syncclean.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 sameJOURNAL_BAG4-tuple asjournalObjectOnce, the slot clone is unchanged, andseenvalues stay Smis. No new references (reachability), DOM, or scheduling. No must-fix or needs-evidence findings.Risk / follow-ups
TrySlot), other entries already restore that DOM. The check keeps capture semantics identical to main.journalRootRangeclosure: no measurable gain. NamingrestoreRootRangefrom the replay switch made it reachable in bundles without the root journal (+190 raw in some).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.journalRootProperty(parentScope.slots…)inportal()for discard-stamped scopes: saves one 4-slot push per compiled portal mount, which is unmeasurable, and adds bytes to compiled-portal apps.unregisterPortalEventRangeallocates about 137 KB per cycle (deleteon comment-node expandos). That is the portal teardown path.journalAttr, a DOM read each) on freshly created de-opt elements, about 0.7%.Provenance
agent-authored)🤖 Generated with Claude Code
Need help on this PR? Tag
@codesmith-botwith 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
journalRootSlotno longer dedupes structural slot captures via a per-transactionstructuresMap and ajournalUndoclosure. It reusesTRANSITION_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
RevealAgainAppand a test where one root attempt reveals a@tryboundary, 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.octanepatch changeset; portal-swarm sees ~6.6% less allocation per open/close and modestopen_close_cyclespeedup; 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.