fix(code-splitting): fold the runtime chunk back after order lowering#10414
Open
hyfdev wants to merge 2 commits into
Open
fix(code-splitting): fold the runtime chunk back after order lowering#10414hyfdev wants to merge 2 commits into
hyfdev wants to merge 2 commits into
Conversation
✅ Deploy Preview for rolldown-rs ready!
To edit notification comments on pull requests, go to your Netlify project configuration. |
hyfdev
force-pushed
the
fold-runtime-chunk-after-order-lowering
branch
from
July 24, 2026 03:36
eac3d40 to
8548a60
Compare
19 tasks
Merging this PR will not alter performance
Comparing Footnotes
|
hyfdev
commented
Jul 24, 2026
hyfdev
marked this pull request as draft
July 24, 2026 04:14
hyfdev
force-pushed
the
fold-runtime-chunk-after-order-lowering
branch
from
July 24, 2026 07:18
8548a60 to
6265551
Compare
hyfdev
marked this pull request as ready for review
July 25, 2026 07:29
ensure_runtime_module_for_order_wraps unconditionally left the runtime on a standalone chunk because the baseline merge proof runs before order analysis and never saw the helper demand lowering adds. By the end of lowering that demand is fully materialized in OrderWrapState, so re-run the merge proof with the post-lowering consumer set: sole-consumer hosts only (any other host creates or reorders chunk-evaluation edges the order analysis never modeled), esm output only (cjs output later mints an invisible __toCommonJS demand on ESM-exports entry chunks), and without widening the host's bits (the order-time standalone chunk carries synthetic all-live-union bits). Part of #10294.
…the implementation contract
hyfdev
force-pushed
the
fold-runtime-chunk-after-order-lowering
branch
from
July 25, 2026 07:29
58e262b to
eae550d
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
First P1 item of #10294:
ensure_runtime_module_for_order_wrapsunconditionally evicts a co-hosted runtime module onto a standalonerolldown-runtimechunk (and mints one when the runtime was unplaced), even when every helper consumer lives in a single chunk.issues/9463ships arolldown-runtime.jswhose only content is two helper re-exports consumed exclusively bycommon~a~b~shared.js— one extra request per page load for nothing, in both wrap modes.The eviction itself is justified: the baseline merge proof (
try_merge_runtime_chunk, called fromgenerate_chunksand the chunk optimizer) runs before order analysis, so nothing it proved covers the helper demand order lowering adds (__esm/__esmMinper wrapper,__toCommonJS/__reExportper lowered overlay). What was missing is re-running the proof afterwards: by the end of lowering the full demand is materialized inOrderWrapState, so the complete post-lowering consumer set is knowable.Fix
ensure_runtime_module_for_order_wrapskeeps its normalize-to-standalone behavior unchanged, then re-runs the merge proof with the post-lowering consumer set:OrderWrapState::runtime_helper_consumer_chunkscollects the order-introduced consumers: each wrapper's syntheticinit_*statement renders in its assigned chunk, and each overlay's lowered import/require glue renders in the importer's chunk. Pre-lowering demand is re-collected bycollect_runtime_consumer_chunks's own scan (chunk helper bits, interop wrappers, statement-level runtime symbol references), and stale/tombstoned chunks are filtered by the existingpost_chunk_optimization_operationsguard.try_merge_runtime_chunkgains aRuntimeMergeCascadeparameter. The two pre-existing call sites useFull(byte-identical cascade). The post-lowering fold usesSingleConsumerOnly, and two deliberate restrictions apply:compute_cross_chunk_linkslater gives every ESM-exports entry chunk — including the zero-module order facades — a__toCommonJSdemand that is invisible at fold time; folding would hand an entry chunk with no visible demand a brand-newrequireedge into a user chunk. Every other post-fold demand source was audited to be either Esm-excluded or already represented in the fold-time consumer set.SingleConsumerOnlymode the merge tail skipstarget_chunk.bits.union(...): the sole consumer's own bits are already exact (the runtime becomes internal to it), while the order-time standalone chunk carries synthetic all-live-union bits whose widening would leak into bits-derived chunk names.Non-esm formats and
strictExecutionOrder: falsebuilds are byte-for-byte untouched; the fold only runs from the order-wrap path (non-empty plan).Output shape
issues/9463(acceptance):rolldown-runtime.jsdisappears and the helpers inline intocommon~a~b~shared.jsin both cells; same forissues/9463_plain_group,issues/9463_three_entries, andstrict_execution_order/concatenate_basic(wrap-all cells fold intomain2.js). 40 snapshots change, all strict-mode fixtures, all the same shape: the standalone runtime chunk is gone and its (actually demanded) helpers render inside the sole consumer —issues/5870andmixed_static_dynamic_same_targetalso drop a previously exported-but-unconsumed__exportAll, since the host renders only demanded statements.One snapshot-cosmetic note: in fixtures where the runtime region folds ahead of a synthetic wrapper rendered without its own region markers (pre-existing quirk), the
HIDDEN [\0rolldown/runtime.js]replacement visually swallows the following wrapper in the snapshot (top_level_await_syntax). The raw emitted chunk was dumped and verified correct —init_foois present; only the snapshot display collapses it.Validation
strictExecutionOrder/onDemandWrapping: follow-up ledger #10294) — zero failure signatures introduced or altered by this change.Part of #10294.