Repository navigation
fix(code-splitting): materialize consumer-local barrel routing when the order-wrap plan is empty - #10544
Conversation
✅ Deploy Preview for rolldown-rs canceled.
|
Merging this PR will not alter performance
Comparing Footnotes
|
0366bf6 to
ee2f15c
Compare
IWANABETHATGUY
left a comment
There was a problem hiding this comment.
Nice write-up in the description — I traced the three-way split (probe / projector / real
lowering) and the fix reads right to me. Couple of things I checked independently and they
hold up: consumer_local_reexport_plan never reads input.plan, so the probe and lowering
really do reach the same decision, and hoisting the call above the wrapper loop in
lower_order_state is behaviorally a no-op since that loop only touches
insert_order_wrapper / set_reexport_init_transparent. I also convinced myself the
exception is earning its keep: in the on-demand variant of
cjs_reexport_barrel_code_splitting_disabled the barrel is WrapKind::Esm, so the plan is
empty but it still owns a carrier — pull the guard and that snapshot flips.
None of the below blocks merging as far as I'm concerned — the fix is right and this is a
shipped crash, so landing it promptly is worth something on its own. A few things I'd like to
see follow, the first one ideally as a commit on this branch:
-
The
entries.len() <= 1half of the guard isn't covered by anything. The description
makes a good case that it's load-bearing (emitted chunk → second entry → per-entry placement
consumes the routes), but all five strict-order fixtures withcodeSplitting: falseare
single-entry, so deleting that clause passes CI while quietly restoring the #10515 cycle for
multi-entry non-splitting builds. That's exactly the kind of clause someone simplifies away
in six months. Cheapest fix I can see is acodeSplitting: falseconfig variant on
cjs_reexport_barrel_probe_plan_divergence— by your own reasoning that build still has to
route, so it should fail today with the clause removed and pass with it. -
The new
_test.mjsfiles only assert values. The thing that actually makes this fix
interesting — entry-a initializesa.cjsand never touchesb.cjs— lives only in the
snapshot right now, so a future snapshot regression sails past the test. The sibling fixture
you're citing asserts both the__eventsordering and the structural difference between
variants (assert.doesNotMatch(main, /init_pure_barrel_cjs/)); pushing to
globalThis.__eventsfrom the two leaves and asserting per-entry lists would pin the real
guarantee and match what the rest of the suite does. -
The empty-plan path isn't cheap anymore.
synchronous_cycle_modules(tarjan over the
whole module graph) plus theconsumer_local_reexport_planfixpoint now run on a path that
used to return immediately, and in on-demand mode an empty plan is the common healthy case.
The exception branch is the annoying one: it builds the SCC and the whole
OrderLoweringInputand then throws both away. An early return keeps that case exactly as
cheap as it was:if plan.is_empty() && code_splitting_disabled && self.link_output.entries.len() <= 1 { // …existing fast path… } // only now build cyclic_modules + input and compute the plan(CodSpeed being flat doesn't say much here — none of the benchmarks turn on
strictExecutionOrder.) -
Follow-up, not for this PR: the "all three phases must agree" invariant is currently held
up by a doc comment. The plan is pure overModuleIdx/SymbolRefvalues that survive
chunking, sopre_chunk_order_statecould compute it once and hand it to both the projector
andapply_order_wraps— that makes the invariant structural instead of documented and drops
two redundant fixpoints and two redundant SCC passes. Worth an issue; this is the second bug
that's come out of the three copies drifting. -
Also follow-up: in both new snapshots
barrel.jsis an entire emitted chunk holding
var init_barrel = __esmMin(() => {})and itsdefinePropertyexport, and each entry
carries a barerequire("./barrel.js")that does nothing. Correct, just an empty file plus a
startup require per entry. Collapsing a barrel that routing has emptied out seems worth
tracking separately.
Nits, take or leave:
ConsumerLocalReexportPlan::is_empty— carriers only get pushed alongside their owner
module, socarriers.is_empty()is already implied bymodules.is_empty(). Harmless, but
the&&hints at a state that can't happen.self.link_output.entries.len()counts distinct entry modules, whilegenerate_chunks
deliberately uses the flattened entry-point count and has a comment saying so. Unique
modules is the right quantity here (duplicate entry points on one module produce identical
bit sets), but a half-line note would save the next person the round trip I just made.- The
internal-docs/code-splitting/implementation.mdaddition tacks another ~700 characters
onto a paragraph that was already pretty dense. Content's right — maybe break the invariant
out into its own short paragraph?
|
Addressed in 73b525e and 60121af, with two deviations worth flagging:
|
60121af to
161ed54
Compare
Merge activity
|
…he order-wrap plan is empty (#10544) With `strictExecutionOrder`, a CJS multi-entry build whose entries `require()` ESM forwarders into one shared re-export-only barrel over CJS leaves emits chunks that `require()` each other in a cycle and crash at startup: ``` TypeError: require_barrel.init_barrel is not a function ``` Fixes #10515. Regression from #10488, shipped in v1.2.1. ## Problem Consumer-local re-export routing is computed in three places: the pre-chunk placement probe, the on-demand projector probes, and real lowering. The probes run `consumer_local_reexport_plan` unconditionally, and its eligibility never reads the order-wrap plan — but real lowering sits behind the `plan.is_empty()` short-circuit in `apply_order_wraps`. When every reachable ESM module is already interop-wrapped (the CJS entries `require()` the forwarders), the order-wrap plan is empty. Chunk placement has already routed each barrel leaf to only its consuming entry's chunk, while emission keeps the barrel's monolithic interop body referencing the per-entry `require_*` wrappers — so the emitted chunks require each other in a startup cycle. The on-demand carrier force-add cannot rescue this: an interop-wrapped barrel never passes `is_order_wrap_eligible`, so the final plan can stay empty even when the wrap-all plan is not. That also rules out fixing this on the probe side — the probe runs before chunking, while the on-demand plan is only computed from the chunk graph afterwards. ## Fix Compute the consumer-local plan before the short-circuit and take the fast path only when both the order-wrap plan and the consumer-local plan are empty. Real lowering then materializes exactly the routes placement consumed, in both strict modes, and `lower_order_state` receives the precomputed plan instead of recomputing it. One exception keeps an existing contract: with code splitting disabled and at most one entry, placement has a single reachability bit, so the probe's routes moved nothing, and an inert on-demand plan keeps its promise of flag-off-equivalent output (pinned by `cjs_reexport_barrel_code_splitting_disabled` from #10514). The disabled option alone is not a sufficient key — only dynamic entries are dropped in disabled mode, so a plugin-emitted chunk still adds a second entry whose per-entry placement consumes the probe's routes — hence the exception is keyed on entry count as well. ## Test - `cjs_reexport_barrel_probe_plan_divergence`: the seven-file reproduction from #10515, wrap-all + on-demand variants. Crashes on current `main`, passes with the fix; the barrel becomes an empty routing waypoint and each entry initializes only its own leaf through a per-record memoized carrier. - `cjs_reexport_barrel_on_demand_inert_plan`: adds a plain-ESM third entry so the wrap-all plan is non-empty while the on-demand plan stays empty — the shape a probe-side gate could not fix. On current `main` the wrap-all variant passes and the on-demand variant crashes; both pass with the fix. - No existing snapshot changes — every previously covered configuration emits byte-identical output.
161ed54 to
7221254
Compare
## [1.2.2] - 2026-08-03 ### 🚀 Features - code-splitting: support inlining of shared deps in dynamic entries (#10526) by @nicolo-ribaudo - plugin: time the user callbacks configured on the options (#10509) by @IWANABETHATGUY ### 🐛 Bug Fixes - dev: force `cleanDir` off in dev mode (#10579) by @shulaoda - dev: keep `?rolldown-lazy` proxy ids out of user `resolveId` hooks (#10580) by @btea - initialize re-exported wrapped ESM modules at the entry chunk (#10567) by @hyfdev - link: resolve circular star reexports as null (#10445) by @Nic-Polumeyv - transform: transformer gate skips newer syntax that oxc can lower (#10564) by @sekyungk - code-splitting: materialize consumer-local barrel routing when the order-wrap plan is empty (#10544) by @hyfdev - plugin: measure plugin hooks in JavaScript, report them from Rust (#10508) by @IWANABETHATGUY - plugin: include external dynamic imports in chunk metadata (#10557) by @hyfdev - plugin: report plugin timings after closeBundle has run (#10521) by @IWANABETHATGUY - browser: avoid using node builtin modules (#10542) by @sapphi-red ### 🚜 Refactor - plugin: give the build's own clocks their own type (#10520) by @shulaoda ### 📚 Documentation - correct stale `buildStart` comment in `ScanStageCache::merge` (#10577) by @shulaoda - update outdated pluginutils references (#10574) by @dogledogle ### ⚡ Performance - external: drop the runtime import from chunks that never wrap (#10517) by @IWANABETHATGUY - plugin: clock the build only when it is being measured (#10558) by @IWANABETHATGUY ### 🧪 Testing - vite-tests: drop the dead `@rolldown/pluginutils` pnpm override (#10575) by @IWANABETHATGUY - transform: group the transform-target fixtures and say why each exists (#10569) by @IWANABETHATGUY - dev: fix hmr-hot-update-hook-vite fixture on Windows (#10565) by @h-a-n-a - dev: match Vite's renamed full-reload log (#10547) by @shulaoda ### ⚙️ Miscellaneous Tasks - deps: update napi (#10576) by @renovate[bot] - deps: bump `@napi-rs/wasm-runtime` to 1.2.2 (#10570) by @shulaoda - deps: update npm packages (#10583) by @renovate[bot] - deps: update dependency rolldown-plugin-dts to ^0.28.0 (#10588) by @renovate[bot] - deps: update taiki-e/install-action action to v2.85.5 (#10587) by @renovate[bot] - deps: update codspeedhq/action action to v5 (#10584) by @renovate[bot] - deps: update github actions (#10582) by @renovate[bot] - deps: update rust crates (#10581) by @renovate[bot] - deps: update dependency vite-plus to v0.2.7 (#10568) by @renovate[bot] - deps: update dependency rolldown-plugin-dts to v0.27.14 (#10531) by @renovate[bot] - deps: update pnpm to v11.17.0 (#10571) by @renovate[bot] - deps: update @napi-rs/wasm-runtime to 1.2.1 (#10545) by @sapphi-red ### ❤️ New Contributors * @sekyungk made their first contribution in [#10564](#10564) * @nicolo-ribaudo made their first contribution in [#10526](#10526) Co-authored-by: shulaoda <[email protected]>
With
strictExecutionOrder, a CJS multi-entry build whose entriesrequire()ESM forwarders into one shared re-export-only barrel over CJS leaves emits chunks thatrequire()each other in a cycle and crash at startup:Fixes #10515. Regression from #10488, shipped in v1.2.1.
Problem
Consumer-local re-export routing is computed in three places: the pre-chunk placement probe, the on-demand projector probes, and real lowering. The probes run
consumer_local_reexport_planunconditionally, and its eligibility never reads the order-wrap plan — but real lowering sits behind theplan.is_empty()short-circuit inapply_order_wraps.When every reachable ESM module is already interop-wrapped (the CJS entries
require()the forwarders), the order-wrap plan is empty. Chunk placement has already routed each barrel leaf to only its consuming entry's chunk, while emission keeps the barrel's monolithic interop body referencing the per-entryrequire_*wrappers — so the emitted chunks require each other in a startup cycle.The on-demand carrier force-add cannot rescue this: an interop-wrapped barrel never passes
is_order_wrap_eligible, so the final plan can stay empty even when the wrap-all plan is not. That also rules out fixing this on the probe side — the probe runs before chunking, while the on-demand plan is only computed from the chunk graph afterwards.Fix
Compute the consumer-local plan before the short-circuit and take the fast path only when both the order-wrap plan and the consumer-local plan are empty. Real lowering then materializes exactly the routes placement consumed, in both strict modes, and
lower_order_statereceives the precomputed plan instead of recomputing it.One exception keeps an existing contract: with code splitting disabled and at most one entry, placement has a single reachability bit, so the probe's routes moved nothing, and an inert on-demand plan keeps its promise of flag-off-equivalent output (pinned by
cjs_reexport_barrel_code_splitting_disabledfrom #10514). The disabled option alone is not a sufficient key — only dynamic entries are dropped in disabled mode, so a plugin-emitted chunk still adds a second entry whose per-entry placement consumes the probe's routes — hence the exception is keyed on entry count as well.Test
cjs_reexport_barrel_probe_plan_divergence: the seven-file reproduction from strictExecutionOrder: pre-chunk consumer-local barrel routing without matching lowering emits a startup-crashing CJS chunk cycle #10515, wrap-all + on-demand variants. Crashes on currentmain, passes with the fix; the barrel becomes an empty routing waypoint and each entry initializes only its own leaf through a per-record memoized carrier.cjs_reexport_barrel_on_demand_inert_plan: adds a plain-ESM third entry so the wrap-all plan is non-empty while the on-demand plan stays empty — the shape a probe-side gate could not fix. On currentmainthe wrap-all variant passes and the on-demand variant crashes; both pass with the fix.