Repository navigation
Conversation
|
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 (1)
📝 WalkthroughWalkthroughAdds abbreviated-metadata normalization helpers, applies them in pnpm and pacquet registry fetch paths when registries return full documents, and adds tests plus a changeset covering the caching behavior. ChangesRegistry metadata normalization
Estimated code review effort: 4 (Complex) | ~45 minutes Sequence Diagram(s)sequenceDiagram
participant Registry
participant fetch as fetchMetadataFromFromRegistry
participant normalize as normalizeAbbreviatedResponse
participant clearMeta as clearMeta
Registry-->>fetch: meta, jsonText, content-type
fetch->>normalize: normalizeAbbreviatedResponse(meta, jsonText, headers)
alt full document returned for abbreviated request
normalize->>clearMeta: clearMeta(meta)
clearMeta-->>normalize: reduced meta
normalize-->>fetch: reduced meta, re-serialized jsonText
else abbreviated document returned
normalize-->>fetch: original meta, jsonText
end
Possibly related PRs
Suggested labels: Suggested reviewers: ✨ Finishing Touches🧪 Generate unit tests (beta)
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): normalize non-abbreviated registry metadata
AI Description
Diagram
High-Level Assessment
Files changed (5)
|
There was a problem hiding this comment.
Pull request overview
This PR improves performance when resolving packages against registries that ignore pnpm’s abbreviated packument Accept header by normalizing “full” metadata responses down to the abbreviated shape at fetch time (keyed off the response Content-Type), reducing cache size and parse overhead without changing resolution results.
Changes:
- Normalize non-abbreviated responses for abbreviated metadata requests inside
fetchMetadataFromFromRegistry()usingclearMeta()when the responseContent-Typeis not the abbreviated media type. - Extract
clearMeta()into a shared module so it can be reused by both the fetch path andpickPackage(forfilterMetadata). - Add coverage that asserts normalization occurs for
application/jsonresponses, and that already-abbreviated responses are cached verbatim.
Reviewed changes
Copilot reviewed 5 out of 5 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
pnpm11/resolving/npm-resolver/src/fetch.ts |
Adds Content-Type-gated normalization of abbreviated metadata responses before caching. |
pnpm11/resolving/npm-resolver/src/clearMeta.ts |
Extracts clearMeta() into a reusable module and makes it null-safe on versions. |
pnpm11/resolving/npm-resolver/src/pickPackage.ts |
Switches to importing clearMeta() from the new module (removes inline implementation). |
pnpm11/resolving/npm-resolver/test/normalizeAbbreviated.test.ts |
Adds tests covering normalization vs. verbatim caching behavior. |
.changeset/normalize-registry-metadata-at-network-layer.md |
Documents the change and bumps @pnpm/resolving.npm-resolver and pnpm. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Code Review by Qodo
1. Normalization forces full parse
|
There was a problem hiding this comment.
Actionable comments posted: 1
🧹 Nitpick comments (1)
.changeset/normalize-registry-metadata-at-network-layer.md (1)
6-6: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick winTrim implementation rationale from the user-facing changeset.
The entry explains how the fix works (Content-Type detection, "at the point of fetching," etc.) rather than only what changed for users. Per REVIEW_GUIDE.md, changesets should be "written for users (no implementation rationale)."
✏️ Suggested trim
-Sped up resolution and reduced memory use against registries that do not implement npm's abbreviated metadata format (for example, Azure DevOps Artifacts). Such registries ignore the `application/vnd.npm.install-v1+json` request and return the full package document — including per-version fields the installer never reads (`scripts`, `exports`, `devDependencies`, custom `package.json` fields, etc.). pnpm now detects this at the point of fetching (via the response `Content-Type`) and normalizes the document down to the abbreviated field set before it enters the cache, so subsequent resolutions read and parse a much smaller document. Registries that honor the abbreviated header (such as the npm registry) are detected as already-abbreviated and pay no extra cost. On a large workspace whose feed serves full documents, this roughly halved `pnpm dedupe --offline` time and cut peak memory, with no change to resolution output. +Reduced memory use and sped up resolution/install against registries that return full (non-abbreviated) package metadata instead of npm's abbreviated format (for example, Azure DevOps Artifacts). Resolution output is unchanged.As per path instructions, "require an accurate changeset written for users (no implementation rationale) and 'smallest correct version' scope discipline."
🤖 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 @.changeset/normalize-registry-metadata-at-network-layer.md at line 6, Rewrite the changeset text to be user-facing only by removing implementation details like Content-Type detection, fetching internals, cache normalization, and parse/path specifics. Keep the summary focused on the observable change for users—pnpm now handles registries that return full package documents more efficiently, reducing resolution time and memory use, while preserving the same resolution output. Reference the existing changeset description and keep it to the smallest correct version scope.Source: Path instructions
🤖 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 `@pnpm11/resolving/npm-resolver/src/clearMeta.ts`:
- Around line 20-44: Hoist the invariant field-list array used by clearMeta out
of the Object.entries(pkg.versions ?? {}) loop so it’s created once instead of
on every iteration. Define the constant near clearMeta and reuse it in the
pick(...) call inside the per-version processing, keeping the behavior the same
while avoiding repeated allocation.
---
Nitpick comments:
In @.changeset/normalize-registry-metadata-at-network-layer.md:
- Line 6: Rewrite the changeset text to be user-facing only by removing
implementation details like Content-Type detection, fetching internals, cache
normalization, and parse/path specifics. Keep the summary focused on the
observable change for users—pnpm now handles registries that return full package
documents more efficiently, reducing resolution time and memory use, while
preserving the same resolution output. Reference the existing changeset
description and keep it to the smallest correct version scope.
🪄 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: 08762627-caf3-4ab8-bfcc-de9b09304759
📒 Files selected for processing (5)
.changeset/normalize-registry-metadata-at-network-layer.mdpnpm11/resolving/npm-resolver/src/clearMeta.tspnpm11/resolving/npm-resolver/src/fetch.tspnpm11/resolving/npm-resolver/src/pickPackage.tspnpm11/resolving/npm-resolver/test/normalizeAbbreviated.test.ts
|
Code review by qodo was updated up to the latest commit a9532b1 |
…e network layer pnpm requests abbreviated package metadata (Accept: application/vnd.npm.install-v1+json). Some registries (e.g. Azure DevOps Artifacts) ignore that header and return the full CouchDB document, including per-version fields the installer never reads (scripts, exports, devDependencies, readme, custom package.json fields). pnpm stored that response verbatim in the abbreviated metadata cache, so every later resolution re-read and re-parsed those unused fields — on a large workspace whose feed serves full documents, a single package's metadata was ~40 MB, ~88% of it unused. Fix the response at the boundary where it enters pnpm: fetchMetadataFromFromRegistry inspects the response Content-Type. When an abbreviated request comes back with anything other than application/vnd.npm.install-v1+json, the registry ignored the header and served the full document, so the fetch layer strips it to the abbreviated field set (via the existing clearMeta helper) and re-serializes. Registries that honor the header (the npm registry echoes the abbreviated Content-Type) are detected as already-abbreviated and take an early return: no clearMeta, no re-serialization — the happy path pays nothing. clearMeta is extracted from pickPackage.ts into its own module so the network layer can use it without a circular import, and is made null-safe on versions so it can run on an unpublished package. pickPackage's abbreviated slot no longer needs any special-casing: the fetch layer now guarantees abbreviated shape, so the resolver keeps only its pre-existing filterMetadata (full-slot) narrowing. This is an alternative to pnpm#12766, which applied the same normalization one layer up in pickPackage. Both produce a byte-identical on-disk cache and byte-identical resolution output; this variant additionally skips the work entirely for spec-compliant registries and removes the special-casing from the resolver. Co-authored-by: Copilot <[email protected]>
a9532b1 to
14c6ed1
Compare
|
Code review by qodo was updated up to the latest commit 14c6ed1 |
1 similar comment
|
Code review by qodo was updated up to the latest commit 14c6ed1 |
- Parse the response Content-Type into its media type (parameters dropped, case-insensitive per RFC 9110) instead of a case-sensitive substring match, so non-canonical casings and lookalike media types are classified correctly. - Build the normalized versions map with a null prototype so a registry-controlled version key named __proto__ cannot mutate the map's prototype at the fetch boundary. - Hoist the invariant abbreviated-field list out of the per-version loop. - Fix the changeset: devDependencies is kept (it is part of the abbreviated field set), and trim implementation rationale from the user-facing note.
Port of the TypeScript-side change in this PR. Both metadata fetchers now inspect the response Content-Type: when an abbreviated request comes back with anything other than application/vnd.npm.install-v1+json (media type parsed parameter-free and case-insensitively), the registry ignored the Accept header and served the full document, so the packument is stripped to the abbreviated field set via the existing clear_meta before it reaches the pick or the on-disk mirror. Registries that honor the header skip the normalization entirely. clear_meta failure (practically unreachable: the fragments were just parsed from the response body) keeps the full document instead of failing the fetch, matching the TypeScript side where normalization cannot fail.
There was a problem hiding this comment.
🧹 Nitpick comments (1)
pacquet/crates/resolving-npm-resolver/src/fetch_full_metadata_cached/tests.rs (1)
141-142: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick winReuse the existing
ACCEPT_ABBREVIATED_DOCconstant instead of duplicating the literal.
fetch_full_metadata.rsalready exportspub(crate) const ACCEPT_ABBREVIATED_DOCwith this exact value. Redefining it here risks drift if the header value changes later (the test would silently stop reflecting the real request header).♻️ Proposed fix
-const ACCEPT_ABBREVIATED: &str = - "application/vnd.npm.install-v1+json; q=1.0, application/json; q=0.8, */*"; +use crate::fetch_full_metadata::ACCEPT_ABBREVIATED_DOC as ACCEPT_ABBREVIATED;🤖 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 `@pacquet/crates/resolving-npm-resolver/src/fetch_full_metadata_cached/tests.rs` around lines 141 - 142, The test is duplicating the abbreviated Accept header literal instead of reusing the shared constant. Update the `fetch_full_metadata_cached/tests.rs` test setup to reference `ACCEPT_ABBREVIATED_DOC` from `fetch_full_metadata.rs` instead of defining `ACCEPT_ABBREVIATED` locally, so the test always matches the वास्तविक request header value and stays in sync with future changes.
🤖 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.
Nitpick comments:
In
`@pacquet/crates/resolving-npm-resolver/src/fetch_full_metadata_cached/tests.rs`:
- Around line 141-142: The test is duplicating the abbreviated Accept header
literal instead of reusing the shared constant. Update the
`fetch_full_metadata_cached/tests.rs` test setup to reference
`ACCEPT_ABBREVIATED_DOC` from `fetch_full_metadata.rs` instead of defining
`ACCEPT_ABBREVIATED` locally, so the test always matches the वास्तविक request
header value and stays in sync with future changes.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Pro Plus
Run ID: 770a4a61-1de7-4d88-8000-35d49e758e4d
📒 Files selected for processing (7)
.changeset/normalize-registry-metadata-at-network-layer.mdpacquet/crates/resolving-npm-resolver/src/fetch_full_metadata.rspacquet/crates/resolving-npm-resolver/src/fetch_full_metadata_cached.rspacquet/crates/resolving-npm-resolver/src/fetch_full_metadata_cached/tests.rspnpm11/resolving/npm-resolver/src/clearMeta.tspnpm11/resolving/npm-resolver/src/fetch.tspnpm11/resolving/npm-resolver/test/normalizeAbbreviated.test.ts
✅ Files skipped from review due to trivial changes (1)
- .changeset/normalize-registry-metadata-at-network-layer.md
🚧 Files skipped from review as they are similar to previous changes (3)
- pnpm11/resolving/npm-resolver/src/fetch.ts
- pnpm11/resolving/npm-resolver/src/clearMeta.ts
- pnpm11/resolving/npm-resolver/test/normalizeAbbreviated.test.ts
|
Code review by qodo was updated up to the latest commit 65c9bd8 |
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #12772 +/- ##
==========================================
+ Coverage 84.99% 85.02% +0.02%
==========================================
Files 414 415 +1
Lines 65282 65415 +133
==========================================
+ Hits 55489 55617 +128
- Misses 9793 9798 +5 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
|
Code review by qodo was updated up to the latest commit 65c9bd8 |
Integrated-Benchmark Report (Linux)Commit: 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": 4.06870175618,
"stddev": 0.1678480695023765,
"median": 4.06479394978,
"user": 3.9256287999999997,
"system": 3.3932914600000004,
"min": 3.85757846178,
"max": 4.35717395078,
"times": [
4.35717395078,
4.19221507478,
3.89673680978,
4.08725062078,
4.145516446779999,
3.99651609578,
4.24085871178,
3.85757846178,
3.87083411078,
4.04233727878
]
},
{
"command": "pacquet@main",
"mean": 4.070505068779999,
"stddev": 0.13652999533398397,
"median": 4.03391190128,
"user": 3.9116412999999994,
"system": 3.38149526,
"min": 3.8696204937800003,
"max": 4.26488259878,
"times": [
4.04453083578,
4.02329296678,
3.8696204937800003,
3.9154980597800004,
3.98881427978,
4.18094363878,
4.00909019978,
4.15775944678,
4.26488259878,
4.25061816778
]
},
{
"command": "pnpr@HEAD",
"mean": 2.09674673918,
"stddev": 0.15818357671634042,
"median": 2.0429353387800004,
"user": 2.7153593999999996,
"system": 2.8385818599999997,
"min": 1.90785790578,
"max": 2.32019998778,
"times": [
2.2068043097800003,
2.2313004647800003,
1.91990788578,
1.90785790578,
2.31544557478,
2.0187288167800004,
2.03747698478,
1.96135176878,
2.0483936927800004,
2.32019998778
]
},
{
"command": "pnpr@main",
"mean": 2.16126596618,
"stddev": 0.11646853325196926,
"median": 2.20655026328,
"user": 2.6943561,
"system": 2.8507574599999996,
"min": 1.9652364557800002,
"max": 2.3001151867800003,
"times": [
2.09941191578,
2.18965585178,
2.01412584978,
1.9652364557800002,
2.2396771607800003,
2.22344467478,
2.24575301178,
2.0654871057800004,
2.3001151867800003,
2.2697524487800003
]
}
]
}Scenario: Isolated linker: fresh restore, hot cache + hot store
BENCHMARK_REPORT.json{
"results": [
{
"command": "pacquet@HEAD",
"mean": 0.66584977532,
"stddev": 0.013364388506212315,
"median": 0.66496444432,
"user": 0.38870515999999994,
"system": 1.3436678999999998,
"min": 0.64490745182,
"max": 0.68896531482,
"times": [
0.66507673082,
0.66357188582,
0.65068339282,
0.67428524482,
0.66485215782,
0.68896531482,
0.67554116982,
0.65453494582,
0.64490745182,
0.67607945882
]
},
{
"command": "pacquet@main",
"mean": 0.67058704272,
"stddev": 0.06764822297709437,
"median": 0.64960527332,
"user": 0.37581455999999996,
"system": 1.3240945999999998,
"min": 0.62306306582,
"max": 0.85635038682,
"times": [
0.65657300482,
0.65484990882,
0.64020313082,
0.63695213682,
0.65192677082,
0.64667288982,
0.64728377582,
0.62306306582,
0.85635038682,
0.69199535682
]
},
{
"command": "pnpr@HEAD",
"mean": 0.71552215112,
"stddev": 0.05003662686726339,
"median": 0.7017814153199999,
"user": 0.40750975999999994,
"system": 1.3567831,
"min": 0.69246443882,
"max": 0.8568957928200001,
"times": [
0.70462067582,
0.69366544182,
0.70035327882,
0.69394627382,
0.70320955182,
0.69246443882,
0.69449291582,
0.8568957928200001,
0.70992353982,
0.70564960182
]
},
{
"command": "pnpr@main",
"mean": 0.69511930442,
"stddev": 0.027418812121846898,
"median": 0.69292727832,
"user": 0.38516155999999996,
"system": 1.3427025999999997,
"min": 0.66356187282,
"max": 0.74898203282,
"times": [
0.68462913682,
0.71867495782,
0.67045344082,
0.66356187282,
0.67492874982,
0.71289496482,
0.74898203282,
0.70122541982,
0.70704186982,
0.66880059882
]
}
]
}Scenario: Isolated linker: fresh install, cold cache + cold store
BENCHMARK_REPORT.json{
"results": [
{
"command": "pacquet@HEAD",
"mean": 4.239982040159999,
"stddev": 0.027942125134977697,
"median": 4.242582693459999,
"user": 3.8442624600000004,
"system": 3.29251472,
"min": 4.193986767459999,
"max": 4.28419586046,
"times": [
4.25570130446,
4.2712556054599995,
4.250184916459999,
4.193986767459999,
4.28419586046,
4.23085510546,
4.204148389459999,
4.22432706546,
4.24179279846,
4.24337258846
]
},
{
"command": "pacquet@main",
"mean": 4.21821854756,
"stddev": 0.030947384021691463,
"median": 4.236202261459999,
"user": 3.80276956,
"system": 3.310076719999999,
"min": 4.17539239146,
"max": 4.24840879846,
"times": [
4.24840879846,
4.18874577146,
4.187522127459999,
4.24061380746,
4.24630996446,
4.17539239146,
4.2334861534599995,
4.24315734346,
4.179630748459999,
4.2389183694599994
]
},
{
"command": "pnpr@HEAD",
"mean": 2.11370555146,
"stddev": 0.11121924809298235,
"median": 2.09166636046,
"user": 2.57234886,
"system": 2.78514092,
"min": 1.9561703814600002,
"max": 2.32643509146,
"times": [
2.10600945846,
2.07476866846,
2.07732326246,
1.9561703814600002,
2.05471814546,
2.32643509146,
2.02191573446,
2.11535251746,
2.27564496046,
2.12871729446
]
},
{
"command": "pnpr@main",
"mean": 2.11738809296,
"stddev": 0.09134154489574722,
"median": 2.08759736396,
"user": 2.56287486,
"system": 2.78596282,
"min": 2.00838789946,
"max": 2.26115126646,
"times": [
2.1812208274600002,
2.00838789946,
2.02390665146,
2.06441660346,
2.17250064546,
2.26115126646,
2.04293525646,
2.2441670514600003,
2.07190128346,
2.10329344446
]
}
]
}Scenario: Isolated linker: fresh install, hot cache + hot store
BENCHMARK_REPORT.json{
"results": [
{
"command": "pacquet@HEAD",
"mean": 1.37986330364,
"stddev": 0.025646325138347432,
"median": 1.3750087741400001,
"user": 1.3767934399999997,
"system": 1.6876349799999997,
"min": 1.3568799686400002,
"max": 1.4504450716400001,
"times": [
1.37782409064,
1.3682705156400001,
1.37022919664,
1.37659675564,
1.37346870464,
1.3765488436400002,
1.3568799686400002,
1.4504450716400001,
1.37924383464,
1.3691260546400001
]
},
{
"command": "pacquet@main",
"mean": 1.37299690984,
"stddev": 0.0343740810114423,
"median": 1.36345217414,
"user": 1.32575654,
"system": 1.69800788,
"min": 1.3411207316400002,
"max": 1.4647601196400002,
"times": [
1.3806927586400002,
1.4647601196400002,
1.35985686164,
1.35068742764,
1.37824255664,
1.35711995064,
1.37058434364,
1.36300464264,
1.3411207316400002,
1.3638997056400002
]
},
{
"command": "pnpr@HEAD",
"mean": 0.70390904654,
"stddev": 0.10483631782845625,
"median": 0.67180985414,
"user": 0.36700654,
"system": 1.28624828,
"min": 0.65816152264,
"max": 1.00103629564,
"times": [
0.65816152264,
0.66841232364,
0.66170985464,
1.00103629564,
0.67153684564,
0.68602756664,
0.65978929264,
0.6720828626400001,
0.67552394664,
0.68480995464
]
},
{
"command": "pnpr@main",
"mean": 0.6541494863399999,
"stddev": 0.005881101036171655,
"median": 0.65396859964,
"user": 0.33475794,
"system": 1.2723747799999998,
"min": 0.64481522864,
"max": 0.6636996376400001,
"times": [
0.65111162664,
0.64481522864,
0.64786951464,
0.65221875464,
0.65032394064,
0.65699205264,
0.66001108764,
0.6636996376400001,
0.6557184446400001,
0.65873457564
]
}
]
}Scenario: Isolated linker: fresh install, cold cache + hot store
BENCHMARK_REPORT.json{
"results": [
{
"command": "pacquet@HEAD",
"mean": 3.042018579319999,
"stddev": 0.028240401010207708,
"median": 3.0353802216199997,
"user": 1.81313608,
"system": 1.98282822,
"min": 3.01188324362,
"max": 3.10647073462,
"times": [
3.10647073462,
3.01188324362,
3.0165069936199997,
3.03504904362,
3.0494716286199997,
3.05929581762,
3.0321671636199996,
3.0159461356199997,
3.05768363262,
3.03571139962
]
},
{
"command": "pacquet@main",
"mean": 3.0283727579199997,
"stddev": 0.02602570215120123,
"median": 3.02170381062,
"user": 1.7756555799999998,
"system": 1.97988792,
"min": 2.99915475062,
"max": 3.0865912066199996,
"times": [
3.01253131862,
3.02378235662,
3.0196252646199997,
3.0050466646199996,
2.99915475062,
3.0141939336199997,
3.0298935006199996,
3.0536331196199997,
3.0865912066199996,
3.0392754636199997
]
},
{
"command": "pnpr@HEAD",
"mean": 0.6677956345199999,
"stddev": 0.00721404267549917,
"median": 0.6688989911200001,
"user": 0.35222838,
"system": 1.28894362,
"min": 0.65624726862,
"max": 0.67540303962,
"times": [
0.6745855376200001,
0.6610936916200001,
0.6678264756200001,
0.65731615862,
0.67540303962,
0.6691882076200001,
0.6743720066200001,
0.65624726862,
0.67331418462,
0.66860977462
]
},
{
"command": "pnpr@main",
"mean": 0.6818356108200001,
"stddev": 0.007324943389202568,
"median": 0.6818457186200001,
"user": 0.33958678,
"system": 1.29594712,
"min": 0.6717955026200001,
"max": 0.6959349316200001,
"times": [
0.6959349316200001,
0.6897517966200001,
0.6813212366200001,
0.6823702006200001,
0.6774218806200001,
0.6717955026200001,
0.6792577026200001,
0.6826299666200001,
0.6851216786200001,
0.6727512116200001
]
}
]
}Scenario: Isolated linker: fresh restore, cold cache + cold store + cold pnpr
BENCHMARK_REPORT.json{
"results": [
{
"command": "pacquet@HEAD",
"mean": 6.74322498868,
"stddev": 0.14146880079545712,
"median": 6.71617000958,
"user": 4.099998459999999,
"system": 3.6637893399999997,
"min": 6.60590011508,
"max": 7.057132656079999,
"times": [
7.057132656079999,
6.7165855810799995,
6.6219784940799995,
6.71819628308,
6.66334439408,
6.84261132708,
6.623583669079999,
6.86716292908,
6.60590011508,
6.71575443808
]
},
{
"command": "pacquet@main",
"mean": 6.8015794106800005,
"stddev": 0.16528004906318616,
"median": 6.760843449579999,
"user": 4.104333459999999,
"system": 3.6260417400000002,
"min": 6.61722612308,
"max": 7.03336209308,
"times": [
6.98975653308,
6.8262442950799995,
6.61722612308,
6.65670618808,
7.01689245208,
6.85909915708,
6.67500751908,
6.64605714208,
7.03336209308,
6.69544260408
]
},
{
"command": "pnpr@HEAD",
"mean": 4.868962460180001,
"stddev": 0.08223482811921691,
"median": 4.8731005110800005,
"user": 2.8427282600000003,
"system": 3.1069894400000004,
"min": 4.690942415079999,
"max": 4.97825430608,
"times": [
4.9489153010799996,
4.88484671408,
4.93947017208,
4.85105453908,
4.87967143908,
4.85045730408,
4.86652958308,
4.97825430608,
4.690942415079999,
4.7994828280799995
]
},
{
"command": "pnpr@main",
"mean": 4.88445890278,
"stddev": 0.06308686374226721,
"median": 4.89140664558,
"user": 2.8093123600000003,
"system": 3.1148537400000005,
"min": 4.78658556108,
"max": 4.95418071408,
"times": [
4.79829414208,
4.84851380708,
4.94819927808,
4.93947004208,
4.84229565408,
4.88346545108,
4.95418071408,
4.94423653808,
4.89934784008,
4.78658556108
]
}
]
} |
|
| Branch | pr/12772 |
| 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,113.71 ms |
| isolated-linker.fresh-install.cold-cache.hot-store | 📈 view plot | 667.80 ms |
| isolated-linker.fresh-install.hot-cache.hot-store | 📈 view plot | 703.91 ms |
| isolated-linker.fresh-restore.cold-cache.cold-store | 📈 view plot | 2,096.75 ms |
| isolated-linker.fresh-restore.cold-cache.cold-store.cold-pnpr | 📈 view plot | 4,868.96 ms |
| isolated-linker.fresh-restore.hot-cache.hot-store | 📈 view plot | 715.52 ms |
…s against drift ACCEPT_ABBREVIATED_DOC and ABBREVIATED_META_CONTENT_TYPE repeat the abbreviated media type as separate literals because Rust cannot build one string const from another without a macro or an extra dependency. Assert that the Accept header offers the media type the response detection recognizes, so an edit to either constant alone fails loudly.
|
Code review by qodo was updated up to the latest commit 43635c9 |
1 similar comment
|
Code review by qodo was updated up to the latest commit 43635c9 |
|
Congrats on merging your first pull request! 🎉🎉🎉 |
|
Thanks @zkochan for reviewing and merging this so quickly! I know that with AI writing code is much easier than reviewing, and I appreciate you doing the hard part :-) This and #12760 combined result in 5x seepedup in dedupe for our large monorepo at Microsoft - effectively unblocking us from migrating our repo to pnpm. That's a huge win for us. |
|
Nice! If you want further speed improvement, you can check pnpr. It is experimental yet but with server side resolution it makes resolution 2 times faster even compared to the rust rewrite of pnpm. |
|
also, interestingly pnpr was also solving this issue out of the box already. If you would request Azure DevOps via a pnpr registry, it would automatically filter the full metadata. |
Awesome! I'll take a look. |
Summary
pnpm requests abbreviated package metadata (
Accept: application/vnd.npm.install-v1+json) — the slim document with only the fields needed to install. Some registries ignore that header and return the full document (npm's abbreviated format is a vendor convention, not something every registry implements). Azure DevOps Artifacts is one such registry: it always returns the full CouchDB document, including per-versionscripts,exports,devDependencies,readme, and arbitrary custompackage.jsonfields.pnpm stored that response verbatim in the abbreviated metadata cache, so every later resolution re-read and re-parsed all of those unused fields.
This PR fixes the malformed response at the boundary where it enters pnpm — the network/fetch layer. The fetch layer inspects the response
Content-Type: an abbreviated request that comes back as anything other thanapplication/vnd.npm.install-v1+jsonmeans the registry ignored the header and served the full document, so the fetch layer normalizes it down to the abbreviated field set (reusing the existingclearMetahelper) before it enters the in-memory cache, the on-disk mirror, or the resolver. The resolver already ignores the dropped fields, so resolution output is byte-identical — the cache just gets much smaller and faster to parse.Registries that honor the abbreviated header (e.g. npmjs.org echoes
Content-Type: application/vnd.npm.install-v1+json) are detected as already-abbreviated and take an early return: no field stripping, no re-serialization — the happy path pays nothing.The problem, concretely
On a large monorepo at Microsoft whose workspace resolves against an Azure DevOps Artifacts feed, one internal package's abbreviated metadata was 39.7 MB — of which only ~12% is install-relevant:
scriptsdevDependenciesexportsdependencies(needed)_id,readme, dev-tooling config, …)dist(needed)The same package on the public npm registry (which honors the abbreviated header) is 0.52 MB. I confirmed the registry behavior directly: requesting that package from Azure DevOps with
Accept: application/vnd.npm.install-v1+jsonreturns byte-for-byte the same response asAccept: application/json— it does no content negotiation. The public npm registry, by contrast, echoesContent-Type: application/vnd.npm.install-v1+jsonfor the abbreviated request andapplication/jsonfor the full one — which is exactly the signal this PR keys off.Because dedupe/resolution parses each package's metadata (potentially once per dependent), the extra ~88% of every document dominates wall time and heap.
The fix
fetchMetadataFromFromRegistry(in@pnpm/resolving.npm-resolver) reads the responseContent-Type. On an abbreviated request whose response is not the abbreviated content type, it runsclearMetaand re-serializes; otherwise it returns the parsed body untouched.clearMetais extracted frompickPackage.tsinto its own module so the fetch layer can use it without a circular import, and is made null-safe for packages with no versions (unpublished), which the abbreviated path can now reach.pickPackageneeds no abbreviated-slot special-casing — it keeps only its pre-existingfilterMetadata(full-slot) narrowing.Why resolution is unchanged
clearMetakeeps every field the resolver reads (dependencies/optionalDependencies/peerDependencies*/dist/engines/cpu/os/libc/bin/bundleDependencies/deprecated/hasInstallScript/_npmUser) and the top-leveltime(sominimumReleaseAgestill works). Resolution output is therefore byte-identical; only the size of the cached document changes.Performance
Warm-cache
pnpm dedupe --lockfile-only --offlineon that monorepo (~5,000 external packages), best of repeated runs:Additionally, because the detection happens at fetch time, spec-compliant registries (npmjs.org) skip
clearMetaand re-serialization entirely — the extra work only ever runs for registries that actually send full documents.pacquet port
The equivalent change is included for the Rust stack: both metadata fetchers in
pacquet-resolving-npm-resolver(fetch_full_metadataandfetch_full_metadata_cached) now inspect the responseContent-Typeon abbreviated requests and strip a full document down to the abbreviated field set via the existingclear_metabefore it reaches the pick or the on-disk mirror. Media-type detection drops parameters and compares case-insensitively (RFC 9110). Registries that echo the abbreviated content type skip the normalization entirely.Testing
normalizeAbbreviated.test.tsdrives the real fetch path through a mock registry: a full document served withContent-Type: application/jsonis normalized in the abbreviated cache (unused fields dropped, install fields kept); a document served with the abbreviated content type (uppercased, with acharsetparameter) is cached verbatim (no stripping, no re-serialization), proving the happy path is untouched.@pnpm/resolving.npm-resolver: full suite passes (239 tests), compile + lint + typecheck clean.fetch_full_metadata_cached/tests.rs;pacquet-resolving-npm-resolversuite passes (280 tests), clippy/fmt clean.Alternative considered: downstream normalization (#12766)
#12766 is an earlier, alternative implementation of the same behavior that applies
clearMetaone layer up, inpickPackage, on the abbreviated slot. It produces a byte-identical cache and byte-identical resolution output. This PR is proposed as the preferable variant because:clearMetaon every abbreviated response, including npmjs.org's already-slim documents; this PR skips it via theContent-Typecheck.upgradedToFulltracking, the dualjsonForDiskpath) disappears.Only one of the two PRs should land.
Note on the media-type constant
The abbreviated media type
application/vnd.npm.install-v1+jsonis intentionally kept as a small localconstinfetch.ts. It also exists (module-private, unexported) in@pnpm/network.fetch, which uses it to build the requestAcceptheader. Two other placements were considered and rejected:@pnpm/network.fetch— the resolver only depends on that package as a devDependency (theFetchFromRegistryfunction is injected, not imported), so consuming a value from it would force a new runtime dependency and couple the resolver to the network package's internals.@pnpm/constants— viable (the resolver already imports the*_META_DIRconstants from there), but it would only fully de-duplicate if@pnpm/network.fetchalso took a dependency on@pnpm/constants, which it currently does not.Neither seemed worth a change to the dependency graph to share a single stable string, so the constant is duplicated locally with a comment.
Squash Commit Body
Checklist
pacquet/port, or the description notes what still needs porting.pnpm changeset) if this PR changes any published package.Written by an agent (GitHub Copilot CLI, claude-opus-4.8).
Summary by CodeRabbit
New Features
Bug Fixes
Tests