feat: skip dead dependencies guarded by inlined constants#21136
Conversation
🦋 Changeset detectedLatest commit: a68f3af The changes in this PR will be included in the next version bump. This PR includes changesets to release 1 package
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
|
This PR is packaged and the instant preview is available (30b18a6). Install it locally:
npm i -D webpack@https://pkg.pr.new/webpack@30b18a6
yarn add -D webpack@https://pkg.pr.new/webpack@30b18a6
pnpm add -D webpack@https://pkg.pr.new/webpack@30b18a6 |
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #21136 +/- ##
========================================
Coverage 92.36% 92.36%
========================================
Files 581 581
Lines 63411 63543 +132
Branches 17544 17604 +60
========================================
+ Hits 58567 58689 +122
- Misses 4844 4854 +10
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
Merging this PR will not alter performance
|
| Mode | Benchmark | BASE |
HEAD |
Efficiency | |
|---|---|---|---|---|---|
| ❌ | Memory | benchmark "asset-modules-inline", scenario '{"name":"mode-development-rebuild","mode":"development","watch":true}' |
325.9 KB | 1,292.4 KB | -74.79% |
| ❌ | Memory | benchmark "many-modules-commonjs", scenario '{"name":"mode-development","mode":"development"}' |
922 KB | 1,836 KB | -49.78% |
| ❌ | Memory | benchmark "many-chunks-commonjs", scenario '{"name":"mode-production","mode":"production"}' |
6.9 MB | 10.1 MB | -31.58% |
| ⚡ | Memory | benchmark "lodash", scenario '{"name":"mode-development-rebuild","mode":"development","watch":true}' |
858.9 KB | 127.4 KB | ×6.7 |
| ⚡ | Memory | benchmark "side-effects-reexport", scenario '{"name":"mode-development-rebuild","mode":"development","watch":true}' |
1,194.7 KB | 753.4 KB | +58.58% |
| ⚡ | Memory | benchmark "many-chunks-esm", scenario '{"name":"mode-production","mode":"production"}' |
9.2 MB | 7.3 MB | +25.53% |
Tip
Investigate this regression by commenting @codspeedbot fix this regression on this PR, or directly use the CodSpeed MCP with your agent.
Comparing dead-branch-by-inlined (a68f3af) with main (bbb8c3f)
|
@hai-x Looks good, feel free to fix test and ping me when it will be ready |
|
@alexander-akait Thanks. It's almost ready, but it still needs a bit of polishing. |
5e5ebba to
54fd896
Compare
|
@alexander-akait Done now. |
54fd896 to
a68f3af
Compare
Summary
What kind of change does this PR introduce?
The ESM/CJS import dependenies used only in a provably-dead conditional branch are not tree-shaken when the branch is selected by an imported constant.
ConstPluginhandles this for same-module constants, but a cross-module constant's value is unknown at parse time, sowebpackonly had to keeps both branches — pulling dead modules into the bundle.so today both
./module_aand./module_bare emitted, even thoughisDEVis a staticallyfalseandDEP_Acan never be reached. And this PR will improve those cases.Did you add tests for your changes?
Yes
Does this PR introduce a breaking change?
No
If relevant, what needs to be documented once your changes are merged or what have you already documented?
No
Use of AI
Partial