Skip to content

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

Merged
graphite-app[bot] merged 1 commit intomainfrom
03-21-feat_chunk-optimizer_skip_circular_dependency_check_when_strict_execution_order_is_enabled
Mar 25, 2026
Merged

feat(chunk-optimizer): skip circular dependency check when strict execution order is enabled#8886
graphite-app[bot] merged 1 commit intomainfrom
03-21-feat_chunk-optimizer_skip_circular_dependency_check_when_strict_execution_order_is_enabled

Conversation

@hyf0
Copy link
Copy Markdown
Member

@hyf0 hyf0 commented Mar 24, 2026

Summary

When strictExecutionOrder is enabled, rolldown wraps modules in init_() functions that guard execution order at runtime. This means circular chunk dependencies are safe — the wrappers ensure correct initialization regardless of load order.

Currently, the chunk optimizer conservatively skips merging chunks that would create circular dependencies. This PR skips that circular dependency check when strictExecutionOrder is enabled, allowing more aggressive chunk merging and producing fewer output chunks.

Changes

  • Wrap the circular dependency check in chunk_optimizer.rs with !self.options.is_strict_execution_order_enabled(), so it is bypassed when strict execution order is active.

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

@netlify
Copy link
Copy Markdown

netlify bot commented Mar 24, 2026

Deploy Preview for rolldown-rs canceled.

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

@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
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 updates the generate-stage chunk optimizer to bypass the “would this merge create a circular chunk dependency?” safeguard when strictExecutionOrder is enabled, based on the assumption that init_*() wrappers make such cycles safe.

Changes:

  • Skip the circular chunk dependency check during facade-chunk merge-op discovery when strictExecutionOrder is enabled.
  • Keep the existing circular-dependency prevention behavior unchanged when strictExecutionOrder is not enabled.

@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-21-feat_chunk-optimizer_skip_circular_dependency_check_when_strict_execution_order_is_enabled (a6ee216) with main (11fe4fe)

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 marked this pull request as draft March 24, 2026 07:12
@hyf0 hyf0 requested a review from Copilot March 24, 2026 07:35
@hyf0 hyf0 marked this pull request as ready for review March 24, 2026 07:37
@hyf0 hyf0 requested a review from IWANABETHATGUY March 24, 2026 07:37
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

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

Copy link
Copy Markdown
Member Author

hyf0 commented Mar 25, 2026

Merge activity

…cution order is enabled (#8886)

## Summary

When `strictExecutionOrder` is enabled, rolldown wraps modules in `init_()` functions that guard execution order at runtime. This means circular chunk dependencies are safe — the wrappers ensure correct initialization regardless of load order.

Currently, the chunk optimizer conservatively skips merging chunks that would create circular dependencies. This PR skips that circular dependency check when `strictExecutionOrder` is enabled, allowing more aggressive chunk merging and producing fewer output chunks.

## Changes

- Wrap the circular dependency check in `chunk_optimizer.rs` with `!self.options.is_strict_execution_order_enabled()`, so it is bypassed when strict execution order is active.

🤖 Generated with [Claude Code](https://claude.com/claude-code)
@graphite-app graphite-app bot force-pushed the 03-21-feat_chunk-optimizer_skip_circular_dependency_check_when_strict_execution_order_is_enabled branch from a6ee216 to 1226947 Compare March 25, 2026 01:50
@graphite-app graphite-app bot merged commit 1226947 into main Mar 25, 2026
30 of 31 checks passed
@graphite-app graphite-app bot deleted the 03-21-feat_chunk-optimizer_skip_circular_dependency_check_when_strict_execution_order_is_enabled branch March 25, 2026 01:54
@github-actions github-actions bot mentioned this pull request 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]>
AlonMiz pushed a commit to AlonMiz/rolldown that referenced this pull request Mar 30, 2026
…mizer

The circular dependency check added by rolldown#8371 was correct for chunks
containing the runtime module or runtime-dependent modules (e.g.,
__commonJSMin, __toESM), but overly conservative for regular ESM chunks.

ESM handles circular imports fine — modules are initialized lazily and
circular references are resolved at access time. Only runtime helpers
need to be available synchronously before the importing module executes,
making circular chunk imports harmful only when runtime is involved.

This fix scopes the circular dependency check to only apply when the
source chunk contains:
1. The runtime module itself, OR
2. Modules that depend on runtime helpers (depended_runtime_helper)

For all other pure ESM chunks, the merge is allowed regardless of
whether it would create circular chunk imports.

In large applications, this was causing +53% more JS files and +8%
bundle size because the cycle detection blocked almost all common
chunk merges.

Closes rolldown#8371 regression
Refs: rolldown#8361, rolldown#8886, rolldown#8910, rolldown#8915
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