Skip to content

fix: tree-shaking unused RawModule#19671

Merged
alexander-akait merged 5 commits intowebpack:mainfrom
colinaaa:colin/0709/raw-module
Jul 10, 2025
Merged

fix: tree-shaking unused RawModule#19671
alexander-akait merged 5 commits intowebpack:mainfrom
colinaaa:colin/0709/raw-module

Conversation

@colinaaa
Copy link
Contributor

@colinaaa colinaaa commented Jul 8, 2025

close: #19670

What kind of change does this PR introduce?

a bugfix

Did you add tests for your changes?

Yes

Does this PR introduce a breaking change?

No

What needs to be documented once your changes are merged?

Nothing

@colinaaa colinaaa marked this pull request as draft July 8, 2025 17:18
*/
getSideEffectsConnectionState(moduleGraph) {
return false;
}
Copy link
Member

Choose a reason for hiding this comment

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

That is wrong, raw module is just a raw and can have side effects

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It looks like all the RawModules generated by webpack appear to lack meaningful content, either /* (ignored) */ or being completely empty.

Do you mean that the class RawModule has been exported and could be used by plugins?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Oh, I see. It should be determined by the source parameter.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I've made a patch to read from this.factoryMeta.sideEffectFree. PTAL~

@codspeed-hq
Copy link

codspeed-hq bot commented Jul 8, 2025

CodSpeed Performance Report

Merging #19671 will degrade performances by 72.85%

Comparing colinaaa:colin/0709/raw-module (dd24db4) with main (24b1ec7)

Summary

⚡ 5 improvements
❌ 81 regressions
✅ 47 untouched benchmarks

⚠️ Please fix the performance issues or acknowledge them on CodSpeed.

Benchmarks breakdown

Benchmark BASE HEAD Change
benchmark "devtool-eval", scenario '{"name":"mode-development-rebuild","mode":"development","watch":true}' 43 ms 12.1 ms ×3.6
benchmark "devtool-eval-source-map", scenario '{"name":"mode-development-rebuild","mode":"development","watch":true}' 41.9 ms 34.6 ms +21.27%
benchmark "devtool-source-map", scenario '{"name":"mode-development-rebuild","mode":"development","watch":true}' 11.7 ms 43 ms -72.85%
benchmark "future-defaults", scenario '{"name":"mode-development-rebuild","mode":"development","watch":true}' 52.6 ms 61.9 ms -15.02%
benchmark "lodash", scenario '{"name":"mode-development-rebuild","mode":"development","watch":true}' 45.7 ms 33.8 ms +35.14%
benchmark "many-chunks-commonjs", scenario '{"name":"mode-development-rebuild","mode":"development","watch":true}' 62.2 ms 9.9 ms ×6.3
benchmark "many-modules-esm", scenario '{"name":"mode-development-rebuild","mode":"development","watch":true}' 45.8 ms 11.2 ms ×4.1
benchmark "minimal", scenario '{"name":"mode-development","mode":"development"}' 24.2 ms 30.4 ms -20.31%
md4 buffer benchmark (size: 10000) 73 µs 114.4 µs -36.16%
md4 buffer benchmark (size: 120) 35 µs 76.2 µs -54.11%
md4 buffer benchmark (size: 160) 35 µs 76.3 µs -54.15%
md4 buffer benchmark (size: 16366) 97.5 µs 138.8 µs -29.79%
md4 buffer benchmark (size: 16368) 97.5 µs 138.8 µs -29.76%
md4 buffer benchmark (size: 16370) 97.5 µs 139 µs -29.86%
md4 buffer benchmark (size: 2) 35 µs 76.6 µs -54.32%
md4 buffer benchmark (size: 20) 32.6 µs 76.6 µs -57.42%
md4 buffer benchmark (size: 200) 35.3 µs 76.6 µs -53.93%
md4 buffer benchmark (size: 2000) 40.8 µs 82 µs -50.28%
md4 buffer benchmark (size: 20000) 111.6 µs 153 µs -27.03%
md4 buffer benchmark (size: 2002) 40.8 µs 82.2 µs -50.36%
... ... ... ... ...

ℹ️ Only the first 20 benchmarks are displayed. Go to the app to view all benchmarks.

@colinaaa colinaaa marked this pull request as ready for review July 8, 2025 18:15
@colinaaa colinaaa requested a review from alexander-akait July 9, 2025 03:10
lib/Module.js Outdated
if (this.factoryMeta !== undefined) {
if (this.factoryMeta.sideEffectFree) return false;
if (this.factoryMeta.sideEffectFree === false) return true;
}
Copy link
Member

Choose a reason for hiding this comment

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

Please put this login inside RawModule, otherwise it is potential breaking changes for plugins

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks! This make more sense

@alexander-akait alexander-akait merged commit 34df7ee into webpack:main Jul 10, 2025
41 of 44 checks passed
ahabhgk pushed a commit to web-infra-dev/rspack that referenced this pull request Jul 11, 2025
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.

Should delete unused ignored module (RawModule)

2 participants