perf(alias): avoid per-resolve split("*") in AliasUtils scan#529
perf(alias): avoid per-resolve split("*") in AliasUtils scan#529alexander-akait merged 2 commits intomainfrom
Conversation
|
🦋 Changeset detectedLatest commit: 285bcb4 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 |
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #529 +/- ##
=======================================
Coverage 96.51% 96.51%
=======================================
Files 50 50
Lines 2639 2640 +1
Branches 805 806 +1
=======================================
+ Hits 2547 2548 +1
Misses 77 77
Partials 15 15
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
Merging this PR will improve performance by 55.12%
|
| Benchmark | BASE |
HEAD |
Efficiency | |
|---|---|---|---|---|
| 🆕 | alias-wildcard-scan: 100+1 wildcard + 1 exact |
N/A | 3.9 ms | N/A |
| ⚡ | pathological-deep-stack: alias chain of 50 (warm) |
24.5 ms | 19.1 ms | +28.3% |
| ⚡ | deep-hierarchy: bare specifier from 10-deep dir (warm) |
2.9 ms | 2.4 ms | +21.23% |
| ⚡ | large-alias-list: 50+8 aliases, match near end |
2.7 ms | 2.2 ms | +23.77% |
| ⚡ | multiple-modules: shared + vendor + node_modules (warm) |
1.7 ms | 1.4 ms | +24.93% |
| ⚡ | stack-churn: 4x60 alias chains, 20 resolves |
161.2 ms | 103.9 ms | +55.12% |
Comparing claude/add-performance-benchmarks-d00HP (285bcb4) with main (6637632)
AliasPlugin's per-resolve scan (`aliasResolveHandler`) called
`item.name.split("*")` for every alias option on every resolve, allocating
an array on each iteration even though almost all aliases in practice
contain no `*` and the split's result was immediately discarded.
Replace with a cheap `indexOf("*")`-based check that only computes the
prefix/suffix slices when the wildcard branch actually fires. Semantics
match the original `split("*").length === 2`: wildcard iff exactly one
`*` is present in `item.name`.
Measured locally via the benchmark suite (wall-clock, n=10):
alias-wildcard-scan 471 -> 552 ops/s (+17.1%)
large-alias-list 836 -> 952 ops/s (+13.9%)
Adds a new `alias-wildcard-scan` benchmark case that stresses this
decision with 100 non-matching aliases + 1 wildcard + 1 exact match so
the wildcard-detection cost shows up cleanly on CodSpeed, separately
from the fixture-IO exercised by `large-alias-list`.
3196401 to
e6d257d
Compare
AliasPlugin's per-resolve scan (
aliasResolveHandler) calleditem.name.split("*")for every alias option on every resolve, allocatingan array on each iteration even though almost all aliases in practice
contain no
*and the split's result was immediately discarded.Replace with a cheap
indexOf("*")-based check that only computes theprefix/suffix slices when the wildcard branch actually fires. Semantics
match the original
split("*").length === 2: wildcard iff exactly one*is present initem.name.Measured locally via the benchmark suite (wall-clock, n=10):
alias-wildcard-scan 471 -> 552 ops/s (+17.1%)
large-alias-list 836 -> 952 ops/s (+13.9%)
Adds a new
alias-wildcard-scanbenchmark case that stresses thisdecision with 100 non-matching aliases + 1 wildcard + 1 exact match so
the wildcard-detection cost shows up cleanly on CodSpeed, separately
from the fixture-IO exercised by
large-alias-list.