Skip to content

perf: precompile AliasPlugin options to speed up huge alias lists#528

Merged
alexander-akait merged 2 commits intomainfrom
claude/benchmark-resolve-performance-JYrp7
Apr 17, 2026
Merged

perf: precompile AliasPlugin options to speed up huge alias lists#528
alexander-akait merged 2 commits intomainfrom
claude/benchmark-resolve-performance-JYrp7

Conversation

@alexander-akait
Copy link
Copy Markdown
Member

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

@linux-foundation-easycla
Copy link
Copy Markdown

linux-foundation-easycla bot commented Apr 16, 2026

CLA Not Signed

@changeset-bot
Copy link
Copy Markdown

changeset-bot bot commented Apr 16, 2026

⚠️ No Changeset found

Latest commit: 78744d1

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

@codecov
Copy link
Copy Markdown

codecov bot commented Apr 16, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 96.52%. Comparing base (68f8a15) to head (78744d1).
⚠️ Report is 1 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main     #528      +/-   ##
==========================================
+ Coverage   96.51%   96.52%   +0.01%     
==========================================
  Files          50       50              
  Lines        2640     2651      +11     
  Branches      806      808       +2     
==========================================
+ Hits         2548     2559      +11     
  Misses         77       77              
  Partials       15       15              
Flag Coverage Δ
integration 96.52% <100.00%> (+0.01%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@codspeed-hq
Copy link
Copy Markdown

codspeed-hq bot commented Apr 16, 2026

Merging this PR will improve performance by 22.23%

⚡ 4 improved benchmarks
✅ 52 untouched benchmarks
🆕 2 new benchmarks

Performance Changes

Benchmark BASE HEAD Efficiency
alias-wildcard-scan: 100+1 wildcard + 1 exact 3.9 ms 3.5 ms +12.32%
pathological-deep-stack: alias chain of 50 (warm) 19.1 ms 17.3 ms +10.45%
large-alias-list: 50+8 aliases, match near end 2.2 ms 2 ms +11.24%
🆕 huge-alias-list: 300+8 aliases, match near end N/A 4 ms N/A
🆕 huge-alias-miss: 300 aliases, no match N/A 2.6 ms N/A
stack-churn: 4x60 alias chains, 20 resolves 104.1 ms 85.1 ms +22.23%

Comparing claude/benchmark-resolve-performance-JYrp7 (78744d1) with main (68f8a15)

Open in CodSpeed

@alexander-akait alexander-akait force-pushed the claude/benchmark-resolve-performance-JYrp7 branch from fd5157f to 6ca4c6f Compare April 17, 2026 11:57
claude added 2 commits April 17, 2026 14:32
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
Short-circuits aliasResolveHandler before computing innerRequest /
entering forEachBail when options is empty, and returns a shared empty
array from compileAliasOptions so both AliasPlugin instances the factory
registers for resolvers without aliases do zero per-resolve work.

Also drops the hoisted hasRequest variable — reading request.request
inline is cheaper than closing over it, and matches the original code
shape to keep no-alias / single-alias cases (array-alias, fully-specified)
on a hot path identical to main.

https://claude.ai/code/session_01ERSdt7j3dKwd9MxNbuuXnm
@alexander-akait alexander-akait force-pushed the claude/benchmark-resolve-performance-JYrp7 branch from 6ca4c6f to 78744d1 Compare April 17, 2026 14:33
@alexander-akait alexander-akait merged commit 990c604 into main Apr 17, 2026
33 of 34 checks passed
@alexander-akait alexander-akait deleted the claude/benchmark-resolve-performance-JYrp7 branch April 17, 2026 14:40
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