Repository navigation
refactor(octane): split runtime.ts into concept modules - #2090
Conversation
scripts/split-runtime.mjs splits packages/octane/src/runtime.ts into concept modules under runtime/ from scripts/split-runtime.map.json, leaving runtime.ts as a facade with the same exports. It works from the TypeScript AST, moves each top-level statement with its comments unchanged, and adds only exports, imports, and the evaluation-order imports. `check` validates the map before anything is written: every declaration mapped and none stale, a `let` lives with every function that assigns it, drivers and Rolldown-uninlined constants stay above the reads oxc folds or inlines, module-scope initializers read only their own module, and load-time pure calls stay in the callee's module. `--suggest` places new declarations with the code beside them. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Once runtime.ts re-exports concept modules under runtime/, every tool that reads the runtime's source reads all of them: the render-writer check, the perf-review scan, error-code generation, the hydration-free gates and size runners, the redact-audit ledger, and the tests that bundle or scan the runtime. Each works on both layouts. Harnesses that patch runtime text and load it in place of runtime.ts read benchmarks/lib/client-runtime.mjs's joined runtime instead: every module's statements in evaluation order with runtime.ts's own exports, from the working tree or a git revision. The effect-postorder harnesses take their helpers by name rather than by slicing between declarations. Co-Authored-By: Claude Opus 5.5 <[email protected]>
… modules Co-Authored-By: Claude Opus 5.5 <[email protected]>
…vers through installers enqueueEffect, runTransition and the three root factories assigned their drivers inline, which made each of them a writer of state that lives with the scheduler. Each now calls an installer declared beside the drivers, on the same once-per-install path: the first effect slot, the first submit transition, and root creation. No call is added to a render, node, or update path, and the drivers keep their truthiness and noop tests. Co-Authored-By: Claude Opus 5.5 <[email protected]>
A root's hydration attempt set the scheduler's flag inline, which made the 381-line hydrateRootWithOutputHandler a writer of scheduler state. It now calls requestFlush, declared beside the flag. The attempt runs once per root hydration and once per suspended retry of it, never per render or update; the per-update schedulers keep setting the flag inline. Co-Authored-By: Claude Opus 5.5 <[email protected]>
… begin hydrating renders through helpers Four boundary and root paths incremented nextClientRootId inline, two deferred hydration notifications copied the same passive requeue, and a root's hydration attempt set ROOT_DISCARD_STAMP after beginning its render. Each now calls a helper declared beside the state it writes: takeClientRootId, requeuePassiveEffect and beginHydratingRootRender. Every one of these paths runs once per root, boundary arm, recovered Hydrate, or root hydration attempt, never per render, node or update. The per-render writes of the same state stay inline. Co-Authored-By: Claude Opus 5.5 <[email protected]>
`node scripts/split-runtime.mjs order` writes the split in place, builds the shell_ app's framework chunk, the full-surface ceiling and every Rolldown scenario of run-minimal.mjs with source maps, then restores runtime.ts. It cuts each chunk into the runs each module emitted and anneals over the module orders the map's constraints permit, scoring each by re-sequencing those runs and gzipping. Every permitted order keeps the same code, so only compression moves. The best of four seeded runs is written into the map's module order. run-minimal.mjs writes each Rolldown scenario's chunk and source map to BUNDLE_SIZE_MAP_DIR when it is set. The tool now formats the map it writes. Co-Authored-By: Claude Opus 5.5 <[email protected]>
With the cold driver installs and scheduler-state writes behind helpers, the module that must hold mutually assigned state shrinks from 8,237 to 5,179 declared lines. The render pass's state and its writers get their own render module, hydrateRootWithOutputHandler moves to roots, and the module order is the one `order` found: shell_ framework gzip 107,446 -> 106,770, full surface 164,403 -> 162,892 and run-minimal Rolldown scenarios 896,232 -> 892,353 against the mean-position order. Co-Authored-By: Claude Opus 5.5 <[email protected]>
The plain-module printer parses to ESTree, where `import {} from` and a bare
import are the same node, so it reprinted every order link as a bare import
and its fidelity test failed for the split runtime. An empty re-export prints
back unchanged, draws no esbuild warning or unused-import error, and keeps the
module order in Rolldown and esbuild. The joined runtime follows these links.
Co-Authored-By: Claude Opus 5.5 <[email protected]>
`check --suggest` placed next's new declarations: the module functions that replaced HydrationCapability's methods go to hydration, the CompiledContext and Provider children helpers to context, the commit-time marker and writer helpers with the concept that calls them. claimedHeadMarker moves to head, beside the claims it reads, which breaks a head/roots order cycle. The module order is the one `order` found. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Generated, not edited: `node scripts/split-runtime.mjs split` on runtime.ts at the previous commit with scripts/split-runtime.map.json. runtime.ts keeps its exports and re-exports 36 modules under runtime/; every statement moved unchanged with its comments. Regenerate this commit rather than editing it: drop it, rebase the commits before it, run `check --suggest`, `order`, then `split`. Co-Authored-By: Claude Opus 5.5 <[email protected]>
|
This PR is too large for Bugbot to review. It changes 98,344 lines and 4,049,930 characters. Split the change into smaller pull requests to get a review. |
domgan-oai
left a comment
There was a problem hiding this comment.
Reviewed f7e8fb8 against 4ae77f2. I found no blocking runtime correctness regression; one nonblocking maintenance clarification is inline.
The concept split addresses the oversized runtime directly. Writer co-location and the small installer extractions preserve the existing state model without introducing hot-path setter wrappers. Regenerating the split in memory from the pre-split parent reproduced all 37 files byte-for-byte: 2,170 declarations, zero unmapped/stale entries, and zero reported invariant violations.
Validation: 42 focused splitter/tooling tests and all four production-profile-bundle tests passed, as did the error-code and 152-writer audits. A separate Rolldown/Oxc production profiling bundle rendered successfully with the expected DOM counters. Three affected benchmark harnesses also passed smoke runs.
Limits: focused local checks used cached dependencies. I did not rerun the full workspace/browser suites, published ESM/CommonJS smoke tests, or the comparative performance matrix. Some current-head CI jobs are still running. Benchmarks that reconstruct a single runtime source file should be treated separately from measurements of the actual split module graph.
Deploying with
|
| Status | Name | Latest Commit | Preview URL | Updated (UTC) |
|---|---|---|---|---|
| ✅ Deployment successful! View logs |
octane-website-mcp | f7e8fb8 | Commit Preview URL Branch Preview URL |
Oct 15 2026, 01:52 PM |
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)
7 other measured values are unchanged. Public-import reachability bundles (bytes)
33 other measured values are unchanged. Lynx dual-thread render (report only)All 13 timed operations (13 without a verdict)
|
Deploying with
|
| Status | Name | Latest Commit | Preview URL | Updated (UTC) |
|---|---|---|---|---|
| ✅ Deployment successful! View logs |
octane-website | f7e8fb8 | Commit Preview URL Branch Preview URL |
Oct 15 2026, 01:53 PM |
Summary
packages/octane/src/runtime.ts(51,689 lines) into 36 concept modules underpackages/octane/src/runtime/.runtime.tsstays the facade with the same exports.scripts/split-runtime.mjsfromscripts/split-runtime.map.json. No statement is hand-edited: each top-level statement moves with its comments, and the only additions areexport, the imports it needs, and evaluation-order links.split-runtime.mjs orderchooses the module order gzip compresses best. Every framework gzip row is smaller than unsplitnext, and all 40 work counters are identical.Why
Changes
Tool (
scripts/split-runtime.mjs,scripts/split-runtime-order.mjs): works from the TypeScript AST and keeps comments.checkenforces five rules before anything is written:letlives with every function that assigns it.@__NO_SIDE_EFFECTS__calls stay in the callee's file.--suggestplaces new declarations,ordersearches the module order, andsplitemits.Module map: 36 modules. Two have no place in the evaluation chain:
types, andprofile-probes(profile builds only). The chain order is drivers > signal-owners > refs > engine > effects > view-transition > hooks > use > transitions > context > hydration > portals > block > hydrate-boundary > suspense > render > roots > hydration-presentation > signal-bindings > host-props > elements > diagnostics > component-slots > child-slots > branches > deopt > activity > lists > head > commit > templates > actions > events > forms. Largest: engine (scheduler, root transactions, commit pipeline; 5,087 lines), suspense (3,144), deopt (2,475), render (2,452: the render pass's state and its writers).Evaluation order: each module first names the module before it, and runtime.ts names the last. When a module imports nothing from its predecessor, the link is an empty re-export (
export {} from). A bare import draws an esbuild warning, a named one is an unused import, and ESTree printers rewriteimport {} fromas a bare import.verbatimModuleSyntaxkeeps these links through every transpile.Engine-shrink commits (runtime +63 −49). Every converted site is cold, meaning once per install, root, boundary arm or root hydration attempt:
installEffectDrivers,installManualFormPending,installRootErrorHandlersrequestFlushtakeClientRootId,requeuePassiveEffect(removes a duplicated block),beginHydratingRootRenderSites that run per render, per node or per update keep their inline writes:
withSlot,recordContextDependency,createPortal,setFormAction,useEffectEvent,useSyncExternalStore,makeRoot's render closures, and the per-update schedulers.Tooling: the render-writer check, perf-review scan, error-code generator, hydration-free gates, bundle-size runners, redact-audit ledger and nine test files now read
runtime.tsplusruntime/*.ts. Harnesses that patch runtime text readbenchmarks/lib/client-runtime.mjs, which joins the modules back into one file from the working tree or a git revision. run-minimal writes chunk source maps toBUNDLE_SIZE_MAP_DIRfor the order search.Docs: the RuleSync project rule, the skills and CONTRIBUTING.md now point at the concept modules.
Re-run procedure:
node scripts/split-runtime.mjs check --suggest, and review the suggestions until it reports 0 unmapped, 0 stale and 0 violations.node scripts/split-runtime.mjs order(about 17 minutes).node scripts/split-runtime.mjs split, and commit the output untouched.Validation
pnpm format:files:checkon every changed filepnpm typecheckpnpm ci:workflow:test: 432 testspnpm render-writes:check: 152 classified writers.pnpm error-codes:checkpasses.pnpm sync: no changes.pnpm testand the browser projects: left to CI.Work counters (
benchmarks/js-framework/pair.mjs --work-only, unsplitnextagainst this branch): 40 of 40 identical.Bytes against unsplit
next(4ae77f2), raw / gzip:The only run-minimal rows that grow are suspense-transition (+3 gz) and binding-usehooks-ts-esbuild (+15 gz).
shell_ app (
measure.mjs):run-hydration-free reports identical retained declarations.
Where the bytes come from:
orderchose, scoring shell_ + full surface + every run-minimal Rolldown scenario with equal weights. That search's numbers were measured before rebasing ontonext: shell 107,446 → 106,770, full surface 164,403 → 162,892 and run-minimal 896,232 → 892,353 against the mean-position order.Cold starts: Vitest cold start for one file went from 7.5–8.1 s to 5.8–6.3 s. Transforming the dev-server client graph went from 3.0 s to 0.9 s. Both were measured before the rebase, under load.
perf-review:node scripts/perf-review-scan.mjs --diffon the source commits finds one candidate.runtime.tsrequestFlush[microtask-hop] is dismissed: it moves an existing hop, and runs once per root hydration attempt. The split itself is a pure move, and the identical counters and bytes above are its evidence.concise-code: runtime +63 −49 in the source commits, and the generated split adds about 3.4k lines of imports, exports and headers. New files: the two tool modules, the map,benchmarks/lib/client-runtime.mjswith its test, and the 36 modules. Rejected alternatives: per-binding setters (about +500 B raw against grouped installers); also converting the 22 cold install sites that don't shrink engine (bytes without benefit); keeping the mean-position order (+0.3–1.4 kB gzip on full-surface bundles).Risk / follow-ups
check --suggest. A new writer of engine state from another concept forces that function into engine.verbatimModuleSyntax: a consumer that transpiles octane source that way drops the order links. This stays correct, but folding may not hold.Provenance
agent-authored)🤖 Generated with Claude Code
Need help on this PR? Tag
@codesmith-botwith what you need.