Skip to content

Optimize add dependency resolution#278

Draft
cijiugechu wants to merge 1 commit intoyarnpkg:mainfrom
cijiugechu:perf/add-resolution-cache
Draft

Optimize add dependency resolution#278
cijiugechu wants to merge 1 commit intoyarnpkg:mainfrom
cijiugechu:perf/add-resolution-cache

Conversation

@cijiugechu
Copy link
Copy Markdown
Contributor

Reuse project state and carry pre-resolved npm metadata into install to avoid duplicate add-time resolver work. Keep the new packument cache scoped to the add path so cold installs stay unchanged.

Benchmark

All benchmarks were run locally on macOS with release binaries.

Warm repeated add kleur

This benchmark measures a warm repeated add kleur path by removing kleur before each iteration.

Baseline binary:
/tmp/zpm-base-bench/target/release/yarn-bin
Patched binary:
/Users/nemurubaka/repos/zpm/target/release/yarn-bin

# Warmup for the baseline binary:
"/tmp/zpm-base-bench/target/release/yarn-bin" remove kleur >/dev/null 2>&1 || true
"/tmp/zpm-base-bench/target/release/yarn-bin" add kleur >/dev/null 2>&1
"/tmp/zpm-base-bench/target/release/yarn-bin" remove kleur >/dev/null 2>&1

# Warmup for the patched binary:
"/Users/nemurubaka/repos/zpm/target/release/yarn-bin" remove kleur >/dev/null 2>&1 || true
"/Users/nemurubaka/repos/zpm/target/release/yarn-bin" add kleur >/dev/null 2>&1
"/Users/nemurubaka/repos/zpm/target/release/yarn-bin" remove kleur >/dev/null 2>&1

# Measured with hyperfine:
hyperfine --warmup 3 --min-runs 20 \
  --export-json /tmp/zpm-add-compare-base-kleur.json \
  --prepare '"/tmp/zpm-base-bench/target/release/yarn-bin" remove kleur >/dev/null 2>&1' \
  '"/tmp/zpm-base-bench/target/release/yarn-bin" add kleur'

hyperfine --warmup 3 --min-runs 20 \
  --export-json /tmp/zpm-add-compare-current-kleur.json \
  --prepare '"/Users/nemurubaka/repos/zpm/target/release/yarn-bin" remove kleur >/dev/null 2>&1' \
  '"/Users/nemurubaka/repos/zpm/target/release/yarn-bin" add kleur'

Results:

  • Before patch: 684.8ms ± 226.0ms
  • After patch: 10.2ms ± 0.6ms

Reuse project state and carry pre-resolved npm metadata into install to avoid duplicate add-time resolver work. Keep the new packument cache scoped to the add path so cold installs stay unchanged.
@github-actions
Copy link
Copy Markdown

⏱️ Benchmark Results

gatsby install-full-cold

Metric Base Head Difference
Mean 2.806s 2.821s +0.54% ⚠️
Median 2.803s 2.815s +0.41% ⚠️
Min 2.761s 2.758s
Max 2.853s 2.993s
Std Dev 0.024s 0.041s
📊 Raw benchmark data (gatsby install-full-cold)

Base times: 2.803s, 2.835s, 2.803s, 2.761s, 2.813s, 2.823s, 2.779s, 2.782s, 2.775s, 2.827s, 2.839s, 2.847s, 2.800s, 2.802s, 2.787s, 2.811s, 2.789s, 2.790s, 2.845s, 2.853s, 2.828s, 2.803s, 2.818s, 2.818s, 2.815s, 2.807s, 2.782s, 2.774s, 2.801s, 2.774s

Head times: 2.993s, 2.758s, 2.873s, 2.838s, 2.838s, 2.835s, 2.839s, 2.801s, 2.825s, 2.831s, 2.825s, 2.799s, 2.814s, 2.815s, 2.827s, 2.788s, 2.799s, 2.810s, 2.805s, 2.806s, 2.787s, 2.841s, 2.815s, 2.807s, 2.820s, 2.805s, 2.807s, 2.789s, 2.872s, 2.774s


gatsby install-cache-and-lock (warm, with lockfile)

Metric Base Head Difference
Mean 0.409s 0.416s +1.81% ⚠️
Median 0.407s 0.416s +2.31% ⚠️
Min 0.398s 0.408s
Max 0.425s 0.426s
Std Dev 0.007s 0.004s
📊 Raw benchmark data (gatsby install-cache-and-lock (warm, with lockfile))

Base times: 0.405s, 0.420s, 0.422s, 0.415s, 0.406s, 0.402s, 0.410s, 0.405s, 0.417s, 0.414s, 0.403s, 0.403s, 0.413s, 0.407s, 0.404s, 0.406s, 0.412s, 0.413s, 0.406s, 0.414s, 0.413s, 0.425s, 0.402s, 0.398s, 0.406s, 0.405s, 0.409s, 0.412s, 0.402s, 0.399s

Head times: 0.416s, 0.411s, 0.409s, 0.408s, 0.416s, 0.418s, 0.421s, 0.425s, 0.419s, 0.420s, 0.411s, 0.415s, 0.417s, 0.414s, 0.410s, 0.419s, 0.410s, 0.416s, 0.416s, 0.420s, 0.416s, 0.413s, 0.419s, 0.419s, 0.418s, 0.426s, 0.421s, 0.416s, 0.419s, 0.414s

@cijiugechu cijiugechu marked this pull request as ready for review April 11, 2026 13:53
@arcanis
Copy link
Copy Markdown
Member

arcanis commented Apr 13, 2026

I think before this optimization I'd be interested we first try to implement the metadata cache originally implemented for Berry in yarnpkg/berry#5491 (also a nit, we don't use the term "packument", we use "metadata").

@cijiugechu cijiugechu marked this pull request as draft April 15, 2026 12:55
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