Skip to content

feat: inline common chunks containing import() and deduplicate shared code in lazy chunks - #11034

Merged
hyfdev merged 2 commits into
mainfrom
feat/inline-common-chunk-placement
Sep 30, 2026
Merged

hyfdev merged 2 commits into
mainfrom
feat/inline-common-chunk-placement

Conversation

@hyfdev

@hyfdev hyfdev commented Sep 29, 2026 •

Copy link
Copy Markdown
Member

With common-chunk inlining enabled, shared loaders can remain separate files, and lazy chunks can include shared code already supplied by their importers. This PR inlines eligible shared loaders containing resolved internal import() calls and omits redundant copies when every entry loading path provides the shared module.

For an entry that uses a shared module and dynamically loads a second reader:

// main.js
import { state } from './shared.js';
console.log(state);
globalThis.load = () => import('./lazy.js');

// lazy.js
import { state } from './shared.js';
console.log(state);

Before, the shared module is merged with the entry's implementation, leaving a separate file to start the entry. Simplified output:

main.js          starts the entry
main-impl.js     main + shared
lazy.js          lazy, importing shared from main-impl
runtime.js

After:

main.js          main + shared factory
lazy.js          lazy, reading shared from the runtime
runtime.js

Changes

  • Allow common chunks containing resolved internal dynamic imports to be inlined. Each output file containing a copy gets the correct relative import path, dynamic-import metadata and target hash dependency. Computed and ignored imports stay in their own file to preserve relative resolution.
  • Apply the import.meta restriction only to statements retained by tree-shaking. An unused function or initializer containing import.meta does not keep an otherwise eligible common chunk as a file.
  • Keep eligible shared code separate during the earlier entry assignment and merging steps, so the inline pass can remove the common file rather than leave shared code inside an entry implementation chunk.
  • Omit a shared factory only when every loading path from configured or plugin-emitted entries has registered it. Intersect multiple parents, include imports in every possible copy of a shared loader, and treat an unknown dynamic target as potentially reaching any output file. A lazy chunk retains its copy if a parent cannot provide the shared module.
  • Accept maxSize: Infinity as an unlimited threshold.

With two independent entries that each provide the shared module before loading the same lazy chunk, the shared factory count falls from three to two. Module initialization and shared state remain common to all readers.

Validation

  • 111 feature tests, 17 placement unit tests and 300 generated module graphs passed. Coverage includes copied loaders in different directories, target hash changes, discarded import.meta, missing and unknown parents, nested imports, entry roots and minified output.
  • just test-rust, just t-node and just lint passed.

Stacked on #10899.

@hyfdev
hyfdev added this pull request to stack #11006 September 29, 2026 16:13
@netlify

netlify Bot commented Sep 29, 2026 •

Copy link
Copy Markdown

✅ Deploy Preview for rolldown-rs canceled.

Name Link
🔨 Latest commit 85bd27b
🔍 Latest deploy log https://app.netlify.com/projects/rolldown-rs/deploys/6abd08323bf3f90008e8fff9

@cloudflare-workers-and-pages

cloudflare-workers-and-pages Bot commented Sep 29, 2026 •

Copy link
Copy Markdown

🚀 Deploying Preview to Cloudflare 🚀

Preview URL: https://feat-inline-common-chunk-placement-rolldown-rs.voidzero-docs.workers.dev (commit 85bd27b)

This URL reflects your latest Preview deployment

Preview Deployments by commit

Status Deployment URL Commit Updated (UTC) See this deployment's details
  • Build: Success ✅
  • Deployment: Success ✅

View logs ↗
https://f2197d3b-rolldown-rs.voidzero-docs.workers.dev 85bd27b 2026-09-30T13:04:25.834Z Visit the dashboard ↗
  • Build: In progress 🔵

View logs ↗
16a74cf 2026-09-30T13:00:33.120Z View logs ↗
  • Build: Success ✅
  • Deployment: Success ✅

View logs ↗
https://374df721-rolldown-rs.voidzero-docs.workers.dev b7eeb99 2026-09-30T12:48:31.753Z Visit the dashboard ↗
  • Build: Success ✅
  • Deployment: Success ✅

View logs ↗
https://8909b375-rolldown-rs.voidzero-docs.workers.dev 055bdaf 2026-09-30T12:42:20.701Z Visit the dashboard ↗
  • Build: Success ✅
  • Deployment: Success ✅

View logs ↗
https://2d12ea6e-rolldown-rs.voidzero-docs.workers.dev 579cb84 2026-09-30T10:30:20.296Z Visit the dashboard ↗
  • Build: Success ✅
  • Deployment: Success ✅

View logs ↗
https://8665db06-rolldown-rs.voidzero-docs.workers.dev 887ea0f 2026-09-29T16:17:40.503Z Visit the dashboard ↗

@hyfdev
hyfdev marked this pull request as ready for review September 30, 2026 03:06
Copilot AI balanced review requested due to automatic review settings September 30, 2026 03:06

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot review overview

🟡 Changes recommended

Dead dynamic imports can incorrectly propagate metadata and hash dependencies into carrier chunks.

Review effort: Balanced
Findings: 1 Medium severity

Open (1)
What changed in this PR

Extends inline common chunks to support internal dynamic imports, deduplicate factories across lazy loading paths, and allow unlimited size thresholds.

Changes:

  • Tracks dynamic-import and import.meta behavior per retained statement.
  • Adds entry-path-aware factory placement and dynamic-edge projection.
  • Adds comprehensive fixtures, behavioral tests, and documentation.
File Description
packages/​rolldown/​tests/​src/​inline-common-chunks/​harness.ts Updates roots and registration checks.
packages/​rolldown/​tests/​behaviors/​inline-common-chunks/​inline-common-chunks.test.ts Adds dynamic-loading and placement tests.
packages/​rolldown/​src/​options/​output-options.ts Documents unlimited sizing.
internal-docs/​inline-common-chunks/​implementation.md Documents implementation changes.
internal-docs/​inline-common-chunks/​design.md Documents loading-path placement.
internal-docs/​code-splitting/​implementation.md Documents earlier placement preservation.
crates/​rolldown/​tests/​rolldown/​function/​inline_common_chunks/​kept_as_file/​dynamic_import_member/​artifacts.snap Removes obsolete snapshot.
crates/​rolldown/​tests/​rolldown/​function/​inline_common_chunks/​errors/​max_size_negative/​artifacts.snap Updates validation message.
crates/​rolldown/​tests/​rolldown/​function/​inline_common_chunks/​dynamic_import_member/​shared.js Adds shared dynamic loader fixture.
crates/​rolldown/​tests/​rolldown/​function/​inline_common_chunks/​dynamic_import_member/​lazy.js Adds lazy target fixture.
crates/​rolldown/​tests/​rolldown/​function/​inline_common_chunks/​dynamic_import_member/​b.js Adds second fixture entry.
crates/​rolldown/​tests/​rolldown/​function/​inline_common_chunks/​dynamic_import_member/​artifacts.snap Captures inlined loader output.
crates/​rolldown/​tests/​rolldown/​function/​inline_common_chunks/​dynamic_import_member/​a.js Adds loader-consuming entry.
crates/​rolldown/​tests/​rolldown/​function/​inline_common_chunks/​dynamic_import_member/​_test.mjs Verifies runtime behavior.
crates/​rolldown/​tests/​rolldown/​function/​inline_common_chunks/​dynamic_import_member/​_config.json Configures fixture inputs.
crates/​rolldown/​tests/​rolldown/​function/​inline_common_chunks/​dynamic_entry_reader/​artifacts.snap Reflects inherited factory removal.
crates/​rolldown/​src/​utils/​prepare_build_context.rs Accepts positive infinity.
crates/​rolldown/​src/​stages/​link_stage/​reference_needed_symbols.rs Preserves conditional helper demand.
crates/​rolldown/​src/​stages/​generate_stage/​inline_common_chunks/​select.rs Expands candidate selection rules.
crates/​rolldown/​src/​stages/​generate_stage/​inline_common_chunks/​rewire.rs Projects copied dynamic edges.
crates/​rolldown/​src/​stages/​generate_stage/​inline_common_chunks/​place.rs Adds entry-path-aware pruning.
crates/​rolldown/​src/​stages/​generate_stage/​dynamic_already_loaded.rs Preserves inline candidates.
crates/​rolldown/​src/​stages/​generate_stage/​chunk_optimizer.rs Avoids premature candidate merging.
crates/​rolldown/​src/​ast_scanner/​impl_visit.rs Records per-statement metadata.
crates/​rolldown_testing/​_config.schema.json Documents infinity semantics.
crates/​rolldown_error/​src/​build_diagnostic/​events/​invalid_option.rs Updates validation diagnostics.
crates/​rolldown_common/​src/​types/​stmt_info.rs Adds statement-level ImportMeta.
crates/​rolldown_common/​src/​inner_bundler_options/​types/​inline_common_chunks_options.rs Documents normalized unlimited size.
crates/​rolldown_common/​src/​ecmascript/​ecma_view.rs Removes module-wide import-meta flag.

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

@codspeed

codspeed Bot commented Sep 30, 2026 •

Copy link
Copy Markdown

Merging this PR will not alter performance

✅ 7 untouched benchmarks
⏩ 10 skipped benchmarks1


Comparing feat/inline-common-chunk-placement (85bd27b) with main (bad4b6e)

Open in CodSpeed

Footnotes

  1. 10 benchmarks were skipped, so the baseline results were used instead. If they were deleted from the codebase, click here and archive them to remove them from the performance reports. ↩

@hyfdev
hyfdev force-pushed the feat/inline-common-chunk-placement branch from 579cb84 to 055bdaf Compare September 30, 2026 12:39
@hyfdev
hyfdev force-pushed the feat/inline-common-chunk-placement branch from 055bdaf to b7eeb99 Compare September 30, 2026 12:46
Base automatically changed from feat/experimental-inline-common-chunks to main September 30, 2026 13:00
@hyfdev
hyfdev force-pushed the feat/inline-common-chunk-placement branch from b7eeb99 to 16a74cf Compare September 30, 2026 13:00
@hyfdev
hyfdev force-pushed the feat/inline-common-chunk-placement branch from 16a74cf to 85bd27b Compare September 30, 2026 13:01
@hyfdev
hyfdev merged commit 6450f2e into main Sep 30, 2026
36 checks passed
@hyfdev
hyfdev deleted the feat/inline-common-chunk-placement branch September 30, 2026 13:06
@rolldown-guard rolldown-guard Bot mentioned this pull request Sep 30, 2026
shulaoda added a commit that referenced this pull request Sep 30, 2026
## [1.2.12] - 2026-09-30

### 🚀 Features

- inline common chunks containing import() and deduplicate shared code in lazy chunks (#11034) by @hyfdev
- experimental `inlineCommonChunks` support (#10899) by @hyfdev
- dev: ship imported bindings for HMR partial accept (#10856) by @h-a-n-a

### 🐛 Bug Fixes

- chunking: re-derive chunk exec orders after the runtime leaves its host chunk (#11005) by @hyfdev
- code-splitting: gate member-read init paths on the reading statement (#11039) by @hyfdev
- code-splitting: retain initialization paths through re-exported namespaces (#11037) by @hyfdev
- dev: reject non-ESM output formats in dev mode (#11038) by @h-a-n-a
- dev: align `import.meta.hot.accept` deps with Vite (#10997) by @h-a-n-a
- dev: clear the resolver cache when a file is created or deleted (#10986) by @waltuov
- error: name the resolved specifier in unresolved import diagnostics (#11014) by @linyiru
- make entries-aware chunk merging deterministic (#11002) by @hyfdev
- watch: avoid restarting macOS watcher for unchanged paths (#10992) by @sep2

### 🚜 Refactor

- dev: ship the dev runtime entry as one file (#10998) by @h-a-n-a
- binding: remove `__internalForcePanic` (#10989) by @IWANABETHATGUY

### 📚 Documentation

- fix cloudflare preview builds (#10996) by @sapphi-red
- fix build config loader warning (#10994) by @sapphi-red
- deps: use Vite 8 (#10993) by @sapphi-red

### ⚡ Performance

- dev: only ship rows with dynamic edges in registerGraph (#11019) by @h-a-n-a

### 🧪 Testing

- code-splitting: cover more re-exported namespace shapes (#11042) by @hyfdev
- webcontainer: cover the WebContainer download fallback in plain Node (#10966) by @shulaoda
- dev: pin the runtime entry file layout that Vite serves (#10983) by @h-a-n-a

### ⚙️ Miscellaneous Tasks

- pin VOID_API_URL for the docs deploy (#11041) by @shulaoda
- opt into the WebContainer smoke test for napi bumps and loader changes (#10967) by @shulaoda
- deps: upgrade oxc to 0.152.0 (#11018) by @camc314
- deps: update rust crates (#11012) by @renovate[bot]
- deps: update npm packages (#11011) by @renovate[bot]
- deps: update crate-ci/typos action to v1.50.3 (#11023) by @renovate[bot]
- deps: update test262 submodule for tests (#11022) by @rolldown-guard[bot]
- deps: update rollup submodule for tests to v4.63.5 (#11021) by @rolldown-guard[bot]
- deps: update dependency vite-plus to v1 (#11017) by @renovate[bot]
- deps: update github actions (#11010) by @renovate[bot]
- remove `CLAUDE.md` (#10925) by @iiio2
- verify release debug info by matching file IDs (#10988) by @IWANABETHATGUY
- deps: update rollup submodule for tests to v4.63.4 (#10940) by @rolldown-guard[bot]

### ❤️ New Contributors

* @waltuov made their first contribution in [#10986](#10986)
* @linyiru made their first contribution in [#11014](#11014)
* @sep2 made their first contribution in [#10992](#10992)

Co-authored-by: shulaoda <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants