Skip to content

fix(mcs): entriesAware should calculate sizes without duplication#8887

Merged
graphite-app[bot] merged 1 commit intomainfrom
03-24-fix_mcs_entriesaware_should_calculate_sizes_without_duplication
Mar 24, 2026
Merged

fix(mcs): entriesAware should calculate sizes without duplication#8887
graphite-app[bot] merged 1 commit intomainfrom
03-24-fix_mcs_entriesaware_should_calculate_sizes_without_duplication

Conversation

@hyf0
Copy link
Copy Markdown
Member

@hyf0 hyf0 commented Mar 24, 2026

Summary

  • Fix: entriesAware subgroups no longer have duplicated shared dependencies, which inflated sizes and broke entriesAwareMergeThreshold comparisons
  • Refactor: module_groups uses IndexVec for regular groups; entries-aware groups stay in a Vec for flexible post-processing (split by bitset, merge, then push into IndexVec)
  • New test: entries_aware_merge_shared_deps — fails on main (shared deps duplicated → inflated sizes → no merge), passes after fix
  • Design doc: meta/design/manual-code-splitting.md — visual explanation of entriesAware flow

The bug

On main, ModuleGroupId includes each module's own bitset, creating separate subgroups during build. With includeDependenciesRecursively, shared dependencies get added to each subgroup independently:

lib-a.js (bits={A}) → subgroup {A}, deps add shared-dep.js
lib-b.js (bits={B}) → subgroup {B}, deps add shared-dep.js  ← DUPLICATE

subgroup {A} = [lib-a, shared-dep]  size: 150  (inflated)
subgroup {B} = [lib-b, shared-dep]  size: 150  (inflated)

Inflated sizes cause entriesAwareMergeThreshold to skip merges that should happen.

The fix

Build entries-aware groups as a flat group first, then split by bitset as post-processing. Each module appears in exactly one subgroup based on its own bits:

flat group = [lib-a, lib-b, shared-dep]

split by bits:
  {A}     → [lib-a]       size: 30   ← correct
  {B}     → [lib-b]       size: 30   ← correct
  {A, B}  → [shared-dep]  size: 100  ← counted once

Test plan

  • cargo test -p rolldown -- entries_aware (5 tests pass)
  • cargo test -p rolldown -- advanced_chunks (25 tests pass)
  • New test entries_aware_merge_shared_deps fails on main, passes on this branch

🤖 Generated with Claude Code

Copy link
Copy Markdown
Member Author

hyf0 commented Mar 24, 2026


How to use the Graphite Merge Queue

Add the label graphite: merge-when-ready to this PR to add it to the merge queue.

You must have a Graphite account in order to use the merge queue. Sign up using this link.

An organization admin has enabled the Graphite Merge Queue in this repository.

Please do not merge from GitHub as this will restart CI on PRs being processed by the merge queue.

This stack of pull requests is managed by Graphite. Learn more about stacking.

@hyf0 hyf0 marked this pull request as ready for review March 24, 2026 06:41
Copilot AI review requested due to automatic review settings March 24, 2026 06:41
@hyf0 hyf0 changed the base branch from 03-21-feat_chunk-optimizer_skip_circular_dependency_check_when_strict_execution_order_is_enabled to graphite-base/8887 March 24, 2026 06:42
@hyf0 hyf0 force-pushed the graphite-base/8887 branch from abe4f5b to efad975 Compare March 24, 2026 06:43
@hyf0 hyf0 force-pushed the 03-24-fix_mcs_entriesaware_should_calculate_sizes_without_duplication branch from 5ea0f64 to 071d65a Compare March 24, 2026 06:43
@hyf0 hyf0 changed the base branch from graphite-base/8887 to main March 24, 2026 06:43
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR fixes manualCodeSplitting.groups[].entriesAware size calculation so shared dependencies aren’t double-counted across per-entry subgroups, which previously caused incorrect entriesAwareMergeThreshold decisions.

Changes:

  • Refactors manual code splitting to collect a flat entriesAware group first, then split into bitset-based subgroups and merge small subgroups by threshold.
  • Adds an integration test fixture + snapshot ensuring shared deps don’t inflate subgroup sizes and incorrectly prevent merging.
  • Adds a design doc explaining entriesAware, why “flat-then-split” matters, and how subgroup merging works.

Reviewed changes

Copilot reviewed 10 out of 10 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
crates/rolldown/src/stages/generate_stage/manual_code_splitting.rs Implements flat collection for entriesAware, post-split subgroup sizing, and updated merge flow.
crates/rolldown/tests/rolldown/function/advanced_chunks/entries_aware_merge_shared_deps/_config.json New regression test configuration for the shared-deps + merge-threshold scenario.
crates/rolldown/tests/rolldown/function/advanced_chunks/entries_aware_merge_shared_deps/_test.mjs Asserts no per-entry vendor chunks are produced when subgroups should merge.
crates/rolldown/tests/rolldown/function/advanced_chunks/entries_aware_merge_shared_deps/artifacts.snap Snapshot validating the expected chunk layout/output.
crates/rolldown/tests/rolldown/function/advanced_chunks/entries_aware_merge_shared_deps/{entry-a.js,entry-b.js,lib-a.js,lib-b.js,shared-dep.js} Test fixture modules used to reproduce the duplication/inflated-size bug.
meta/design/manual-code-splitting.md New documentation describing entriesAware mechanics and merge behavior.

@codspeed-hq
Copy link
Copy Markdown

codspeed-hq bot commented Mar 24, 2026

Merging this PR will not alter performance

✅ 4 untouched benchmarks
⏩ 10 skipped benchmarks1


Comparing 03-24-fix_mcs_entriesaware_should_calculate_sizes_without_duplication (54e2cba) with main (efad975)

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.

@hyf0 hyf0 force-pushed the 03-24-fix_mcs_entriesaware_should_calculate_sizes_without_duplication branch from 071d65a to 60ca9c0 Compare March 24, 2026 07:02
@netlify
Copy link
Copy Markdown

netlify bot commented Mar 24, 2026

Deploy Preview for rolldown-rs canceled.

Name Link
🔨 Latest commit 7833704
🔍 Latest deploy log https://app.netlify.com/projects/rolldown-rs/deploys/69c2484e2a4f1a000800bc90

Copy link
Copy Markdown
Member Author

hyf0 commented Mar 24, 2026

Merge activity

…8887)

## Summary

- **Fix**: `entriesAware` subgroups no longer have duplicated shared dependencies, which inflated sizes and broke `entriesAwareMergeThreshold` comparisons
- **Refactor**: `module_groups` uses `IndexVec` for regular groups; entries-aware groups stay in a `Vec` for flexible post-processing (split by bitset, merge, then push into IndexVec)
- **New test**: `entries_aware_merge_shared_deps` — fails on `main` (shared deps duplicated → inflated sizes → no merge), passes after fix
- **Design doc**: `meta/design/manual-code-splitting.md` — visual explanation of `entriesAware` flow

## The bug

On `main`, `ModuleGroupId` includes each module's own bitset, creating separate subgroups during build. With `includeDependenciesRecursively`, shared dependencies get added to **each** subgroup independently:

```
lib-a.js (bits={A}) → subgroup {A}, deps add shared-dep.js
lib-b.js (bits={B}) → subgroup {B}, deps add shared-dep.js  ← DUPLICATE

subgroup {A} = [lib-a, shared-dep]  size: 150  (inflated)
subgroup {B} = [lib-b, shared-dep]  size: 150  (inflated)
```

Inflated sizes cause `entriesAwareMergeThreshold` to skip merges that should happen.

## The fix

Build entries-aware groups as a **flat group first**, then split by bitset as post-processing. Each module appears in exactly one subgroup based on its own bits:

```
flat group = [lib-a, lib-b, shared-dep]

split by bits:
  {A}     → [lib-a]       size: 30   ← correct
  {B}     → [lib-b]       size: 30   ← correct
  {A, B}  → [shared-dep]  size: 100  ← counted once
```

## Test plan

- [x] `cargo test -p rolldown -- entries_aware` (5 tests pass)
- [x] `cargo test -p rolldown -- advanced_chunks` (25 tests pass)
- [x] New test `entries_aware_merge_shared_deps` fails on `main`, passes on this branch

🤖 Generated with [Claude Code](https://claude.com/claude-code)
@graphite-app graphite-app bot force-pushed the 03-24-fix_mcs_entriesaware_should_calculate_sizes_without_duplication branch from 54e2cba to 7833704 Compare March 24, 2026 08:16
@graphite-app graphite-app bot merged commit 7833704 into main Mar 24, 2026
31 checks passed
@graphite-app graphite-app bot deleted the 03-24-fix_mcs_entriesaware_should_calculate_sizes_without_duplication branch March 24, 2026 08:20
This was referenced Mar 25, 2026
shulaoda added a commit that referenced this pull request Mar 25, 2026
## [1.0.0-rc.12] - 2026-03-25

### 🚀 Features

- chunk-optimizer: skip circular dependency check when strict execution order is enabled (#8886) by @hyf0

### 🐛 Bug Fixes

- emit build warnings during watch mode rebuilds (#8897) by @IWANABETHATGUY
- lazy-barrel: load import-then-export specifiers when barrel has local exports (#8895) by @shulaoda
- correct execution order of transferred CJS init calls (#8877) by @IWANABETHATGUY
- mcs: `entriesAware` should calculate sizes without duplication (#8887) by @hyf0
- non-deterministic chunk generation (#8882) by @sapphi-red
- `is_top_level` incorrectly treats strict-mode scopes as top-level (#8878) by @Dunqing

### 🚜 Refactor

- treeshake: migrate SideEffectDetector to Oxc's MayHaveSideEffects trait (#8624) by @Dunqing

### 🧪 Testing

- make dev server tests deterministic by replacing fixed sleeps with event-driven polling (#8561) by @Boshen

### ⚙️ Miscellaneous Tasks

- deps: update dependency vite-plus to v0.1.14 (#8902) by @camc314
- deps: update dependency oxfmt to ^0.42.0 (#8891) by @renovate[bot]
- deps: update rust crate oxc_sourcemap to v6.1.1 (#8890) by @renovate[bot]
- remove Rolldown MF plan (#8883) by @shulaoda
- deps: update rollup submodule for tests to v4.60.0 (#8881) by @sapphi-red
- deps: update test262 submodule for tests (#8880) by @sapphi-red
- deps: upgrade oxc crates to 0.122.0 (#8879) by @shulaoda

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.

4 participants