Skip to content

Commit 5cfa879

Browse files
committed
perf: precompile AliasPlugin options to speed up huge alias lists
Hoists per-option strings (nameWithSlash, absolutePath, wildcardPrefix/Suffix) out of the hot AliasPlugin scan into AliasUtils#compileAliasOptions, invoked once per resolver in AliasPlugin#apply (and in TsconfigPathsPlugin when a paths map is built). The per-resolve loop then runs with no string concat, no name.split("*"), and no resolver.join per unmatched entry - the cost that dominated projects with hundreds of webpack aliases (see #438). Adds two benchmark cases covering the monorepo-scale scenario: - huge-alias-list: 300 non-matching + 8 matching aliases, match near end - huge-alias-miss: 300 aliases + requests that never match any Local wall-clock numbers (Node 22, tinybench): before after delta huge-alias-list 225 ops 405 ops +80% huge-alias-miss 453 ops 893 ops +97% large-alias-list 653 ops 856 ops +31% https://claude.ai/code/session_01ERSdt7j3dKwd9MxNbuuXnm
1 parent b5259a0 commit 5cfa879

23 files changed

Lines changed: 256 additions & 38 deletions

File tree

benchmark/README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,8 @@ export default function register(bench, { caseName, caseDir, fixtureDir }) {
101101
| `failed-resolution` | Error path: missing files and packages, walks the full pipeline before reporting the miss |
102102
| `concurrent-batch` | 15 resolves through `Promise.all`, exercising in-flight request de-duplication |
103103
| `large-alias-list` | 50 non-matching + 8 matching aliases, stresses AliasPlugin's linear scan |
104+
| `huge-alias-list` | 300 non-matching + 8 matching aliases, match near end — monorepo-scale AliasPlugin scan |
105+
| `huge-alias-miss` | 300 aliases + requests that never match any — pure per-option overhead, no `doResolve` recursion |
104106
| `multiple-modules` | `modules: [shared, vendor, node_modules]` mix of root + hierarchical directories |
105107
| `mixed-conditions` | Nested condition map (browser/worker/node/development/production/...) under 4 condition configurations |
106108
| `exports-patterns-many` | Package with 6 wildcard subpath exports × 4 leaves per prefix — pattern-matcher stress |
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
{"name":"huge-alias-list-fixture","version":"1.0.0"}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
module.exports = {};
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
module.exports = {};
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
module.exports = {};
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
module.exports = {};
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
module.exports = {};
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
module.exports = {};
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
module.exports = {};
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
module.exports = {};

0 commit comments

Comments
 (0)