Skip to content

feat(inline-common-chunks): deduplicate shared code along known loading paths - #11093

Merged
graphite-app[bot] merged 1 commit into
mainfrom
fix/inline-common-chunks-loading-paths
Oct 7, 2026
Merged

graphite-app[bot] merged 1 commit into
mainfrom
fix/inline-common-chunks-loading-paths

Conversation

@hyfdev

@hyfdev hyfdev commented Oct 4, 2026 •

Copy link
Copy Markdown
Member

With experimentalInlineCommonChunks enabled, an unrelated runtime import(url) can keep duplicate shared code in lazy chunks whose known parents already provide it. This change lets those chunks reuse the parent's registered copy.

For example, a.js and b.js are independent entries:

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

// lazy.js
import { state } from './shared.js';
export const value = state;

// b.js
globalThis.loadPlugin = (url) => import(url);

When shared code is selected for inlining, a.js registers its factory. The generated lazy.js also registers a copy before reading it (simplified):

__share("shared", (exports) => { /* shared code */ });
const shared = __share_require("shared");

With this change, lazy.js uses the existing registration:

const shared = __share_require("shared");

A factory is omitted only when every resolved loading path from the configured and plugin-emitted entries provides it. Unresolved and ignored imports remain native; their unknown targets do not add parents to the internal chunk graph.

Loading a non-entry output chunk by URL through an unresolved import or external module is outside the supported loading paths, as are static cycles through external modules back into generated output. Modules intended for independent URL loading can be emitted as entries with preserveSignature: 'strict'. Modules forming external cycles can be bundled together, or their shared dependencies excluded from inlining.

Shared code is named as part of the emitted files that contain it, avoiding a separate naming pass for chunks emitted only through their copies.

Benchmark: automatic splitting, no manual groups

Base ce90f203 → PR 9b11615f.

Complete client build

Inline maxSize Total JS files Common chunks Base gzip MiB PR gzip MiB Reduction
Off 4,771 2,229 35.067 35.067 0%
5 KiB 3,390 848 36.517 35.555 2.63%
10 KiB 3,150 608 38.181 36.120 5.40%
20 KiB 2,951 409 41.913 37.490 10.55%
50 KiB 2,795 253 52.009 41.443 20.32%
100 KiB 2,718 176 60.738 44.777 26.28%
1 MiB 2,615 73 252.169 87.424 65.33%

Three-page session

Cold start, then same-document navigation with cache retained. Preloads included; separately hosted third-party JS excluded.

Inline maxSize Downloaded JS files, base and PR Base gzip MiB PR gzip MiB Reduction
100 KiB 245 13.514 12.560 7.06%
1 MiB 165 34.566 31.589 8.61%

@netlify

netlify Bot commented Oct 4, 2026 •

Copy link
Copy Markdown

✅ Deploy Preview for rolldown-rs ready!

Name Link
🔨 Latest commit f918ebb
🔍 Latest deploy log https://app.netlify.com/projects/rolldown-rs/deploys/6ac5c2adfe275f00083a2eaa
😎 Deploy Preview https://deploy-preview-11093--rolldown-rs.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.
🤖 Make changes Run an agent on this branch

To edit notification comments on pull requests, go to your Netlify project configuration.

@cloudflare-workers-and-pages

cloudflare-workers-and-pages Bot commented Oct 4, 2026 •

Copy link
Copy Markdown

🚀 Deploying Preview to Cloudflare 🚀

Preview URL: https://fix-inline-common-chunks-loading-paths-rolldown-rs.voidzero-docs.workers.dev (commit f918ebb)

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://e5705841-rolldown-rs.voidzero-docs.workers.dev f918ebb 2026-10-07T03:57:20.488Z Visit the dashboard ↗
  • Build: Success ✅
  • Deployment: Success ✅

View logs ↗
https://bc1356a2-rolldown-rs.voidzero-docs.workers.dev 9b11615 2026-10-05T16:58:09.031Z Visit the dashboard ↗
  • Build: Success ✅
  • Deployment: Success ✅

View logs ↗
https://7f174714-rolldown-rs.voidzero-docs.workers.dev 37f84bf 2026-10-04T06:23:10.336Z Visit the dashboard ↗

@hyfdev hyfdev changed the title perf(inline-common-chunks): deduplicate shared code along known loading paths feat(inline-common-chunks): deduplicate shared code along known loading paths Oct 4, 2026
@hyfdev
hyfdev force-pushed the fix/inline-common-chunks-loading-paths branch from 37f84bf to 9b11615 Compare October 5, 2026 16:55
@hyfdev
hyfdev marked this pull request as ready for review October 6, 2026 06:54
Copilot AI balanced review requested due to automatic review settings October 6, 2026 06:54

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

🔵 Needs a closer look

It changes core chunk-placement guarantees and intentionally narrows supported runtime loading paths, warranting final human validation.

Review effort: Balanced
Findings: None

What changed in this PR

Optimizes inline common chunks by reusing registrations from known entry loading paths while documenting unsupported runtime paths.

Changes:

  • Removes unresolved dynamic imports as inferred graph parents.
  • Skips unnecessary record-only deconfliction.
  • Adds behavioral tests and loading-path guidance.
File Description
packages/​rolldown/​tests/​behaviors/​inline-common-chunks/​inline-common-chunks.test.ts Tests known-parent reuse and public runtime-loaded modules.
packages/​rolldown/​src/​options/​output-options.ts Documents supported loading paths and mitigations.
internal-docs/​runtime-helpers/​implementation.md Clarifies unregistered runtime behavior.
internal-docs/​inline-common-chunks/​implementation.md Updates implementation details and invariants.
internal-docs/​inline-common-chunks/​design.md Defines the supported loading-path contract.
crates/​rolldown/​src/​stages/​generate_stage/​mod.rs Skips deconfliction for non-emitted records.
crates/​rolldown/​src/​stages/​generate_stage/​inline_common_chunks/​select.rs Removes untracked-import parent collection.
crates/​rolldown/​src/​stages/​generate_stage/​inline_common_chunks/​rewire.rs Uses resolved graph edges for placement.
crates/​rolldown/​src/​stages/​generate_stage/​inline_common_chunks/​place.rs Prunes copies using known dynamic parents only.
crates/​rolldown/​src/​stages/​generate_stage/​inline_common_chunks/​mod.rs Updates naming-state documentation.

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

@codspeed

codspeed Bot commented Oct 6, 2026

Copy link
Copy Markdown

Merging this PR will not alter performance

✅ 7 untouched benchmarks
⏩ 10 skipped benchmarks1


Comparing fix/inline-common-chunks-loading-paths (9b11615) with main (d0e7203)

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. ↩

shulaoda commented Oct 7, 2026 •

Copy link
Copy Markdown
Member

Merge activity

  • Oct 7, 3:54 AM UTC: The merge label 'graphite: merge-when-ready' was detected. This PR will be added to the Graphite merge queue once it meets the requirements.
  • Oct 7, 3:54 AM UTC: shulaoda added this pull request to the Graphite merge queue.
  • Oct 7, 3:59 AM UTC: Merged by the Graphite merge queue.

…ng paths (#11093)

With `experimentalInlineCommonChunks` enabled, an unrelated runtime `import(url)` can keep duplicate shared code in lazy chunks whose known parents already provide it. This change lets those chunks reuse the parent's registered copy.

For example, `a.js` and `b.js` are independent entries:

```js
// a.js
import { state } from './shared.js';
console.log(state);
globalThis.loadPage = () => import('./lazy.js');

// lazy.js
import { state } from './shared.js';
export const value = state;

// b.js
globalThis.loadPlugin = (url) => import(url);
```

When shared code is selected for inlining, `a.js` registers its factory. The generated `lazy.js` also registers a copy before reading it (simplified):

```js
__share("shared", (exports) => { /* shared code */ });
const shared = __share_require("shared");
```

With this change, `lazy.js` uses the existing registration:

```js
const shared = __share_require("shared");
```

A factory is omitted only when every resolved loading path from the configured and plugin-emitted entries provides it. Unresolved and ignored imports remain native; their unknown targets do not add parents to the internal chunk graph.

Loading a non-entry output chunk by URL through an unresolved import or external module is outside the supported loading paths, as are static cycles through external modules back into generated output. Modules intended for independent URL loading can be emitted as entries with `preserveSignature: 'strict'`. Modules forming external cycles can be bundled together, or their shared dependencies excluded from inlining.

Shared code is named as part of the emitted files that contain it, avoiding a separate naming pass for chunks emitted only through their copies.

## Benchmark: automatic splitting, no manual groups

Base `ce90f203` → PR `9b11615f`.

### Complete client build

| Inline maxSize | Total JS files | Common chunks | Base gzip MiB | PR gzip MiB | Reduction |
| --- | ---: | ---: | ---: | ---: | ---: |
| Off | 4,771 | 2,229 | 35.067 | 35.067 | 0% |
| 5 KiB | 3,390 | 848 | 36.517 | 35.555 | 2.63% |
| 10 KiB | 3,150 | 608 | 38.181 | 36.120 | 5.40% |
| 20 KiB | 2,951 | 409 | 41.913 | 37.490 | 10.55% |
| 50 KiB | 2,795 | 253 | 52.009 | 41.443 | 20.32% |
| 100 KiB | 2,718 | 176 | 60.738 | 44.777 | 26.28% |
| 1 MiB | 2,615 | 73 | 252.169 | 87.424 | 65.33% |

### Three-page session

Cold start, then same-document navigation with cache retained. Preloads included; separately hosted third-party JS excluded.

| Inline maxSize | Downloaded JS files, base and PR | Base gzip MiB | PR gzip MiB | Reduction |
| --- | ---: | ---: | ---: | ---: |
| 100 KiB | 245 | 13.514 | 12.560 | 7.06% |
| 1 MiB | 165 | 34.566 | 31.589 | 8.61% |
@graphite-app
graphite-app Bot force-pushed the fix/inline-common-chunks-loading-paths branch from 9b11615 to f918ebb Compare October 7, 2026 03:55
@graphite-app
graphite-app Bot merged commit f918ebb into main Oct 7, 2026
36 of 37 checks passed
@graphite-app
graphite-app Bot deleted the fix/inline-common-chunks-loading-paths branch October 7, 2026 03:59
@rolldown-guard rolldown-guard Bot mentioned this pull request Oct 7, 2026
shulaoda added a commit that referenced this pull request Oct 7, 2026
## [1.2.13] - 2026-10-07

### 🚀 Features

- rolldown_plugin_vite_import_glob: follow file creation and deletion via hotUpdate (#10550) by @shulaoda
- inline-common-chunks: deduplicate shared code along known loading paths (#11093) by @hyfdev
- rolldown_plugin_vite_import_glob: record a matcher per glob call in dev (#10592) by @shulaoda
- rolldown_plugin_vite_import_glob: watch the directory each glob reads (#10549) by @shulaoda
- watch: hand watch.exclude to notify as its ignore filter (#11008) by @shulaoda
- dev: add `experimental.devMode.hotUpdate` option (#11123) by @h-a-n-a

### 🐛 Bug Fixes

- renamer: check the printed name of namespace-alias imports for captures (#11129) by @IWANABETHATGUY
- devtools: honor `devtools.sessionId` by @Brooooooklyn
- renamer: keep a renamed nested binding off its module's top-level bindings (#11128) by @IWANABETHATGUY
- dev: keep `this` undefined when calling an imported function in HMR patches and lazy chunks (#11126) by @h-a-n-a
- dev: read string-named imports correctly in HMR patches and lazy chunks (#11127) by @h-a-n-a
- sanitize preserveModules chunk names after resolving the relative path (#11087) by @waltuov
- keep the `with` clause on bare external imports (#11100) by @IWANABETHATGUY
- generator: filter DISABLE_JS_HOOK bits from generated HookUsage (#10346) by @Brooooooklyn
- dev: make the module factory async for top-level await (#11118) by @h-a-n-a
- node: give each renderChunk call its own meta object (#11115) by @Brooooooklyn
- honor `externalLiveBindings` for imported exports (#11048) by @camc314
- dev: keep a late payload from replacing newer module code (#11030) by @h-a-n-a
- binding: use-after-free in async `transform` with a `TsconfigCache` (#11080) by @shulaoda
- fail on chunk syntax errors and escape export names once (#11051) by @hyfdev
- dev: ship newly imported modules the client never received (#11029) by @h-a-n-a
- code-splitting: avoid cycles from redundant re-export initialization (#11073) by @hyfdev
- link: treat re-exports of the same external binding as one export (#11069) by @IWANABETHATGUY
- escape namespace properties in IIFE and UMD output (#11085) by @hyfdev
- escape dependency paths in CJS and UMD output (#11084) by @hyfdev
- use computed access for arbitrary import names (#11083) by @hyfdev
- generate valid bindings for shimmed exports (#11082) by @hyfdev
- dev: reload the page when an HMR update fails after merging its edit (#11031) by @h-a-n-a
- dev/lazy: ship the deps of a module that a patch shipped but never ran (#11028) by @h-a-n-a
- code-splitting: don't move init calls in front of unwrapped JSON modules (#11062) by @IWANABETHATGUY
- escape export names in `defineProperty` calls (#11047) by @camc314

### 📚 Documentation

- say the CLI bundles multiple configs one after another (#11111) by @Brooooooklyn
- add `renderChunk` hook filter docs (#11065) by @sapphi-red

### ⚡ Performance

- use `concat_string!` instead of `format!` for plain string joins (#11139) by @IWANABETHATGUY
- utils: evaluate each `concat_string!` argument once (#11105) by @IWANABETHATGUY
- json: escape `JSON.parse` string with `json-escape-simd` (#11104) by @IWANABETHATGUY
- unwrap JSON modules with a non-object root (#11066) by @IWANABETHATGUY

### 🧪 Testing

- inline-common-chunks: fix flaky inlineCommonChunks concurrent imports (#11088) by @hyfdev

### ⚙️ Miscellaneous Tasks

- deps: upgrade oxc to 0.153.0 (#11109) by @camc314
- update pnpm to v12 (#10876) by @btea
- deps: update pnpm to v11.28.0 (#11049) by @renovate[bot]
- deps: update rollup submodule for tests to v4.64.0 (#11116) by @rolldown-guard[bot]
- deps: update napi (#11137) by @renovate[bot]
- scripts: spawn the rolldown CLI without a shell in setup-vite (#10875) by @Brooooooklyn
- deps: bump `@napi-rs/wasm-runtime` to `~1.2.5` (#11117) by @shulaoda
- deps: update napi (#11108) by @renovate[bot]
- deps: update taiki-e/install-action action to v2.87.22 (#11096) by @renovate[bot]
- deps: update npm packages (#11095) by @renovate[bot]
- deps: update rust crates (#11097) by @renovate[bot]
- deps: update napi (#11063) by @renovate[bot]
- deps: update dependency rust to v1.99.0 (#11071) by @renovate[bot]
- deps: update dependency vite-plus to v1 (#11056) by @renovate[bot]

Co-authored-by: shulaoda <[email protected]>

This branch was previously deployed

1 inactive deployment
void — f918ebbe Deployed Oct 7, 2026 by graphite-app[bot] via Deploy to Void #5622
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