Skip to content

Runtime: replace the nine render-deferral mechanisms with one commit model (transitions, Suspense, off-screen, ViewTransition, signal transitions) #2029

Closed as not planned

Description

@trueadm

Summary

Octane writes to the live DOM while it renders. Every feature that needs "don't show this yet" (transitions that suspend, Suspense holds and reveals, off-screen swaps, ViewTransition, signal writes inside a transition) has therefore built its own way to hold back or undo those writes. There are nine such mechanisms today. React gets the same behaviour from one commit phase and a work-in-progress tree.

Measured on the shell_ app from #2027 (every feature in use; oxc minify; sourcemap attribution per declaration; gzip figures are the saving from deleting a group's bytes and re-gzipping, which runs about 20% low against a real build):

Area: transitions, Suspense/try/lazy, journal, off-screen, ViewTransition, signal transitions raw gzip
Octane 130.5 kB 39.0 kB
React 19.3 (commit phase, Suspense/Offscreen/Activity, throw/ping/retry, lanes, lazy, ViewTransition) 54.6 kB 15.5 kB

That is about 24 kB of the 54.5 kB gzip gap between the two shell_ twins (124.3 vs 69.8 kB). Even with no Suspense, lazy or ViewTransition in use, this machinery costs 14.7 kB gzip of the base app.

Nine mechanisms for one problem

# Mechanism What it hides or undoes raw gz
1 Root undo journal (record + rollback) binding writes of an attempt that suspends 7.4 2.4
2 Deferred root teardown + root commit removals until the root commits 4.9 1.4
3 Keyed-list chain records + row parking list moves and removals 4.2 1.3
4 Boundary journal windows + staged reveal groups per-boundary reveal batching 2.5 0.8
5 Off-screen render + effect capture/splice new subtrees at swap sites 4.6 1.4
6 Transition attempts + held root/sync transitions, replay/rebase, cell staging single-buffered state during a held transition 13.7 4.0
7 Suspense hide (display:none) / reveal / resume committed content under a fallback 10.6 3.0
8 DOMStage proxy + staged commit capture + deferred layout + ~600–800 inline STAGED_DOM checks ViewTransition's render before startViewTransition 34.4 8.3
9 Signals transition candidates (SignalActionFrame, transition coordinator) signal writes inside a transition 16.5 4.8

They overlap:

  • During a ViewTransition the journal (1) and DOMStage (8) are both active, so every write is logged twice: an undo entry plus a forward op whose guard is cancelled through journalUndo.
  • StagedCommitCapture wraps an OffscreenCapture (5), and DeferredLayoutCapture moves the same refs, stores and passives a second time.
  • Off-screen swaps (5) duplicate deferred root replacement (2) inside root transactions.
  • The signals coordinator (9) re-implements the renderer's begin/hold/rollback protocol through a 30-member host interface.
  • Hydration builds two more of its own: a DOM undo log and four separate Suspense hydration paths (Hydration: collapse the hydration engine back into the mount path (Ripple/Svelte-style cursor), 23 kB → ~5 kB gzip #2028).

Only part of #7 is React parity that any design keeps: display:none hiding, ref/effect disconnect and reconnect, and the retry throttle. These are React's hideInstance and disappear/reappearLayoutEffects.

Root causes

  1. Render is the mutation. Writes reach the live DOM during render, so withholding them needs either undo (journal), redirection (off-screen), or interception (DOMStage, which must answer every read-back of a node the runtime just wrote: parentNode, attributes, text, form ownership, selectors).
  2. State has one copy. React holds a transition as lane-tagged updates on each update queue and simply doesn't process them. Octane has to revert cells, re-render the pending cue against the old inputs, swap memo entries back and forth, harvest warm caches between rounds and then promote. Signals repeat all of this for their own cells.

Target design

  • Render writes a withheld op log; commit applies it. Writes go through a small set of write points (about 30) into a flat log in renderer-owned order. Commit applies the log as one batch. A suspended transition drops it, a Suspense reveal applies it, and an off-screen swap becomes a fresh subtree plus a withheld insert. ViewTransition applies the log inside startViewTransition, split into mutation/layout stages like React's flushMutationEffects/flushLayoutEffects.
  • Render stops reading back DOM it wrote. Structure comes from Block ranges and values from bag caches. This is the prerequisite for deleting DOMStage and its read projection. The keyed reconciler, clearChildContent and collectBlockRange must resolve ranges against renderer-owned structure instead of walking live siblings mid-render.
  • Transition holds come from update queues, not undo. Hook state gets React's model: a base value plus pending updates tagged by batch. Holding a transition means not processing its updates. Signal cells use the same queue, so the signals coordinator and candidate frames go away. A renderer-state journal for thrown-away renders survives only where something still lacks two copies (bag guards, list-chain records).

Estimated effect:

gzip
Fully replaced: journal DOM entries, deferred teardown, row parking, off-screen capture, reveal windows, staged commit/deferred layout, DOMStage, staged-DOM checks 11.7 kB
Partly replaced: rollback/commit core, attempts/holds, reveal/resume, signals coordinator up to 7.2 kB
New code: op log, applier, staged commit about +2 kB
Net about −10 to −17 kB

ViewTransition's own logic (naming, measuring, activation, 8.5 kB gzip against React's ~2.6 kB) is separate follow-up work.

Performance (estimated, to be measured). The always-on journal was earlier measured at 10–30% of update time. The op log costs the same one push per write, but drops:

  • reading old values back from the DOM (journalAttr's getAttribute)
  • range snapshots and undo closures
  • inserting and moving off-screen markers
  • the per-op staged-DOM branch

It adds one dispatch per op at commit. Expected −10% to +5% against today's journaled updates. Urgent updates must not regress.

Plan

Each step lands on its own, with the async-composition, transition, Suspense and ViewTransition suites green and update/mount benches compared against the base:

  1. Merge duplicate paths inside today's model (low risk, −2 to −3.5 kB gzip).
    • Off-screen swaps use root deferred replacement.
    • One hold record instead of HELD_SYNC_TRANSITION and owner.transition.
    • One reveal-window system.
    • The signals coordinator reuses the renderer's attempt protocol.
  2. Signal transitions on the update-queue model (−4 to −4.5 kB gzip). Fork semantics stay (decided 2026-10-13; see Signals: thin core — transitions via renderer update queues, commit-time subscriptions, seeds behind hydration (22 kB → ~8–10 kB gzip) #2031): signal cells get the same batch-tagged pending-update queue as hook state.
  3. No DOM read-back during render. Make the reconciler and writers resolve structure and values from renderer state. Measure update cost.
  4. ViewTransition on the op log. Delete DOMStage, the staged-DOM checks and the staged commit/deferred layout captures (−5 to −5.5 kB gzip alone).
  5. Transitions and Suspense on the op log. Delete journal DOM entries, deferred teardown, row parking, off-screen capture and reveal windows, and simplify reveal/resume.
  6. Holds from update queues. Replace revert, re-render and promote, and keep only the renderer-state journal that is still needed.

Must keep

  • Transitions: React semantics. All-or-nothing commit of a transition, committed UI held while it is pending, isPending, async-action entanglement, useOptimistic.
  • Suspense: fallbacks, display:none hiding with effect and ref disconnect/reconnect, retry throttling, Activity.
  • ViewTransition: update/name/class props that change within the same transition still choose the old snapshot correctly (the reason for feat: align ViewTransition with React and add element scopes #1095).
  • Moves don't disturb nodes: applying the log must not detach and reinsert nodes in ways that reload iframes, pause media or blur focused elements. This is why DOMStage withholds rather than applies and reverts.
  • Focus and selection preservation, controlled inputs, hydration adoption.
  • The already-closed divergences in packages/octane/audit/SUSPENSE_DIVERGENCE.md stay closed. This design should also close feat: add basic agent skills and MCP scaffold #4's remaining limitation (general transition-wide work in progress: content patched outside a suspended boundary can commit early), moving Octane fully onto React's semantics there.

Decided

  • Signal writes inside startTransition keep fork semantics (2026-10-13). The update-queue design must therefore cover signal cells and derived$/query$ producers, not only hook state.
  • DOM writes from render become visible at commit, matching React's timing (2026-10-13). Side effects of those writes therefore run during commit, not mid-render: custom-element attributeChangedCallback/connectedCallback, MutationObserver records, and anything they do, such as moving focus. Tests that pin the earlier mid-render timing are updated to React's. A prototype showed 4 focus-restoration tests depend on it.

Open questions

Refs: #2027 (benchmark), #2028 (hydration), #1095 (ViewTransition parity), #1864 (scheduling), #1801 (size umbrella), packages/octane/audit/SUSPENSE_DIVERGENCE.md.

🤖 Generated with Claude Code

Activity

  1. added
    perf
    refactor
    agent-authored
    on Oct 13, 2026
  2. trueadm commented on Oct 13, 2026

    @trueadm
    CollaboratorAuthor

    Per-render wrapper cost today (renderBlockInner), for sizing the new commit path

    These are measurements of the function that wraps every Block body render. It holds most of the per-render bookkeeping this issue replaces: the journal push, capture targets, the urgent-transition driver and warm-plan checkpoints. They show what that bookkeeping costs per render today and how V8 treats it on a cold hydration.

    Setup. benchmarks/app-frame-hydration, frame scenario (1,653 Blocks, 1,653 renders, signals on). Chromium 149 headless shell, 4× CPU throttle, a fresh browser context per cold sample. A/B runs use run.mjs N --base=<main> (paired ratios, bootstrap 95% CI). Base is main at c4b9932.

    1. Most of its profiled self time is compilation of what it calls

    • 79% of the function's cold CPU-profile ticks fall on the block.body(...) call line.
    • With only the interpreter enabled, a second hydration of the same HTML in the same page drops that line from 149 ticks to 7. The rest of the function is unchanged (199 → 172 ticks). So the cost is V8 compiling each body on its first call, charged to the caller's line, not per-render work.
    • --js-flags=--no-lazy has no effect in Chromium; --log-function-events still shows ~450 lazy compiles during hydration.
    • Inside one cold hydration window, lazy parse plus bytecode generation for runtime functions is ~28 ms at 4× (~390 functions); app code adds ~7.6 ms. That is roughly a quarter of the hydration, and it grows with the number of distinct functions a render or commit path reaches for the first time.

    2. The wrapper itself

    • 1,603 bytes of bytecode, 40 registers.
    • The common path runs about 300 bytecodes plus six calls: Array.prototype.push for the 4-slot journal entry, blockIsAncestor, contextEpochNow, the native-read driver's beginRender/endRender, and isSuspenseException.
    • With compile noise removed, its self time is ~3.3 ms of a 68 ms hydration at 4×, ~2 µs per render. Of that:
      • about a third is the body call itself;
      • the endRender + isSuspenseException line takes the largest share of the rest;
      • then the journal push, the ancestry check, beginRender, and the output-handler check.

    Which checks fire during the cold hydration (instrumented, 1,653 renders):

    Check Renders
    WIP_CAPTURE present and a root transaction, so effect-event targets come from the capture 1,653
    TRANSITION_JOURNAL at depth 1, with a JOURNAL_RENDER push 1,653
    Native-read driver begin/end 1,653
    Direct parent is the previous Block (ancestry walk could stop at one step) 1,550
    Output handler present, with an undefined return, so the slots[0].returnedOutput load runs 269
    Warm-plan stack length changed during the body 254
    rare record, context read maps, effect slots, native retry map, pending/replay, urgent-transition driver, invalid status 0

    On the hydration path the journal and capture bookkeeping is the common case, not a rare branch. Every render pays it, because hydration runs inside a root transaction. The checks that really are rare total only ~25–30 bytecodes.

    3. Tier-up

    Sampling %GetOptimizationStatus on every call gives this timeline:

    Calls Tier
    1–10 Ignition
    10–~730 Sparkplug
    ~730–1,116 Maglev
    1,117–1,653 (~540 calls) Sparkplug, never re-optimized
    • Bytecode size does not block tier-up; the Maglev compile takes 0.36 ms.
    • The drop back to Sparkplug comes from an eager "wrong map" deopt on the returnedOutput load. That load reads whatever record a Block keeps in slots[0], an open-ended set of shapes.
    • %HaveSameMap shows the slots arrays themselves are stable.
    • With that load removed (measurement only), Maglev arrives at about call 530, and the function re-optimizes after a second deopt.

    4. How much moving it is worth (paired cold hydration, head/base)

    Variant Pairs Cold Warm
    Stripped wrapper with behaviour cut to this bench: no status/capture/urgent/replay/rare/context checks, no try/finally, no returnedOutput load. A ceiling only 100 0.985 [0.979–0.992] 0.997 [0.979–1.003]
    Behaviour-preserving call cuts: direct-parent shortcut, isSuspenseException only on failure 200 0.999 [0.995–1.005] 1.003 [1.000–1.008]
    No returnedOutput load, so it stays in Maglev longer 100 0.994 [0.991–0.998] 0.997 [0.989–1.011]

    Deterministic counters (Blocks, renders, jitless heap bytes) were identical across all variants. No change was landed.

    What this suggests for the new commit path

    • The per-render deferral bookkeeping costs at most ~1.5% of a cold hydration today. Wall-clock wins should come from the deletions, not from cheaper per-render checks.
    • The cold-start cost that does scale is how many distinct functions a render or commit reaches on first use. Fewer, larger write points and one applier should help through compile cost as much as through bytes.
    • Keep property loads in the per-render function monomorphic. One load over an open-ended record shape, like slots[0].returnedOutput, is enough to drop it out of Maglev for the rest of a cold hydration.
    • If the new design keeps a per-render entry, as JOURNAL_RENDER is today, it runs on every hydration render. Keep its entry shape and push site fixed.
  3. trueadm commented on Oct 13, 2026

    @trueadm
    CollaboratorAuthor

    Agent-authored note (Claude Code, for @trueadm).

    A scheduling rule this commit model must support

    @trueadm decided the following on 2026-10-13 (#1864), and #2028 step 5 implements it. The full rule, the numbers and the lessons are on #2028; that issue was closed by accident when #2033 merged.

    When boundaries hydrate through the client retry path, they follow React 19's schedule:

    • Arms after the shell. hydrateRoot adopts and commits the shell in one task. Server-resolved Suspense arms stay dehydrated, holding server DOM. They hydrate in later host tasks, in document order, at least one per task within the shared ~5 ms host budget.
    • Selective hydration. A discrete event aimed at a dehydrated arm hydrates it synchronously, then dispatches.
    • Updates. An update or a context change that reaches a dehydrated arm hydrates it first, with its server inputs and context, then applies the update. The arm renders on the client only when that is impossible.
    • Resume without a parent replay. Resuming an arm renders only the boundary, never its parent.

    What this needs from the commit model:

    1. One commit per dehydrated boundary, or per batch of boundaries, in a later task. Each commit runs that boundary's refs and layout effects after the shell's have run, and it never re-renders the parent. The budget-only prototype resumed arms through scheduleRender(parentBlock) and paid for it:

      without replay with replay
      Busy total baseline +26%
      renderBlockInner calls 1,674 2,886
    2. A synchronous hydrate-and-commit inside an event dispatch. Selective hydration has to finish its commit before the dispatch continues.

    3. Holding an update while the boundary it reaches hydrates first. This is React's bumped-lane SelectiveHydrationException. The update-queue holds planned in step 6 fit this.

      Hydrating the arm inside the update's own render failed in perf(octane): hydrate server-resolved Suspense boundaries after the shell #2040. It made the arm read external state that a shell layout effect had already changed, so the arm fell back to client rendering and lost its server DOM.

    The reference implementation, #2040, is kept as a draft and won't merge on today's engine. On frame-boundaries at 4× CPU it took the longest task from 87.7 to 20.5 ms, with busy total +3.8%. It builds three pieces on today's resolved-arm path, and this model would have to rebuild them:

    • Direct resume. A deferred arm hydrates inside its root's render transaction and its parent's render context, and arms commit in batches.
    • Root-node capture listeners for selective hydration. These are installed on each waiting arm's root node only while arms wait. They are needed because delegation is lazy per event type.
    • Hydrate-first on update. This lives in tryBlock.

    That path relies on the undo journal and off-screen capture that steps 5–6 delete: its speculative attempt, rollback, and createOffscreenCapture. So the deferral is better built once, on this model, through #2028 step 5.

    Two more points from #2040 for this model:

    • Avoid the per-Block preserveRootCreatedDom cost. An arm committed outside the root's hydrating transaction called it once per created Block, about +5% busy time, until its transaction was marked hydrating. The new model's hydration commits should not pay it.
    • Fold in the suspended-arm retry. An arm whose own hydration suspends still retries through scheduleRender(state.parentBlock), a parent replay, as on main. A single resume route should cover it too.
  4. trueadm commented on Oct 13, 2026

    @trueadm
    CollaboratorAuthor

    Superseded by #2043, which describes one vision covering the commit model, one renderer and signals. The decisions recorded here (signal fork semantics, React commit timing) carry over.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    agent-authoredperfrefactor

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions