Repository navigation
refactor(resolving-npm-resolver): decide the pick's mirror shortcuts in one pure route - #17032
Conversation
…in one pure route Each read a pick tries before the registry checked its own eligibility: - the uncacheable gate in mirror_fast_paths - the spec-type and flag checks in version_spec_pick - range_pick_is_stable and range_can_reuse_unvalidated_mirror - the scope and ETag checks in fresh_unvalidated_mirror_pick - the offline-range and release-age checks in published_by_pick - the cache-first condition in pick_package - the private-route rule in disk_fallback The new pick_package::route module decides them all from the request, the policy, and the mirror's header line: - MirrorShortcuts::decide returns which of the four pre-permit reads apply: exact_version, dominant_lockfile_version, unvalidated_mirror, and written_after with the release-age cutoff. - unvalidated_mirror_is_fresh holds the mtime age rule, and UNVALIDATED_MIRROR_MAX_AGE moves with it. - DiskFirst::decide (Never, Always, UnlessUncacheable) gates the read after the fetch permit. - fetch_failure_falls_back is the private-route rule for a failed fetch. The shortcuts keep only their content checks: whether the mirror holds the version, whether its pick agrees, and the mtime against the age or cutoff. The mirror's mtime is still read only by a shortcut that needs it. No behavior changes. Table-driven tests cover each decision. The offline range exclusion from the release-age shortcut had no test before, and removing it now fails one. Part of pnpm/tasks#146. Co-Authored-By: Claude Opus 5.5 <[email protected]>
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info
📝 Walkthrough
Merge Risk: ⚪ Minimal · up to
|
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #17032 +/- ##
=======================================
Coverage 92.55% 92.55%
=======================================
Files 1777 1779 +2
Lines 228522 228563 +41
=======================================
+ Hits 211499 211543 +44
+ Misses 17023 17020 -3 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
Micro-Benchmark ResultsLinux |
Same-run regression checkHEAD and main are measured on the same runner. The tolerance is 5% of the main median or 2 ms, whichever is larger. A regression requires both the median slowdown and the gap between the fastest retained HEAD sample and slowest retained main sample to exceed this tolerance, after trimming up to 10% from each tail. Suspected regressions are rerun once with target order reversed and only fail if reproduced. This conservative noise guard is not a statistical confidence interval. Inconclusive rows do not fail the check. They remain visible for performance review. Bencher retains absolute minimum timings for historical tracking; historical alerts do not gate this PR. Sequential measurements can still be affected by runner drift.
Integrated-Benchmark Report (Linux)Commit: Regular scenarios report direct and pnpr installs. The peer-heavy resolver scenario compares current Rust, main Rust, and TypeScript pnpm; the linked and injected workspace scenarios compare current Rust against main Rust. Bencher consumes pacquet@HEAD and pnpr@HEAD. The tables below show mean ± σ. Bencher tracks absolute minimum latency; PR regression checks compare HEAD and main samples from the same runner. Historical timing alerts do not gate PRs. Scenario: Isolated linker: fresh restore, cold cache + cold store
BENCHMARK_REPORT.json{
"results": [
{
"command": "pacquet@HEAD",
"mean": 2.3438979245,
"stddev": 0.11422433382257574,
"median": 2.3037143121000003,
"user": 1.2198740999999997,
"system": 1.26715736,
"min": 2.2509289136,
"max": 2.6349100286000002
},
{
"command": "pacquet@main",
"mean": 2.3365334043,
"stddev": 0.09474199167039568,
"median": 2.3167654816,
"user": 1.1767553,
"system": 1.29109846,
"min": 2.2536326606,
"max": 2.5715167666000003
},
{
"command": "pnpr@HEAD",
"mean": 1.3981808704,
"stddev": 0.10401874824672323,
"median": 1.3899265316,
"user": 1.1365162999999998,
"system": 1.1609964600000002,
"min": 1.2862210076,
"max": 1.5947041946000002
},
{
"command": "pnpr@main",
"mean": 1.4137282472000003,
"stddev": 0.11839825720161522,
"median": 1.3662860196,
"user": 1.0903676,
"system": 1.2228055599999998,
"min": 1.3028455076,
"max": 1.6339559756000002
}
]
}Scenario: Isolated linker: fresh restore, hot cache + hot store
BENCHMARK_REPORT.json{
"results": [
{
"command": "pacquet@HEAD",
"mean": 0.29318161186,
"stddev": 0.010565053640808432,
"median": 0.2893866433600001,
"user": 0.34918442,
"system": 0.7655852799999999,
"min": 0.28451503336000006,
"max": 0.31662231636000004
},
{
"command": "pacquet@main",
"mean": 0.29134917016000006,
"stddev": 0.011321305550963631,
"median": 0.28832387186,
"user": 0.33498091999999996,
"system": 0.78912698,
"min": 0.28276323136000003,
"max": 0.32174636136000007
},
{
"command": "pnpr@HEAD",
"mean": 0.43930794316000005,
"stddev": 0.11145265092111777,
"median": 0.45496523586000004,
"user": 0.50599172,
"system": 1.09023278,
"min": 0.31482465436000007,
"max": 0.57926094636
},
{
"command": "pnpr@main",
"mean": 0.31741613916,
"stddev": 0.005622652639672289,
"median": 0.3182451418600001,
"user": 0.34695792000000003,
"system": 0.81074798,
"min": 0.30670816436000004,
"max": 0.32535781336
}
]
}Scenario: Isolated linker: repeat install, hot cache + hot store
BENCHMARK_REPORT.json{
"results": [
{
"command": "pacquet@HEAD",
"mean": 0.009092610929523811,
"stddev": 0.000622086037095533,
"median": 0.009014247620000002,
"user": 0.0052093378231292545,
"system": 0.004746172789115645,
"min": 0.007613476619999999,
"max": 0.011000579620000001
},
{
"command": "pacquet@main",
"mean": 0.009040601493333333,
"stddev": 0.0013889973571758214,
"median": 0.008901139620000002,
"user": 0.0053029300000000034,
"system": 0.004444534000000002,
"min": 0.007746367620000001,
"max": 0.029287523620000002
},
{
"command": "pnpr@HEAD",
"mean": 0.008507531025498278,
"stddev": 0.0005395743950543903,
"median": 0.00846265562,
"user": 0.0052603092096219954,
"system": 0.0039483147766323015,
"min": 0.007430472620000001,
"max": 0.01055877862
},
{
"command": "pnpr@main",
"mean": 0.00863305405260188,
"stddev": 0.0006675513926523101,
"median": 0.008534609620000001,
"user": 0.005160968087774295,
"system": 0.004172923510971788,
"min": 0.007512146620000001,
"max": 0.012287149620000002
}
]
}Scenario: Isolated linker: repeat install, cold cache + hot store
BENCHMARK_REPORT.json{
"results": [
{
"command": "pacquet@HEAD",
"mean": 0.008141470540638976,
"stddev": 0.0004252979541275584,
"median": 0.00814996894,
"user": 0.0049863514376996855,
"system": 0.003943777507987219,
"min": 0.00710579694,
"max": 0.010858900940000001
},
{
"command": "pacquet@main",
"mean": 0.008147823479249142,
"stddev": 0.00051247373318617,
"median": 0.00809582694,
"user": 0.005106081911262797,
"system": 0.0037767283276450513,
"min": 0.0072080489400000005,
"max": 0.010945442940000001
},
{
"command": "pnpr@HEAD",
"mean": 0.008054905977037036,
"stddev": 0.0004044065160317706,
"median": 0.00800675094,
"user": 0.004978771043771043,
"system": 0.0038452283501683496,
"min": 0.00721333894,
"max": 0.00998119094
},
{
"command": "pnpr@main",
"mean": 0.008150890408401494,
"stddev": 0.00042710068593493643,
"median": 0.00808027794,
"user": 0.005164918215613384,
"system": 0.003732119851301115,
"min": 0.00731589094,
"max": 0.01074315294
}
]
}Scenario: Isolated linker: fresh install, cold cache + cold store
BENCHMARK_REPORT.json{
"results": [
{
"command": "pacquet@HEAD",
"mean": 2.5350084152399996,
"stddev": 0.13370109651193765,
"median": 2.48684564624,
"user": 2.1468857199999998,
"system": 1.7457574799999995,
"min": 2.45189022674,
"max": 2.87849994774
},
{
"command": "pacquet@main",
"mean": 2.4953291078399995,
"stddev": 0.031066301685335442,
"median": 2.4896893257399997,
"user": 2.02360332,
"system": 1.5727593800000002,
"min": 2.46419625874,
"max": 2.57698486374
},
{
"command": "pnpr@HEAD",
"mean": 1.5973744665400003,
"stddev": 0.12201133028467413,
"median": 1.62446096874,
"user": 1.3442246199999999,
"system": 1.3670513799999997,
"min": 1.38852543674,
"max": 1.7540492567400001
},
{
"command": "pnpr@main",
"mean": 1.5250991691400002,
"stddev": 0.09331004268669499,
"median": 1.5048769907400001,
"user": 1.37595602,
"system": 1.3316106799999998,
"min": 1.4261648297399998,
"max": 1.73378078474
}
]
}Scenario: Isolated linker: fresh install, hot cache + hot store
BENCHMARK_REPORT.json{
"results": [
{
"command": "pacquet@HEAD",
"mean": 0.44612621846000006,
"stddev": 0.018204707865164965,
"median": 0.44138754676,
"user": 0.6301427000000001,
"system": 0.7454945800000001,
"min": 0.42620831276,
"max": 0.47792093176
},
{
"command": "pacquet@main",
"mean": 0.45192252086000007,
"stddev": 0.015490644087548949,
"median": 0.44817662276000003,
"user": 0.6530693,
"system": 0.7193256800000001,
"min": 0.43506990976,
"max": 0.47977878976
},
{
"command": "pnpr@HEAD",
"mean": 0.29154975496,
"stddev": 0.01001312336400722,
"median": 0.29111572525999996,
"user": 0.252502,
"system": 0.57237128,
"min": 0.27825806076,
"max": 0.30559019576
},
{
"command": "pnpr@main",
"mean": 0.3520516987600001,
"stddev": 0.08556371581655292,
"median": 0.30621841476,
"user": 0.3139439,
"system": 0.6885047799999999,
"min": 0.28502881176,
"max": 0.49779955376
}
]
}Scenario: Isolated linker: fresh install, cold cache + hot store
BENCHMARK_REPORT.json{
"results": [
{
"command": "pacquet@HEAD",
"mean": 1.6461572435,
"stddev": 0.10334149153558726,
"median": 1.6075144694,
"user": 0.9539340600000001,
"system": 0.9546226599999998,
"min": 1.5886914439,
"max": 1.9348191739
},
{
"command": "pacquet@main",
"mean": 1.6429954354000003,
"stddev": 0.10399695613212812,
"median": 1.6147498994,
"user": 0.9249624599999999,
"system": 0.94634196,
"min": 1.5886511059000001,
"max": 1.9359750809000003
},
{
"command": "pnpr@HEAD",
"mean": 0.28165865740000007,
"stddev": 0.011337226457402,
"median": 0.28653253190000005,
"user": 0.25273566000000003,
"system": 0.5287999600000001,
"min": 0.26234250890000005,
"max": 0.29446704690000003
},
{
"command": "pnpr@main",
"mean": 0.2732936361,
"stddev": 0.014749696395078168,
"median": 0.27283424440000004,
"user": 0.21704126,
"system": 0.52994826,
"min": 0.2506115929,
"max": 0.2925657849
}
]
}Scenario: Isolated linker: fresh resolve, hot cache, offline
BENCHMARK_REPORT.json{
"results": [
{
"command": "pacquet@HEAD",
"mean": 0.22907601586666662,
"stddev": 0.018600427226030083,
"median": 0.2238139667,
"user": 0.20984455666666665,
"system": 0.07637479,
"min": 0.2075070242,
"max": 0.2653455852
},
{
"command": "pacquet@main",
"mean": 0.22690975691428572,
"stddev": 0.019357715164461158,
"median": 0.2237913497,
"user": 0.21252806857142856,
"system": 0.07871189714285713,
"min": 0.2075282842,
"max": 0.2746883122
},
{
"command": "pnpr@HEAD",
"mean": 0.08948696376666666,
"stddev": 0.00254336546071998,
"median": 0.0880470837,
"user": 0.030403873333333324,
"system": 0.014080071999999999,
"min": 0.08628870620000001,
"max": 0.0952010622
},
{
"command": "pnpr@main",
"mean": 0.09145861471515153,
"stddev": 0.0023175620105692985,
"median": 0.0920146282,
"user": 0.0327380793939394,
"system": 0.014934492121212123,
"min": 0.08656005620000001,
"max": 0.09521278320000001
}
]
}Scenario: Isolated linker: peer-heavy resolve, hot cache, offline
BENCHMARK_REPORT.json{
"results": [
{
"command": "pacquet@HEAD",
"mean": 0.24151702890444446,
"stddev": 0.013140100704814762,
"median": 0.23984558846,
"user": 0.2506972244444444,
"system": 0.05569835777777778,
"min": 0.22551257246,
"max": 0.25937422646
},
{
"command": "pacquet@main",
"mean": 0.2351885012377778,
"stddev": 0.0125582038719515,
"median": 0.23496571646,
"user": 0.24164800222222219,
"system": 0.05712769111111111,
"min": 0.22029726046,
"max": 0.26483851946000003
},
{
"command": "pnpm@HEAD",
"mean": 3.784287482126667,
"stddev": 0.1630069561691188,
"median": 3.77310875046,
"user": 5.788350335555555,
"system": 0.34777502444444447,
"min": 3.52301226146,
"max": 4.04555425546
}
]
}Scenario: Isolated linker: linked-workspace resolve, hot cache, offline
BENCHMARK_REPORT.json{
"results": [
{
"command": "pacquet@HEAD",
"mean": 0.20200558976285718,
"stddev": 0.005862944809655519,
"median": 0.20188634262000002,
"user": 0.16140836285714283,
"system": 0.07815602285714286,
"min": 0.19307520112,
"max": 0.21185270812
},
{
"command": "pacquet@main",
"mean": 0.20502529912000003,
"stddev": 0.005503170277561106,
"median": 0.20451004212,
"user": 0.17055495076923072,
"system": 0.07423599538461538,
"min": 0.19534709312,
"max": 0.21376386112
}
]
}Scenario: Isolated linker: injected workspace repeat install, hot cache + hot store
BENCHMARK_REPORT.json{
"results": [
{
"command": "pacquet@HEAD",
"mean": 0.08506496772352941,
"stddev": 0.002833427073480814,
"median": 0.08545891289999999,
"user": 0.032339170588235294,
"system": 0.0590978294117647,
"min": 0.0797143924,
"max": 0.0920149914
},
{
"command": "pacquet@main",
"mean": 0.08266002617777778,
"stddev": 0.0021846233647958,
"median": 0.0820391464,
"user": 0.03181464444444445,
"system": 0.05712127222222222,
"min": 0.07939909839999999,
"max": 0.0896486654
}
]
}Scenario: Isolated linker: fresh restore, cold cache + cold store + cold pnpr
BENCHMARK_REPORT.json{
"results": [
{
"command": "pacquet@HEAD",
"mean": 4.47819219446,
"stddev": 0.08849763864832308,
"median": 4.47178557786,
"user": 1.52324096,
"system": 1.5716118000000001,
"min": 4.37744151386,
"max": 4.65344134186
},
{
"command": "pacquet@main",
"mean": 4.43571440066,
"stddev": 0.1270435357508586,
"median": 4.39107027336,
"user": 1.44655296,
"system": 1.4543570999999997,
"min": 4.36731595586,
"max": 4.78179816486
},
{
"command": "pnpr@HEAD",
"mean": 3.49867523996,
"stddev": 0.07285870711417972,
"median": 3.47846199536,
"user": 1.32830996,
"system": 1.3757107,
"min": 3.42380150686,
"max": 3.66876471586
},
{
"command": "pnpr@main",
"mean": 3.5084540118599996,
"stddev": 0.12283926065338215,
"median": 3.47045215336,
"user": 1.3058734600000002,
"system": 1.3897756999999997,
"min": 3.39908664186,
"max": 3.79144240986
}
]
}Scenario: GVS linker: fresh restore, hot cache + hot storeSame install as the isolated fresh-restore hot/hot scenario, into the shared virtual store, the layout pnpm 12 installs into by default. Scenarios run on separate machines, so compare main and branch within each table.
BENCHMARK_REPORT.json{
"results": [
{
"command": "pacquet@HEAD",
"mean": 0.12026627946000003,
"stddev": 0.008740497286229916,
"median": 0.11937722396,
"user": 0.14900317818181816,
"system": 0.12414568909090908,
"min": 0.11050551446000001,
"max": 0.15470653046000002
},
{
"command": "pacquet@main",
"mean": 0.19164495061384618,
"stddev": 0.027018068101747287,
"median": 0.19347428346,
"user": 0.23119112923076918,
"system": 0.18282628,
"min": 0.15187719646,
"max": 0.23523174246
},
{
"command": "pnpr@HEAD",
"mean": 0.22493955296,
"stddev": 0.019922313994448295,
"median": 0.22728352446,
"user": 0.24991511,
"system": 0.21065744666666664,
"min": 0.19922836946,
"max": 0.25167699046
},
{
"command": "pnpr@main",
"mean": 0.16605708656,
"stddev": 0.058423816205311195,
"median": 0.13019900896,
"user": 0.19045716,
"system": 0.15890917999999996,
"min": 0.12655179246,
"max": 0.26008066046000006
}
]
}Scenario: Store only: unlocked direct deps, cold cache + hot storeStore-only install (
BENCHMARK_REPORT.json{
"results": [
{
"command": "pacquet@HEAD",
"mean": 1.1265889001799998,
"stddev": 0.0215499895343932,
"median": 1.12780273528,
"user": 0.5146650600000001,
"system": 0.21402525999999997,
"min": 1.09416889878,
"max": 1.1522687837799999
},
{
"command": "pacquet@main",
"mean": 1.17688357508,
"stddev": 0.08024097902248124,
"median": 1.1405619907799998,
"user": 0.6155192599999999,
"system": 0.24695996,
"min": 1.1031260297799999,
"max": 1.29935432678
}
]
} |
|
@coderabbitai review |
There was a problem hiding this comment.
Your trial has ended. Reactivate Greptile to resume code reviews.
PR Summary by QodoCentralize npm mirror shortcut decisions in a pure pick route
AI Description
Diagram
High-Level Assessment
Files changed (5)
|
|
Code Review by Qodo
1. The claimed speedup lacks proof
|
PR Code Suggestions ✨Warning
No code suggestions found for the PR. |
RouteInputs computed release_age_applies_to for every pick that reached the mirror shortcuts. That included a pinned version the mirror answers, which the old code never asked about. The inputs now hold the pick policy and the package name, so the lookup runs only where it is needed: - range_pick_is_stable tests it last, after the cheap flags. - written_after, moved onto RouteInputs, runs only after the other shortcuts missed. A pinned-version hit does no lookup, and a stable range that falls through does at most two. The old code did up to three, because it checked range stability twice. The route tests now build a real PackagePickPolicy, with a minimumReleaseAgeExclude rule for the excluded cases. Co-Authored-By: Claude Opus 5.5 <[email protected]>
There was a problem hiding this comment.
Your trial has ended. Reactivate Greptile to resume code reviews.
|
Code review by qodo was updated up to the latest commit a70b6ee |
PR Code Suggestions ✨Warning
No code suggestions found for the PR. |
|
On Qodo's "The claimed speedup lacks proof": this PR claims no speedup over main, so there is nothing to benchmark. a70b6ee restores the laziness the first commit lost, where The lookup counts in the description come from the code paths:
No Written by an agent (Claude Code, claude-opus-5-5). |
Summary
Third step of pnpm/tasks#146 (Related to pnpm/tasks#146), after #17024 and #17028. It covers the pick side of the task's "no explicit state machine" item. There is no behavior change.
Before a pick asks the registry, it can try several mirror reads. Each read checked its own eligibility in a different place:
mirror_fast_pathsMirrorShortcuts::decideversion_spec_pickMirrorShortcuts::exact_versionrange_pick_is_stableMirrorShortcuts::dominant_lockfile_versionrange_can_reuse_unvalidated_mirror+ scope/ETag checksMirrorShortcuts::unvalidated_mirror(+unvalidated_mirror_is_fresh)published_by_pickRouteInputs::written_afterpick_packageDiskFirst::decidedisk_fallbackfetch_failure_falls_backThe new
pick_package::routemodule is pure. It decides from the request, the policy, and the mirror's header line. The reads keep only their content checks: whether the mirror holds the version, whether its pick agrees, and the mtime against the age or the cutoff. The mirror mtime is still read only by a shortcut that needs it, so the hot path gains nostat.The release-age exclusion (
release_age_applies_to, a policy lookup) stays lazy.RouteInputsholds the pick policy, not a precomputed answer:range_pick_is_stablechecks it last, after the cheap flags.RouteInputs::written_afterruns only after the other shortcuts missed.A pinned version the mirror answers does no lookup. A stable range that falls through does at most two, where the old code did up to three because it checked range stability twice.
Tests. Table-driven unit tests cover each decision. All 623 tests of
pnpm-resolving-npm-resolverpass. Sabotage checks:pnpm updateexclusion from the ETag-less shortcut fails the new test and 4 existing integration tests.Still open on the task. These are left for later PRs:
cached_pick/handle_cache_hit).No changeset, since nothing changes for users.
Squash Commit Body
Checklist
already linked to it solves it.
are implemented in every affected version.
Written by an agent (Claude Code, claude-opus-5-5).
🤖 Generated with Claude Code
Summary by CodeRabbit