Skip to content

feat: tree shaking nested exports for destructuring assignment#19955

Merged
alexander-akait merged 3 commits intowebpack:mainfrom
ahabhgk:feat-deep-tree-shaking-for-destructuring
Sep 29, 2025
Merged

feat: tree shaking nested exports for destructuring assignment#19955
alexander-akait merged 3 commits intowebpack:mainfrom
ahabhgk:feat-deep-tree-shaking-for-destructuring

Conversation

@ahabhgk
Copy link
Contributor

@ahabhgk ahabhgk commented Sep 28, 2025

Summary

After #19811 we can collect the nested properties in destructuring assignment, so this PR add it and use it to enhance tree shaking for nested exports

// lib.js
export * as a from "./a";
export * as b from "./b";

// index.js
import * as lib from "./lib";
// before the referenced exports is "lib.a", only "lib.b" is tree-shaken, and everything inside "lib.a" is kept
// now the referenced exports is "lib.a.inner", only "lib.a.inner" is kept, everything else is tree-shaken
const { a: { inner } } = lib;

What kind of change does this PR introduce?

feature

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?

Nothing

@codspeed-hq
Copy link

codspeed-hq bot commented Sep 28, 2025

CodSpeed Performance Report

Merging #19955 will degrade performances by 48.07%

Comparing ahabhgk:feat-deep-tree-shaking-for-destructuring (c4436c8) with main (d9121b3)

Summary

⚡ 4 improvements
❌ 2 regressions
✅ 36 untouched

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

Benchmarks breakdown

Benchmark BASE HEAD Change
benchmark "devtool-eval", scenario '{"name":"mode-development","mode":"development"}' 335.8 ms 265.5 ms +26.46%
benchmark "devtool-eval", scenario '{"name":"mode-development-rebuild","mode":"development","watch":true}' 84.3 ms 44.9 ms +87.65%
benchmark "devtool-eval-source-map", scenario '{"name":"mode-development-rebuild","mode":"development","watch":true}' 73.4 ms 112.5 ms -34.73%
benchmark "devtool-source-map", scenario '{"name":"mode-development-rebuild","mode":"development","watch":true}' 45.3 ms 87.2 ms -48.07%
benchmark "future-defaults", scenario '{"name":"mode-development-rebuild","mode":"development","watch":true}' 132.1 ms 89.1 ms +48.24%
benchmark "lodash", scenario '{"name":"mode-development-rebuild","mode":"development","watch":true}' 86.9 ms 68.1 ms +27.66%

@alexander-akait alexander-akait merged commit 8c0fa9e into webpack:main Sep 29, 2025
19 of 24 checks passed
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.

2 participants