Skip to content

perf: reduce hot-path allocations in resolve pipeline#615

Open
xiaoxiaojx wants to merge 1 commit into
mainfrom
perf/reduce-hot-path-allocations
Open

perf: reduce hot-path allocations in resolve pipeline#615
xiaoxiaojx wants to merge 1 commit into
mainfrom
perf/reduce-hot-path-allocations

Conversation

@xiaoxiaojx

Copy link
Copy Markdown
Member

Summary

Reduce per-resolve object allocations on the hot path by eliminating redundant spreads, deferring string construction, and reusing context objects. Motivated by profiling the cache-hit resolve path which showed ~15-20 short-lived allocations per resolve. Benchmarks show 5-7% throughput improvement on unsafe-cache-hit workloads with no regressions.

Related: general resolve performance improvement, no linked issue.

What kind of change does this PR introduce?

Performance (perf).

Did you add tests for your changes?

Yes — test/identifier.test.js gains a Resolver.parse() output shape assertion that guards against ParsePlugin field drift.

Does this PR introduce a breaking change?

No. All changes are internal allocation optimizations with identical observable behavior.

If relevant, what needs to be documented once your changes are merged?

n/a

Use of AI

Used Claude Code for analysis, implementation, and benchmarking.

🤖 Generated with Claude Code

@changeset-bot

changeset-bot Bot commented Jun 21, 2026

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: 31643b6

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
enhanced-resolve Patch

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

codecov Bot commented Jun 21, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 95.18072% with 4 lines in your changes missing coverage. Please review.
✅ Project coverage is 98.09%. Comparing base (e56eb3f) to head (31643b6).

Files with missing lines Patch % Lines
lib/Resolver.js 94.20% 4 Missing ⚠️
Additional details and impacted files
@@           Coverage Diff           @@
##             main     #615   +/-   ##
=======================================
  Coverage   98.09%   98.09%           
=======================================
  Files          49       49           
  Lines        9740     9757   +17     
=======================================
+ Hits         9554     9571   +17     
  Misses        186      186           
Flag Coverage Δ
integration 98.09% <95.18%> (+<0.01%) ⬆️

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

☔ View full report in Codecov by Harness.
📢 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

codspeed-hq Bot commented Jun 21, 2026

Copy link
Copy Markdown

Merging this PR will improve performance by 78.07%

⚠️ Different runtime environments detected

Some benchmarks with significant performance changes were compared across different runtime environments,
which may affect the accuracy of the results.

Open the report in CodSpeed to investigate

⚡ 5 improved benchmarks
❌ 2 regressed benchmarks
✅ 131 untouched benchmarks

Warning

Please fix the performance issues or acknowledge them on CodSpeed.

Performance Changes

Mode Benchmark BASE HEAD Efficiency
Memory pathological-deep-stack: alias chain of 50 (warm) 14.8 KB 24.9 KB -40.53%
Simulation realistic-midsize: mixed batch (cold cache) 7 ms 8 ms -12.6%
Memory cache-predicate: mixed cached/uncached requests (warm) 96.7 KB 1.5 KB ×64
Simulation cache-predicate: mixed cached/uncached requests (warm) 2.3 ms 2 ms +15.65%
Memory symlinks: follow symlinks=true (warm) 491.6 KB 425.4 KB +15.58%
Memory node-compare: enhanced-resolve promise x 1000 (no cache) 118 KB 103 KB +14.55%
Simulation alias-field: browser field (warm) 1.5 ms 1.3 ms +11.13%

Tip

Investigate this regression by commenting @codspeedbot fix this regression on this PR, or directly use the CodSpeed MCP with your agent.


Comparing perf/reduce-hot-path-allocations (31643b6) with main (e56eb3f)

Open in CodSpeed

@xiaoxiaojx xiaoxiaojx marked this pull request as draft June 21, 2026 07:07

@alexander-akait alexander-akait left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Looks good

- ParsePlugin: replace triple object spread with single spread +
  direct field assignments, eliminating two property enumerations
  per resolve (~5-7% throughput improvement on cache-hit benchmarks)
- Resolver.resolve(): skip redundant resolveContext wrapper object
  when no yield callback is present
- Resolver.resolve(): defer message template literal construction
  to the failure-only retry path
- Resolver.doResolve(): mutate-and-restore stack on internally-owned
  context instead of allocating via createInnerContext, saving 3-4
  object allocations per resolve on the no-log path
- Add Resolver.parse() output shape test to guard against
  ParsePlugin field drift
@xiaoxiaojx xiaoxiaojx force-pushed the perf/reduce-hot-path-allocations branch from ae33455 to 31643b6 Compare June 22, 2026 16:30
@xiaoxiaojx xiaoxiaojx marked this pull request as ready for review June 23, 2026 04:42
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