Repository navigation
perf(octane): let Vite's minifier drop unused optional drivers - #1942
Conversation
Vite 8 emits top-level `let` as `var` (Rolldown's `topLevelVar`). A `var` can be read before its initializer runs, so oxc only knows a never-assigned driver is "null or undefined" and folds only truthiness tests of it, and only when the declaration precedes every reader. `D !== null`, `D?.f()`, and plain local copies kept every optional capability's call sites in every bundle, including the 893 `STAGED_DOM?.view(x) ?? x` reads of ViewTransition's stage. Declare the optional drivers and stages above their readers and read them by truthiness (`D ? D.view(x) : x`, `D && D.f()`, `if (!D) return`, a needed local copy as `D ? D : null`). Applications that never install ViewTransition, native reads, Activity visibility, deferred layout, transition swaps, or form actions now ship none of that code: framework gzip drops 2.6 kB on the js-framework rows app, 3.0 kB on TodoMVC, and 3.7 kB on the weather app. The staged-DOM boundary check now accepts only the foldable receiver form, and a production Vite build test proves both directions: a plain app retains none of the driver declarations, and an app using each capability retains them all. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Deploying with
|
| Status | Name | Latest Commit | Preview URL | Updated (UTC) |
|---|---|---|---|---|
| ✅ Deployment successful! View logs |
octane-website | 5df7e8e | Commit Preview URL Branch Preview URL |
Oct 09 2026, 05:11 PM |
Deploying with
|
| Status | Name | Latest Commit | Preview URL | Updated (UTC) |
|---|---|---|---|---|
| ✅ Deployment successful! View logs |
octane-website-mcp | 5df7e8e | Commit Preview URL Branch Preview URL |
Oct 09 2026, 05:13 PM |
domgan-oai
left a comment
There was a problem hiding this comment.
The minifier-facing change is well targeted: it enables removal of unused capabilities without adding helper calls or duplicate driver state. I found one correctness regression in the optional-call rewrite, detailed inline. Using the existing view-transition-staging tests with production compilation, all three focused scenarios pass on the base, fail with this exact head's runtime, and pass with the outer inFlush branches braced.
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)
10 other measured values are unchanged. Public-import reachability bundles (bytes)
36 other measured values are unchanged. |
Expanding `if (inFlush) A?.f(o); else B?.g(o);` into truthiness tests made the `else` bind to the new inner `if (A)`, so outside a flush a same-component root render skipped refreshing the pending ViewTransition receipt and the prepared commit was dropped as stale. Brace the outer branch, and flatten the five other nested `if (cond) if (D)` statements the rewrite produced into `if (D && cond)` (each condition is side-effect free). Co-Authored-By: Claude Opus 5.5 <[email protected]>
…udit (#1943) #1915 renamed setText's text node to `target` and wrapped its journal call, so contracts.mjs's exact-string instrumentation found no match and the root-transactions audit threw before measuring anything. Match the call with a pattern that accepts any spelling of the staged-view read, so the pending ternary form in #1942 keeps matching too. Co-authored-by: Claude Opus 5.5 <[email protected]>
…chability (#2032) * test(bench): measure a rolldown + oxc split-chunk shell in bundle-reachability A production rolldown + oxc app ships Octane as ESM chunks: `codeSplitting` groups put the signal engine and the rest of the octane package in chunks of their own, and the renderer loads on a dynamic-import chain. No reachability fixture built that way, so nothing showed whether the optional-driver eliminations from #1855 and #1942 survive chunk boundaries, or what each chunk costs. The split-shell fixture hydrates a server-rendered shell after activating a renderer-free behavior island, with native reads of imported signals, a visible() Hydrate boundary, a lazy route behind useTransition, @Try over use(), a portal and a keyed list. It reports the whole application and each group's chunk, rejects Octane modules in application chunks, and checks through the source map that the runtime chunk drops the unused ViewTransition and Activity drivers. The chunks run in jsdom linked into one script. Co-Authored-By: Claude Opus 5.5 <[email protected]> * test(bench): resolve the linked split-shell entry without platform paths linkChunks found the entry chunk through path.relative, which joins with backslashes on Windows while chunk file names stay POSIX. Pass the virtual entry id as the link build's input instead. Co-Authored-By: Claude Opus 5.5 <[email protected]> * test(bench): list only each split-shell chunk's modules in its row The runtime and signals rows measure one chunk each but recorded the whole application's module list. Each chunk row now carries its own modules; the behavior snapshot stays on every row because all rows come from the one verified build. Co-Authored-By: Claude Opus 5.5 <[email protected]> --------- Co-authored-by: Claude Opus 5.5 <[email protected]>
Summary
Vite applications that never use an optional capability (ViewTransition, native signal reads, Activity and Suspense visibility, deferred layout, transition swaps, form actions) now ship none of its code. Framework gzip drops 2.6 kB on the js-framework rows app (−7.5%), 3.0 kB on TodoMVC, and 2.1–3.8 kB on every Vite scenario in
run-minimal. Behavior is unchanged.Why the code stayed
Vite 8 forces Rolldown's
output.topLevelVar = true, so every top-levelletinruntime.tsships asvar. Avarcan be read before its initializer runs, so oxc only knows a never-assigned driver is "its initializer orundefined". It therefore folds a test only when both values agree on the result (truthiness), and only when the declaration sits above the reader. I confirmed this with a repro on the repo's Vite 8.1.5 / Rolldown 1.1.5 (statements before the declaration areglobalThis.a = new WeakMap()):var D = nullif (D),D && D.f(),D ? D.f() : x,!DD !== null,D === null,D != nullD?.f(),D?.f() ?? xconst d = D; if (d)(plain local copy)const d = D ? D : nullvar D;(no initializer)The earlier audit's prototype gated each read with a separate
falseboolean. That works for the same reason, but it doubles the state per driver. Reading the driver itself by truthiness folds just as well, with no new variables and nothing to keep in sync.Changes
runtime.ts: declare the optional drivers and stages (STAGED_DOM, the transition, ViewTransition, visibility and deferred-layout drivers,STAGED_COMMIT_CAPTURE,FORM_SUBMIT_DRIVER,activityRefState,EFFECT_RECONNECT_CONTEXT) in one block above every reader. A comment there states the rule.STAGED_DOM?.view(x) ?? xreceivers becomeSTAGED_DOM ? STAGED_DOM.view(x) : x. That is exact, becauseDOMStage.viewreturns its argument or a proxy and never nullish. The rewrite was mechanical (AST codemod plus prettier), and most of the runtime line count is that rewrite and its reflow. Other forms:D?.m() === true→D && D.m()(each such method returnsboolean);D?.m() ?? d→D ? D.m() : dwheremnever returns nullish (splitCuecan, so it keeps its?? renderBlock);const d = D; if (d === null) return→if (!D) return; const d = D.transitionRoot,swapDriver×4), are writtenD ? D : null. Copies of drivers that are installed once and never cleared (visibility, ViewTransition flush) read the global instead.scripts/check-staged-dom.mjsnow accepts only the foldable receiverSTAGED_DOM ? STAGED_DOM.view(x) : x, soSTAGED_DOM?.view(x) ?? xandSTAGED_DOM !== null ? …are rejected. Fixtures are updated.packages/octane/tests/optional-driver-bundle.test.ts: two real Vite production builds (default oxc minifier, runtime bundled from source), checked with the existing source-map oracle fromhydration-free-gates.mjs. A plain list app retains none of nine optional declarations. An app using ViewTransition, Suspense, Activity and signals retains all nine, which proves the oracle can see each one. Both minified bundles then run (render, click, unmount), so the folded code is executed, not only measured.benchmarks/bundle-size/hydration-free-gates.d.mts: types for the gate helpers the test imports, followingbenchmarks/lib/dom-nodes.d.mts.benchmarks/root-transactions/contracts.mjs: itsjournalAttrpatch string now uses the new receiver spelling.octane-core-extendskill: one line on the driver read form, so the next change doesn't reintroduceD !== null. RuleSync copies regenerated.Validation
pnpm format:check: not run repo-wide;pnpm format:files:checkon every changed file passespnpm typecheck: not run repo-wide;pnpm typecheck:files packages/octane/src/runtime.ts packages/octane/tests/optional-driver-bundle.test.tspassespnpm test: left to CItargeted tests:
octaneandoctane-prod. On main'sruntime.tsthe plain-app case fails, with all nine declarations retained. Reverting one reached read (getFirstChild'sif (STAGED_DOM)→!== null) fails it withexpected [ 'STAGED_DOM' ] to deeply equal [].tests/hydration/inoctane+octane-prod: 332 file runs, 16,022 tests pass.octane+octane-prod(everyview-transition*,activity*,suspense*,transition*,form-action*,native-*,ref*,deferred*,manual-hook*,warm-plan*file and the new test), on head 5df7e8e: 102 file runs, 1,586 tests pass. Correction: my first run of these files never executed. zsh didn't split the file list I passed, so onlytests/hydration/ran, and the earlier version of this line claimed results I didn't have. The review caught a danglingelsethatview-transition-staging.test.tsdetects; it is fixed in 5df7e8e (see Risk).octane-signals-prod, full project: 25 files, 333 tests pass.signals-native*inoctane-signals+octane-signals-prod: 6 files, 50 tests pass.node scripts/check-staged-dom.mjsis clean;node --test scripts/check-staged-dom.test.mjs9/9;node --test benchmarks/bundle-size/hydration-free-gates.test.mjs11/11.Work counters:
node benchmarks/js-framework/pair.mjs --base-tree=<origin/main 4f82777bbd worktree> --work-only. All 40calls_*/dom_*counters are identical foroctane-tsrxandoctane-jsx(for examplecalls_run25,087 → 25,087,calls_runlots250,084 → 250,084,dom_clear10,004 → 10,004). These fixtures build withminify: 'esbuild', which never folds, so this shows the rewritten reads add no work. The folded oxc bundle is what the new test executes.Bytes, base
origin/main4f82777 vs head, same machine and commands.node benchmarks/bundle-size/run.mjs octane-tsrx octane-jsx, framework chunk:App chunks change only by +1–7 B (gzip/brotli) from cross-chunk import renaming; app source and compiler output are unchanged. The CI benchmark report matches these rows, and all 64 work counters are unchanged.
node benchmarks/bundle-size/run-minimal.mjs, gzip: every Vite runtime scenario drops 2,150–3,818 B, for exampleroot-static-specialized24,085 → 21,935,root-static52,694 → 48,876,hooks-state28,313 → 25,973,hydrate-root44,500 → 42,093,suspense-transition45,649 → 43,441,binding-radix-vite64,385 → 61,604. Theesbuildscenarios grow 19–30 B (for examplebinding-radix-esbuild+19,binding-usehooks-ts-esbuild+30). Server,capture-only,behavior-rootand isolated binding scenarios are unchanged.perf-review:node scripts/perf-review-scan.mjs→ 4 candidates, all dismissed. Hot paths touched:renderBlock(per render:NATIVE_READ_DRIVERbegin/end and theurgentTransitionDrivertest), the drain loop (per queued block: visibility find,splitCue, transition attempt), event dispatch (per event:pauseLifecycle), and DOM helpers (per node: staged receivers). Each read keeps the same work.X?.m()becomesif (X) X.m(), andX !== nullbecomes a truthiness test of the same object-or-null value.urgentTransitionDrivergains a leading driver test that short-circuits first when transitions are unused. No new fields, allocations, closures, DOM operations or scheduling, and thepair.mjscounters above are identical.packages/octane/src/runtime.ts(runtime-wide)?.where nothing folds: esbuild users +19–30 B gzip, full-API ceiling +19 Brun.mjs/run-minimal.mjsrows aboveDismissed candidates:
packages/octane/src/runtime.ts:9009-9010,9146-9147[layout-read]: existing focus-restorescrollLeft/scrollTopreads. Only the receiver spelling changed (STAGED_DOM?.view(x) ?? x→ ternary); order and phase are unchanged.concise-code: src +1,494 −1,157 (runtime +1,494 −1,157). 895 of the added runtime lines are the mechanicalSTAGED_DOMternary, and most of the rest is prettier reflow of those lines. New files: the test, which is the regression the change needs, andhydration-free-gates.d.mts, so the TypeScript test can import the existing oracle. No new exports in shipped code. Alternatives considered:falsegates: the same number of read-site edits, plus about 14 gate variables and writes at each installer, a second piece of state per driver.stagedView(x)helper for the 893 receivers: a few lines of diff, but oxc does not inline the folded identity function, which leaves about 158 calls in the rows bundle, and it puts a call back on every host operation (the runtime comment rules that out).topLevelVar: falsefrom the Vite plugin: no source change, but it changes TDZ semantics and costs for the whole application, not Octane's to choose.STAGED_DOMto something shorter to avoid reflow: gratuitous churn.Bytes: the rows above.
Risk / follow-ups
Fixed after review (5df7e8e): rewriting
if (inFlush) A?.f(o); else B?.g(o);asif (inFlush) if (A) A.f(o); else …bound theelseto the innerif. Outside a flush, a same-componentroot.render()then skipped refreshing the pending ViewTransition receipt. The outer branch is now braced, and the five otherif (cond) if (D)statements are flattened toif (D && cond)(each condition is side-effect free). An AST scan of main's source finds no other optional-call statement that was the then-branch of anif … else, and none of these nestedifs remain.Regression guard is partial by design. The new test fails if a reached read of any listed declaration stops folding, and the staged-DOM checker rejects non-folding receivers. A new driver, or a read in a path neither fixture reaches, still relies on the runtime comment and the skill line.
Deliberately left:
TRANSITION_ROOT_DRIVER/TRANSITION_TASK_DRIVERstay in the rows bundle (about 30–40 B gzip each). Their remaining reads are guarded byowner.transition !== undefinedorTRANSITION_QUEUE.length !== 0, which imply the driver is installed. Folding them needs an extra driver test at each site. The rest of the leftovers live outsideruntime.ts(installedEnvironment,signalOwnerFrame,hiddenTextWriter) and are under 40 B each.Existing breakage, not from this PR:
benchmarks/root-transactions/contracts.mjs'sjournalTextpatch string already matches nothing on main, because that call now passes a precomputedprevious. Theroot-transactionsaudit throws before it reaches thejournalAttrstring updated here.The esbuild +19–30 B and ceiling +19 B are the cost of the longer forms in bundles that cannot fold. They are reported, not gated.
Provenance
agent-authored)🤖 Generated with Claude Code
Need help on this PR? Tag
@codesmith-botwith what you need. Autofix is disabled.Note
Medium Risk
Touches pervasive hot-path runtime reads (staged DOM receivers, driver gates) across
runtime.ts; behavior is intended to be equivalent but regression coverage is partial for drivers not exercised by the new fixtures.Overview
Apps that never use optional capabilities (ViewTransition, Activity/Suspense visibility, native signal reads, staged DOM, etc.) can now ship less runtime after a Vite production build. Optional module-level drivers are declared above their readers and guarded with truthiness checks (
if (D),D ? D.f() : x) instead ofD !== null,D?.f(), orSTAGED_DOM?.view(x) ?? x, so oxc can fold never-installed drivers and drop the code behind them.The bulk of the diff is the mechanical
STAGED_DOM ? STAGED_DOM.view(node) : nodereceiver rewrite across the runtime, pluscheck-staged-domenforcement and updated fixtures. A newoptional-driver-bundle.test.tsruns real Vite production builds and uses the hydration-free source-map oracle to assert optional declarations are absent in a plain app and retained when ViewTransition, Suspense, Activity, and signals are used; both bundles are executed to confirm behavior is unchanged.Reviewed by Cursor Bugbot for commit 5df7e8e. Bugbot is set up for automated code reviews on this repo. Configure here.