Repository navigation
perf(npm-resolver): cache meta in memory for exact version matches. - #12458
Conversation
|
💖 Thanks for opening this pull request! 💖 |
Code Review by Qodo
1. Cross-registry meta cache pollution
|
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Path: .coderabbit.yaml Review profile: CHILL Plan: Pro Plus Run ID: 📒 Files selected for processing (3)
🚧 Files skipped from review as they are similar to previous changes (1)
📝 WalkthroughWalkthroughThe PR extends the in-memory and shared package metadata cache with registry-aware keys and a conditional bypass mechanism. A new ChangesIn-memory and shared metadata cache registry-qualification
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~25 minutes Possibly related PRs
Suggested reviewers
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
Warning There were issues while running some tools. Please review the errors and either fix the tool's configuration or disable the tool if it's a critical failure. 🔧 ESLint
ESLint install failed. For unrecoverable errors, disable the tool in CodeRabbit configuration. Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
PR Summary by Qodoperf(npm-resolver): memoize disk-loaded metadata for exact version fast-path WalkthroughsDescription• Cache parsed packument in memory after exact-version disk hit • Avoid repeated disk reads/parses for the same package metadata • Speeds up large-monorepo installs by reusing ctx.metaCache across resolutions Diagramgraph TD
resolver["Dependency resolver"] --> pick["pickPackage()"] --> cache["metaCache (mem)"]
cache -->|"hit"| ret["Return meta + version"]
cache -->|"miss"| disk[("Meta mirror (disk)")] --> fast["pickMatchingVersionFast"] --> set["Cache meta in memory"] --> ret
set --> cache
High-Level AssessmentThe following are alternative approaches to this PR: 1. Bound metaCache with LRU/TTL eviction
2. Cache only the exact version entry instead of full meta
Recommendation: The PR’s approach (write-through to the existing ctx.metaCache on the exact-version disk fast-path) is the best near-zero-complexity win and aligns with how other pickPackage branches already populate the cache. If this cache is used in long-lived processes, consider adding an LRU/TTL later to cap memory growth, but that’s orthogonal to this performance fix. File ChangesEnhancement (1)
|
There was a problem hiding this comment.
Caution
Some comments are outside the diff and can’t be posted inline due to platform limitations.
⚠️ Outside diff range comments (1)
resolving/npm-resolver/src/pickPackage.ts (1)
276-297:⚠️ Potential issue | 🔴 CriticalAdd a changeset entry for the pickPackage cache optimization.
The
@pnpm/resolving.npm-resolverpackage already has the equivalent Rust implementation in pacquet (the in-memory cache is populated after disk-cache hits in the version-spec fast path). However, this user-visible performance optimization (minutes → seconds for adding packages in large monorepos) requires a changeset entry. Add a.changeset/*.mdfile with"@pnpm/resolving.npm-resolver": patchand"pnpm": patch, describing the cache population improvement.🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@resolving/npm-resolver/src/pickPackage.ts` around lines 276 - 297, A changeset entry is missing for the pickPackage cache optimization in the pickMatchingVersionFast function. Create a new markdown file in the .changeset directory with a filename following the project's naming convention (typically a unique identifier). The file should contain entries for "`@pnpm/resolving.npm-resolver`": patch and "pnpm": patch, followed by a description of the performance improvement that the cache population optimization provides (specifically how it reduces resolution time from minutes to seconds in large monorepos by populating the in-memory cache after disk-cache hits in the version-spec fast path).Source: Coding guidelines
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Outside diff comments:
In `@resolving/npm-resolver/src/pickPackage.ts`:
- Around line 276-297: A changeset entry is missing for the pickPackage cache
optimization in the pickMatchingVersionFast function. Create a new markdown file
in the .changeset directory with a filename following the project's naming
convention (typically a unique identifier). The file should contain entries for
"`@pnpm/resolving.npm-resolver`": patch and "pnpm": patch, followed by a
description of the performance improvement that the cache population
optimization provides (specifically how it reduces resolution time from minutes
to seconds in large monorepos by populating the in-memory cache after disk-cache
hits in the version-spec fast path).
ℹ️ Review info
⚙️ Run configuration
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Pro Plus
Run ID: 41c06128-b1fa-4207-a838-c03f9a1bbcbe
📒 Files selected for processing (1)
resolving/npm-resolver/src/pickPackage.ts
In pickPackage(), cache the parsed package metadata in memory after reading it from disk for exact version matches. Without this, we were repeatedly reading and parsing the same metadata.
bf3e9b2 to
ca7538e
Compare
|
Code review by qodo was updated up to the latest commit ca7538e |
The in-memory metaCache was keyed only by package name (and `:full`), while the on-disk mirror is registry-qualified. A package of the same name served by two registries in one install could collide on a single cache slot and resolve the wrong tarball/integrity. This became reachable on the common warm-cache path once the exact-version disk fast path started populating the cache. Include the registry in the in-memory cache key via a shared getPkgMetaCacheKey helper, and thread the registry through the verifier's shared-meta reads (which already documented this as the prerequisite for a registry-qualified read).
|
Code review by qodo was updated up to the latest commit 682f60b |
…onicalize the registry key Addresses two issues raised in review of the metadata-cache change. updateChecksums must force a conditional registry request, but the in-memory cache can now hold a packument promoted from the on-disk exact-version fast path rather than a fresh network fetch. On a shared or long-lived resolver a later updateChecksums call could short-circuit on that disk-sourced entry and skip revalidation. Bypass the in-memory cache when updateChecksums is set. Ported to pacquet, guarding both the pre-permit read and the post-permit re-check. getPkgMetaCacheKey keyed by the raw registry string, so the resolver (which may pass a configured named-registry URL verbatim) and the verifier (which routes through trailing-slashed prefixes) could build different keys for the same logical registry and miss the shared cache. Canonicalize the registry to its origin plus a trailing-slashed path; origin and path are preserved so registries that genuinely differ never collapse. This is a pnpm-only change for now: pacquet populates only the default registry today and its verifier shared-meta read is name-only, so the canonicalization has nothing to converge there yet.
|
Code review by qodo was updated up to the latest commit 5c6c040 |
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@resolving/npm-resolver/src/pickPackage.ts`:
- Around line 614-627: The getPkgMetaCacheKey function is missing the
filterMetadata parameter, causing cache collisions when the same
registry/package/fullMetadata combination has different filterMetadata values.
Add filterMetadata as a parameter to the function signature and include it in
the cache key generation by appending a suffix (similar to the existing :full
suffix) based on the filterMetadata boolean value—for example, append :filtered
when filterMetadata is true and :unfiltered when false, to match the Rust
implementation and prevent data corruption from cache key collisions.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Pro Plus
Run ID: 096b9072-dd95-42b9-bbd8-37674bc3ac8a
📒 Files selected for processing (4)
pacquet/crates/resolving-npm-resolver/src/pick_package.rspacquet/crates/resolving-npm-resolver/src/pick_package/tests.rsresolving/npm-resolver/src/pickPackage.tsresolving/npm-resolver/test/metaCache.test.ts
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #12458 +/- ##
==========================================
+ Coverage 88.18% 88.19% +0.01%
==========================================
Files 313 313
Lines 43074 43086 +12
==========================================
+ Hits 37983 37998 +15
+ Misses 5091 5088 -3 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
The on-disk metaDir already splits full metadata into filtered and unfiltered mirrors, but the in-memory metaCache key did not. A filterMetadata resolver stores a clearMeta-stripped packument, so when a metaCache is shared across resolvers with different filterMetadata settings an unfiltered-full request could be served the stripped form (or vice versa). Add the filtered dimension to getPkgMetaCacheKey, matching pacquet's `:full:filtered` key and the on-disk split, and probe both full variants from the verifier's shared-meta reads — a filtered full packument still carries the time/_npmUser/dist the verifier needs.
|
Code review by qodo was updated up to the latest commit 5785a04 |
Integrated-Benchmark Report (Linux)Each scenario reports direct installs and pnpr installs. Bencher consumes pacquet@HEAD and pnpr@HEAD. Scenario: Isolated linker: fresh restore, cold cache + cold store
BENCHMARK_REPORT.json{
"results": [
{
"command": "pacquet@HEAD",
"mean": 3.89954755424,
"stddev": 0.21477766042002577,
"median": 3.80462874094,
"user": 3.03767598,
"system": 2.631602419999999,
"min": 3.6816237849399998,
"max": 4.330957451940001,
"times": [
3.7352403009399997,
4.18043127694,
3.7834067169399996,
3.8220347379399997,
4.06176627394,
4.330957451940001,
3.80395633394,
3.6816237849399998,
3.80530114794,
3.79075751694
]
},
{
"command": "pacquet@main",
"mean": 3.7807601142399996,
"stddev": 0.16079385396668638,
"median": 3.73301369044,
"user": 3.0567855799999997,
"system": 2.6344546199999996,
"min": 3.6031225719399997,
"max": 4.14775680494,
"times": [
3.73475602094,
3.67541018194,
3.8031645039399997,
3.95415018594,
3.7126930999399996,
3.7312713599399996,
3.78908622294,
3.6031225719399997,
3.65619018994,
4.14775680494
]
},
{
"command": "pnpr@HEAD",
"mean": 2.87685768264,
"stddev": 0.5117999439586768,
"median": 2.6546033684399997,
"user": 2.06452078,
"system": 2.2270720199999996,
"min": 2.43063524494,
"max": 4.00076095294,
"times": [
3.0046638079399997,
2.7358099719399998,
4.00076095294,
2.6580563419399996,
2.59965438994,
2.47763837194,
2.64699737694,
3.5632099729399997,
2.43063524494,
2.6511503949399997
]
},
{
"command": "pnpr@main",
"mean": 2.31434133804,
"stddev": 0.14351635871532786,
"median": 2.28540532644,
"user": 2.1065118800000002,
"system": 2.22274572,
"min": 2.11737513794,
"max": 2.56944125694,
"times": [
2.56944125694,
2.31081089894,
2.23367569694,
2.48391785994,
2.20362328094,
2.11737513794,
2.32865199594,
2.19389669694,
2.4420208019399996,
2.25999975394
]
}
]
}Scenario: Isolated linker: fresh restore, hot cache + hot store
BENCHMARK_REPORT.json{
"results": [
{
"command": "pacquet@HEAD",
"mean": 0.60966179316,
"stddev": 0.03004576661888147,
"median": 0.6013932791600001,
"user": 0.2943006799999999,
"system": 1.0181628799999998,
"min": 0.58912532466,
"max": 0.69136989466,
"times": [
0.59687595266,
0.58912532466,
0.58974721566,
0.61211901366,
0.69136989466,
0.59757515066,
0.61010244266,
0.60521140766,
0.61185264766,
0.59263888166
]
},
{
"command": "pacquet@main",
"mean": 0.6857105371600001,
"stddev": 0.057482054592654555,
"median": 0.71885349816,
"user": 0.29521578,
"system": 1.0251325799999997,
"min": 0.59679442166,
"max": 0.72764811366,
"times": [
0.72764811366,
0.72100769566,
0.61023310666,
0.59679442166,
0.71200160366,
0.60133915466,
0.72240014466,
0.72274520466,
0.71669930066,
0.72623662566
]
},
{
"command": "pnpr@HEAD",
"mean": 0.6998451556599999,
"stddev": 0.08088021019015088,
"median": 0.64246592216,
"user": 0.30117088,
"system": 1.05668468,
"min": 0.62728681066,
"max": 0.80983863566,
"times": [
0.64100106066,
0.62728681066,
0.80513283966,
0.80983863566,
0.75773090466,
0.79661183066,
0.63702349366,
0.64393078366,
0.63971264766,
0.64018254966
]
},
{
"command": "pnpr@main",
"mean": 0.7231128273599999,
"stddev": 0.09539765837716996,
"median": 0.70586809616,
"user": 0.30580147999999996,
"system": 1.0423899799999998,
"min": 0.63588840866,
"max": 0.9462263816600001,
"times": [
0.67729482766,
0.65156771866,
0.78125573466,
0.6534568536600001,
0.73444136466,
0.63588840866,
0.64028522366,
0.75562146266,
0.75509029766,
0.9462263816600001
]
}
]
}Scenario: Isolated linker: fresh install, cold cache + cold store
BENCHMARK_REPORT.json{
"results": [
{
"command": "pacquet@HEAD",
"mean": 3.9845867885399997,
"stddev": 0.03662996094920252,
"median": 3.9908436304399997,
"user": 2.9132855999999996,
"system": 2.5901848400000005,
"min": 3.90123359594,
"max": 4.03775874894,
"times": [
3.97893805394,
3.99695030994,
3.90123359594,
3.98597814694,
4.001943467939999,
4.03775874894,
3.9608895229399996,
3.97111986094,
4.01534706394,
3.99570911394
]
},
{
"command": "pacquet@main",
"mean": 3.9911136654399995,
"stddev": 0.05470084545815714,
"median": 3.96323746994,
"user": 2.9461989999999996,
"system": 2.55496604,
"min": 3.93995000294,
"max": 4.10875951194,
"times": [
3.93995000294,
3.96071672494,
3.96007977394,
3.95812271694,
4.05718593594,
3.9909417649399996,
3.95011246394,
4.10875951194,
3.96575821494,
4.01950954394
]
},
{
"command": "pnpr@HEAD",
"mean": 2.6039930775399998,
"stddev": 0.3349377493944825,
"median": 2.5122065079399998,
"user": 1.9583884,
"system": 2.1787110400000005,
"min": 2.28007372194,
"max": 3.3337709109399998,
"times": [
2.4331040809399997,
2.38237563994,
2.28007372194,
2.28345850894,
2.51017926794,
2.57089827294,
3.3337709109399998,
2.5142337479399997,
2.73188885594,
2.9999477679399997
]
},
{
"command": "pnpr@main",
"mean": 2.67206789074,
"stddev": 0.406545528061934,
"median": 2.5885225419399998,
"user": 1.9797498,
"system": 2.16061454,
"min": 2.2386911439399997,
"max": 3.65048232394,
"times": [
2.78053707494,
3.65048232394,
2.9710394509399998,
2.62493396394,
2.69229222394,
2.41733416194,
2.2386911439399997,
2.5521111199399997,
2.33494148494,
2.45831595894
]
}
]
}Scenario: Isolated linker: fresh install, hot cache + hot store
BENCHMARK_REPORT.json{
"results": [
{
"command": "pacquet@HEAD",
"mean": 1.17209238696,
"stddev": 0.009300536775615636,
"median": 1.16973715406,
"user": 1.03809588,
"system": 1.3493729399999999,
"min": 1.16130546856,
"max": 1.19388893256,
"times": [
1.16621761556,
1.16940396356,
1.1645032145599998,
1.16936020756,
1.17331528556,
1.17007034456,
1.19388893256,
1.18073337756,
1.16130546856,
1.17212545956
]
},
{
"command": "pacquet@main",
"mean": 1.2374354429599999,
"stddev": 0.12310259180889725,
"median": 1.1891483110599999,
"user": 1.0398925799999998,
"system": 1.3853755399999998,
"min": 1.1697867845599998,
"max": 1.56812650056,
"times": [
1.17540825256,
1.19289868156,
1.19742222056,
1.17907416456,
1.56812650056,
1.30987418256,
1.18114583856,
1.1697867845599998,
1.21521986356,
1.18539794056
]
},
{
"command": "pnpr@HEAD",
"mean": 0.67110330716,
"stddev": 0.09295468810081928,
"median": 0.6377356025600001,
"user": 0.27360528,
"system": 1.0010487399999999,
"min": 0.6308893545600001,
"max": 0.9331798285600001,
"times": [
0.63234219156,
0.6398462555600001,
0.6318397305600001,
0.63562494956,
0.6319207175600001,
0.65346238156,
0.6308893545600001,
0.9331798285600001,
0.6690889805600001,
0.6528386815600001
]
},
{
"command": "pnpr@main",
"mean": 0.6374999392600001,
"stddev": 0.006044927590986967,
"median": 0.6373166765600001,
"user": 0.2591136799999999,
"system": 1.00473804,
"min": 0.6280287095600001,
"max": 0.6486202645600001,
"times": [
0.6363298375600001,
0.6486202645600001,
0.6280287095600001,
0.63023037956,
0.6335834455600001,
0.64234151256,
0.6393975905600001,
0.6371520585600001,
0.64183429956,
0.6374812945600001
]
}
]
}Scenario: Isolated linker: fresh install, cold cache + hot store
BENCHMARK_REPORT.json{
"results": [
{
"command": "pacquet@HEAD",
"mean": 2.6842347081800004,
"stddev": 0.029283729577661323,
"median": 2.6769069884800003,
"user": 1.37741786,
"system": 1.55046326,
"min": 2.65106668998,
"max": 2.75232963498,
"times": [
2.7121796059800003,
2.6653859059800005,
2.65106668998,
2.67040963198,
2.69222429798,
2.66261353898,
2.6745493989800004,
2.68232379898,
2.67926457798,
2.75232963498
]
},
{
"command": "pacquet@main",
"mean": 2.7753731288800005,
"stddev": 0.053096533360065944,
"median": 2.75211064398,
"user": 1.3816032599999999,
"system": 1.6650021600000002,
"min": 2.7197431359800004,
"max": 2.85647045898,
"times": [
2.7197431359800004,
2.82467512398,
2.75021568498,
2.72533444098,
2.7412508249800003,
2.84313971598,
2.75400560298,
2.85647045898,
2.7255686229800005,
2.81332767698
]
},
{
"command": "pnpr@HEAD",
"mean": 0.64125288458,
"stddev": 0.003718854553443272,
"median": 0.6410961764800001,
"user": 0.26984226,
"system": 0.9888409599999999,
"min": 0.63655727198,
"max": 0.64812007198,
"times": [
0.63857567598,
0.63738216798,
0.64589925298,
0.64234129098,
0.64059111598,
0.64812007198,
0.63858174098,
0.63655727198,
0.64160123698,
0.64287901998
]
},
{
"command": "pnpr@main",
"mean": 0.63499959698,
"stddev": 0.004796950272162789,
"median": 0.6350919614799999,
"user": 0.26458906,
"system": 0.9987876599999999,
"min": 0.62506101498,
"max": 0.64113700998,
"times": [
0.63899547198,
0.63419069698,
0.63897061498,
0.63412310698,
0.64113700998,
0.63254797798,
0.63599322598,
0.63835975898,
0.63061709098,
0.62506101498
]
}
]
} |
|
| Branch | pr/12458 |
| Testbed | pacquet |
Click to view all benchmark results
| Benchmark | Latency | Benchmark Result milliseconds (ms) (Result Δ%) | Upper Boundary milliseconds (ms) (Limit %) |
|---|---|---|---|
| isolated-linker.fresh-install.cold-cache.cold-store | 📈 view plot 🚷 view threshold | 3,984.59 ms(-5.49%)Baseline: 4,215.93 ms | 5,059.11 ms (78.76%) |
| isolated-linker.fresh-install.cold-cache.hot-store | 📈 view plot 🚷 view threshold | 2,684.23 ms(-10.53%)Baseline: 3,000.12 ms | 3,600.14 ms (74.56%) |
| isolated-linker.fresh-install.hot-cache.hot-store | 📈 view plot 🚷 view threshold | 1,172.09 ms(-11.61%)Baseline: 1,326.07 ms | 1,591.28 ms (73.66%) |
| isolated-linker.fresh-restore.cold-cache.cold-store | 📈 view plot 🚷 view threshold | 3,899.55 ms(-6.01%)Baseline: 4,149.09 ms | 4,978.91 ms (78.32%) |
| isolated-linker.fresh-restore.hot-cache.hot-store | 📈 view plot 🚷 view threshold | 609.66 ms(-0.88%)Baseline: 615.09 ms | 738.11 ms (82.60%) |
|
| Branch | pr/12458 |
| Testbed | pnpr |
⚠️ WARNING: No Threshold found!Without a Threshold, no Alerts will ever be generated.
Click here to create a new Threshold
For more information, see the Threshold documentation.
To only post results if a Threshold exists, set the--ci-only-thresholdsflag.
Click to view all benchmark results
| Benchmark | Latency | milliseconds (ms) |
|---|---|---|
| isolated-linker.fresh-install.cold-cache.cold-store | 📈 view plot | 2,603.99 ms |
| isolated-linker.fresh-install.cold-cache.hot-store | 📈 view plot | 641.25 ms |
| isolated-linker.fresh-install.hot-cache.hot-store | 📈 view plot | 671.10 ms |
| isolated-linker.fresh-restore.cold-cache.cold-store | 📈 view plot | 2,876.86 ms |
| isolated-linker.fresh-restore.hot-cache.hot-store | 📈 view plot | 699.85 ms |
|
Congrats on merging your first pull request! 🎉🎉🎉 |
Summary
In
pickPackage(), cache the parsed package metadata in memory after reading itfrom disk for exact version matches. Without this, the same metadata was read
and parsed from disk repeatedly. In a large monorepo this brings the time for
adding a new package down from minutes to seconds.
While populating the in-memory cache on the exact-version disk fast path, the
cache key is now also scoped by the registry. The on-disk mirror was already
registry-qualified, but the in-memory
metaCachekey was only the package name(plus a
:fullsuffix). A package of the same name served by two registries inone install (e.g. the default registry plus a
gh:/named registry) couldcollide on a single cache slot and resolve the wrong tarball/integrity. The
network-fetch path already populated this registry-blind cache, so the gap was
pre-existing — but having the disk fast path populate it too made the collision
reachable on the common warm-cache path. The cache key is now registry-qualified
end to end, including the verifier's shared-meta reads, which already documented
this as the prerequisite for a registry-qualified read.
Squash Commit Body
Checklist
pacquet/port — pacquet already scopes its in-memory cache key by registryand populates it on the disk fast path, so no port was needed.
Written by an agent (Claude Code, claude-opus-4-8).
Summary by CodeRabbit
Bug Fixes
updateChecksumsalways revalidates from the registry, bypassing both warm in-memory cache and the on-disk exact-version fast path.Tests
updateChecksumscache-bypass scenarios.