Skip to content

fix(rolldown): remove empty common chunks for advanced chunking#9550

Open
aminpaks wants to merge 2 commits into
rolldown:mainfrom
aminpaks:amin--fix-empty-barrel-chunks
Open

fix(rolldown): remove empty common chunks for advanced chunking#9550
aminpaks wants to merge 2 commits into
rolldown:mainfrom
aminpaks:amin--fix-empty-barrel-chunks

Conversation

@aminpaks

@aminpaks aminpaks commented May 25, 2026

Copy link
Copy Markdown
Contributor

Manual/advanced chunking could leave a barrel module in its own common chunk after its re-export declarations resolved to symbols in other chunks. The chunk rendered as an empty JS file, but entry chunks still imported it.

This adds an empty-common-chunk optimization that removes only graph-proven ESM re-export facades. Before marking the chunk removed, the optimizer retargets importers to any live side-effectful dependencies forwarded through the removed chunk, so load-order side effects are preserved without source-string re-export detection.

Related: #8625 is an earlier attempt at the same #6677 issue. This PR takes a graph-level approach so chunk removal can stay conservative around side effects, dynamic imports, runtime helpers, CJS wrappers, externals, and CSS-owning modules.

Fixes #6677.

Disclosure: AI tools assisted with investigation and implementation. I reviewed, tested, and take responsibility for the submitted changes.

@aminpaks aminpaks force-pushed the amin--fix-empty-barrel-chunks branch 7 times, most recently from 083b89f to d3b7bd1 Compare May 25, 2026 19:37
aminpaks added 2 commits May 25, 2026 16:15
Add graph-level empty common chunk elimination for advanced chunking.\n\n- Remove only non-entry common JS/TS chunks made entirely of metadata-confirmed re-export barrels.\n- Preserve chunks that import CSS so asset/hash ownership stays intact.\n- Retarget importer chunks to any side-effect chunks those barrels forwarded.\n- Treat no-replacement pure barrels as renderless unassigned modules in downstream passes.\n- Document the optimizer boundary.
Add rolldown#6677 regression coverage separately from the implementation.\n\n- Cover empty common chunk removal for side-effect and pure-barrel cases.\n- Keep barrels emitted when they are dynamic import targets.\n- Keep chunks that anchor external imports, CommonJS wrappers, or runtime-helper state.\n- Snapshot output so future guard changes cannot silently delete unsafe chunks.
@aminpaks aminpaks force-pushed the amin--fix-empty-barrel-chunks branch from d3b7bd1 to 3b34d12 Compare May 25, 2026 20:16
@aminpaks aminpaks marked this pull request as ready for review May 26, 2026 09:48
@codspeed-hq

codspeed-hq Bot commented May 26, 2026

Copy link
Copy Markdown

Merging this PR will not alter performance

✅ 4 untouched benchmarks
⏩ 10 skipped benchmarks1


Comparing aminpaks:amin--fix-empty-barrel-chunks (3b34d12) with main (df616cb)2

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.

  2. No successful run was found on main (406be5e) during the generation of this report, so df616cb was used instead as the comparison base. There might be some changes unrelated to this pull request in this report.

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.

empty chunk generated and imported when using advancedChunks

1 participant