Repository navigation
perf(resolver): derive the link-target anchor once per importer - #14478
Conversation
Re-rendering a workspace link: target starts from the consuming importer's directory expressed as a suffix of the lockfile root — and that suffix was re-derived (validated, prefix-stripped) once per dependency edge at all three rendering sites, though both anchors are constant per importer. ImporterAnchor now derives it once: TreeCtx holds one per importer for the walk's canonical-resolution rendering and the pkgIdWithPatchHash fold (with a debug assertion pinning that a workspace edge never runs under the per-edge project-dir override, which fires for file: specifiers only), and the peer pass builds one per importer around its direct-deps loop. A disarmed anchor renders nothing, keeping every fallback exactly where it was. The graph sequencer's interner also stops hashing paths component by component: a PathNode wrapper compares and hashes the underlying OsStr's bytes, used by the plan ordering and the cycle search. On the 6,833-project reproduction from #14352 (87,630 workspace edges, warm non-noop lockfile-only update), the resolution stage drops from ~581 ms to ~505 ms (median of 8, sigma 4 ms), whole-run wall time from ~1.30 s to ~1.21 s, and the written lockfile is byte-identical. Related to #14352.
PR Summary by QodoCache link-target anchors per importer and optimize path hashing
AI Description
Diagram
High-Level Assessment
Files changed (15)
|
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Path: .coderabbit.yaml Review profile: CHILL Plan: Team Run ID: 📒 Files selected for processing (1)
Included review availability: Your plan provides up to 10 included reviews per hour; 7 remain after this review. 📝 WalkthroughWalkthroughThe resolver now computes importer anchors once and reuses them for ChangesAnchored links and workspace sequencing
Estimated code review effort: 3 (Moderate) | ~25 minutes Merge Risk: ⚪ Minimal · up to This localized performance change preserves lockfile output and has reported test coverage and benchmark improvements; no actionable merge-blocking risk remains beyond normal checks and review. Sequence Diagram(s)sequenceDiagram
participant TreeCtx
participant ImporterAnchor
participant render_workspace_resolution
TreeCtx->>ImporterAnchor: construct base_link_anchor
TreeCtx->>render_workspace_resolution: pass base_link_anchor
render_workspace_resolution->>ImporterAnchor: target_relative_to_importer(target)
ImporterAnchor-->>render_workspace_resolution: relative target or None
Suggested labels: Suggested reviewers: ✨ Finishing Touches📝 Generate docstrings
🧪 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 |
Code Review by Qodo
1. Changeset colon misused
|
PR Code Suggestions ✨Warning
No code suggestions found for the PR. |
Confidence Score: 5/5The PR appears safe to merge. No blocking failure remains. Reviews (2): Last reviewed commit: "fix(deps-restorer): re-export PathNode a..." | Re-trigger Greptile |
Micro-Benchmark ResultsLinux |
The consuming crates import it through this re-export; it was edited but left out of the previous commit.
Dismissed because a newer commit was pushed; Greptile will re-review the current head.
|
Code review by qodo was updated up to the latest commit 60ff04b |
PR Code Suggestions ✨Warning
No code suggestions found for the PR. |
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #14478 +/- ##
========================================
Coverage 88.90% 88.90%
========================================
Files 703 703
Lines 126022 126150 +128
========================================
+ Hits 112037 112157 +120
- Misses 13985 13993 +8 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
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. Bencher consumes pacquet@HEAD and pnpr@HEAD. The tables below show mean ± σ; Bencher thresholds on the minimum latency, which is far less perturbed by shared-runner contention (noise only adds time). Scenario: Isolated linker: fresh restore, cold cache + cold store
BENCHMARK_REPORT.json{
"results": [
{
"command": "pacquet@HEAD",
"mean": 2.4820136209599997,
"stddev": 0.1136839410028818,
"median": 2.43392539266,
"user": 1.6399706999999997,
"system": 1.70837574,
"min": 2.36011376516,
"max": 2.68446155916
},
{
"command": "pacquet@main",
"mean": 2.54095653396,
"stddev": 0.1290555924306562,
"median": 2.5163900771599996,
"user": 1.8538394,
"system": 1.8436834400000002,
"min": 2.38582520916,
"max": 2.8137013021599997
},
{
"command": "pnpr@HEAD",
"mean": 1.4941609634600002,
"stddev": 0.12521988682611726,
"median": 1.4721870091600002,
"user": 1.5791459999999997,
"system": 1.73637314,
"min": 1.36662724416,
"max": 1.7284537391600001
},
{
"command": "pnpr@main",
"mean": 1.52295146806,
"stddev": 0.10207288266505125,
"median": 1.48643894416,
"user": 1.6003470999999998,
"system": 1.63570924,
"min": 1.3891303591600002,
"max": 1.7107235301600001
}
]
}Scenario: Isolated linker: fresh restore, hot cache + hot store
BENCHMARK_REPORT.json{
"results": [
{
"command": "pacquet@HEAD",
"mean": 0.29380933740000004,
"stddev": 0.011381411605310676,
"median": 0.2912456465,
"user": 0.2957661399999999,
"system": 0.6565698400000001,
"min": 0.2800186075,
"max": 0.3191724695
},
{
"command": "pacquet@main",
"mean": 0.27118336830000006,
"stddev": 0.009798565371917981,
"median": 0.2689804845,
"user": 0.2830184399999999,
"system": 0.61143494,
"min": 0.2564535725,
"max": 0.2928669035
},
{
"command": "pnpr@HEAD",
"mean": 0.31302144069999993,
"stddev": 0.021668990044019575,
"median": 0.30486487650000005,
"user": 0.29895564,
"system": 0.6560461400000002,
"min": 0.2930729005,
"max": 0.3539921145
},
{
"command": "pnpr@main",
"mean": 0.3162097669,
"stddev": 0.014854855099620543,
"median": 0.3139748815,
"user": 0.28836343999999997,
"system": 0.66729814,
"min": 0.2938443505,
"max": 0.3500710145
}
]
}Scenario: Isolated linker: repeat install, hot cache + hot store
BENCHMARK_REPORT.json{
"results": [
{
"command": "pacquet@HEAD",
"mean": 0.008727619448316836,
"stddev": 0.0015589556222753397,
"median": 0.00847958528,
"user": 0.005764753465346535,
"system": 0.0035479224752475226,
"min": 0.00670086328,
"max": 0.016254624279999998
},
{
"command": "pacquet@main",
"mean": 0.008895531979300687,
"stddev": 0.0021868781272969032,
"median": 0.008045444280000001,
"user": 0.0057098167832167835,
"system": 0.003765289440559442,
"min": 0.00634266928,
"max": 0.01677530328
},
{
"command": "pnpr@HEAD",
"mean": 0.00905586081719009,
"stddev": 0.0008445066933618783,
"median": 0.00892459628,
"user": 0.005610043801652894,
"system": 0.004093043719008263,
"min": 0.00755113028,
"max": 0.01219592828
},
{
"command": "pnpr@main",
"mean": 0.008697248526710525,
"stddev": 0.0011643831638434607,
"median": 0.008611773780000002,
"user": 0.005449524342105264,
"system": 0.0038854734868421057,
"min": 0.00626776928,
"max": 0.01285708028
}
]
}Scenario: Isolated linker: repeat install, cold cache + hot store
BENCHMARK_REPORT.json{
"results": [
{
"command": "pacquet@HEAD",
"mean": 0.00918167180307692,
"stddev": 0.0015968416132435654,
"median": 0.008755529880000001,
"user": 0.005362117692307693,
"system": 0.004437457499999997,
"min": 0.00659048688,
"max": 0.01613160488
},
{
"command": "pacquet@main",
"mean": 0.007582577414296026,
"stddev": 0.0014053719024038694,
"median": 0.007212855880000001,
"user": 0.004636783826714801,
"system": 0.0034576364620938628,
"min": 0.0058312408800000005,
"max": 0.01756433688
},
{
"command": "pnpr@HEAD",
"mean": 0.007359422633926705,
"stddev": 0.0013107923529937296,
"median": 0.00695767688,
"user": 0.004612575078534031,
"system": 0.0032671572774869103,
"min": 0.00586475288,
"max": 0.012498397880000001
},
{
"command": "pnpr@main",
"mean": 0.006790754194641745,
"stddev": 0.000656218902640725,
"median": 0.006661800880000001,
"user": 0.004359502180685358,
"system": 0.002899720436137072,
"min": 0.00558367488,
"max": 0.01013869388
}
]
}Scenario: Isolated linker: fresh install, cold cache + cold store
BENCHMARK_REPORT.json{
"results": [
{
"command": "pacquet@HEAD",
"mean": 2.81416146502,
"stddev": 0.05032001058327084,
"median": 2.83514149052,
"user": 1.9480978400000002,
"system": 1.53435834,
"min": 2.70959814952,
"max": 2.85997912452
},
{
"command": "pacquet@main",
"mean": 2.7380527566200006,
"stddev": 0.08713062600628774,
"median": 2.7011972595200002,
"user": 1.7408154399999998,
"system": 1.38849824,
"min": 2.65220392652,
"max": 2.90385431352
},
{
"command": "pnpr@HEAD",
"mean": 1.5178087876200002,
"stddev": 0.1118309716565469,
"median": 1.49569343452,
"user": 1.13738594,
"system": 1.2671861399999997,
"min": 1.37831646052,
"max": 1.6715879485199998
},
{
"command": "pnpr@main",
"mean": 1.58438299002,
"stddev": 0.08501230861759693,
"median": 1.58530846452,
"user": 1.33477414,
"system": 1.48851924,
"min": 1.4674589645199998,
"max": 1.74349700352
}
]
}Scenario: Isolated linker: fresh install, hot cache + hot store
BENCHMARK_REPORT.json{
"results": [
{
"command": "pacquet@HEAD",
"mean": 0.40431228782,
"stddev": 0.033895817821853386,
"median": 0.39242308892,
"user": 0.46900297999999996,
"system": 0.70770422,
"min": 0.37208725292000006,
"max": 0.46809859692000005
},
{
"command": "pacquet@main",
"mean": 0.4489488228200001,
"stddev": 0.0722286217627331,
"median": 0.45264682892,
"user": 0.5477660799999999,
"system": 0.72206492,
"min": 0.36824221492000003,
"max": 0.62233806192
},
{
"command": "pnpr@HEAD",
"mean": 0.35755668032,
"stddev": 0.026046428152397178,
"median": 0.35720924292,
"user": 0.27698517999999994,
"system": 0.62767002,
"min": 0.31538274992000004,
"max": 0.39879347192000003
},
{
"command": "pnpr@main",
"mean": 0.43075888312000005,
"stddev": 0.059142013276915366,
"median": 0.44425820192000004,
"user": 0.32370748000000005,
"system": 0.69289322,
"min": 0.35270147692000003,
"max": 0.50318886992
}
]
}Scenario: Isolated linker: fresh install, cold cache + hot store
BENCHMARK_REPORT.json{
"results": [
{
"command": "pacquet@HEAD",
"mean": 2.3356875590400006,
"stddev": 0.14695004656076555,
"median": 2.3238461367400003,
"user": 1.3057410399999998,
"system": 1.0450186399999999,
"min": 2.15583724324,
"max": 2.5539261802400004
},
{
"command": "pacquet@main",
"mean": 2.2451264795400006,
"stddev": 0.3965146707762084,
"median": 2.0930145122400003,
"user": 1.14081944,
"system": 0.9893772399999998,
"min": 1.86311411624,
"max": 2.95643981224
},
{
"command": "pnpr@HEAD",
"mean": 0.42158861404000003,
"stddev": 0.07290135354792089,
"median": 0.41214067724000003,
"user": 0.3359491399999999,
"system": 0.68368264,
"min": 0.31763814124,
"max": 0.58345507324
},
{
"command": "pnpr@main",
"mean": 0.30497669914,
"stddev": 0.016358997836873813,
"median": 0.30175055823999997,
"user": 0.20825354000000001,
"system": 0.56298804,
"min": 0.28987281323999997,
"max": 0.34637530624
}
]
}Scenario: Isolated linker: fresh resolve, hot cache, offline
BENCHMARK_REPORT.json{
"results": [
{
"command": "pacquet@HEAD",
"mean": 0.26373224914000004,
"stddev": 0.023704575298010424,
"median": 0.25144110664,
"user": 0.24203552333333336,
"system": 0.06812681999999999,
"min": 0.24145970264,
"max": 0.31668652664
},
{
"command": "pacquet@main",
"mean": 0.26518072918545454,
"stddev": 0.013019315246049117,
"median": 0.26496041364,
"user": 0.2394623490909091,
"system": 0.06919495636363636,
"min": 0.24570936364,
"max": 0.28638452464
},
{
"command": "pnpr@HEAD",
"mean": 0.10649890388000002,
"stddev": 0.004030838325571012,
"median": 0.10552871664,
"user": 0.04155832,
"system": 0.0158634,
"min": 0.09655225064,
"max": 0.11546186064000001
},
{
"command": "pnpr@main",
"mean": 0.10782652626068966,
"stddev": 0.007228179115003006,
"median": 0.10771979164,
"user": 0.041320612413793104,
"system": 0.018371388965517238,
"min": 0.09642052264,
"max": 0.12756451664
}
]
}Scenario: Isolated linker: peer-heavy resolve, hot cache, offline
BENCHMARK_REPORT.json{
"results": [
{
"command": "pacquet@HEAD",
"mean": 0.7066737156088888,
"stddev": 0.06960214614375868,
"median": 0.71028550872,
"user": 0.7282113111111111,
"system": 0.1647756622222222,
"min": 0.61604077272,
"max": 0.81706316072
},
{
"command": "pacquet@main",
"mean": 0.7119634863866666,
"stddev": 0.11237012858183114,
"median": 0.7388507587200001,
"user": 0.7376751999999999,
"system": 0.16491899555555556,
"min": 0.47928171172000006,
"max": 0.87022399772
},
{
"command": "pnpm@HEAD",
"mean": 3.4712022934977775,
"stddev": 0.42527663118542686,
"median": 3.2994250437200003,
"user": 5.340032088888888,
"system": 0.28976688444444443,
"min": 3.0451682517200003,
"max": 4.29065780872
}
]
}Scenario: Isolated linker: fresh restore, cold cache + cold store + cold pnpr
BENCHMARK_REPORT.json{
"results": [
{
"command": "pacquet@HEAD",
"mean": 4.58228948654,
"stddev": 0.13590474254016824,
"median": 4.56720472324,
"user": 2.08171636,
"system": 1.95113436,
"min": 4.427797367739999,
"max": 4.91859790674
},
{
"command": "pacquet@main",
"mean": 4.824379907139999,
"stddev": 0.16784594431641015,
"median": 4.86840872824,
"user": 2.3173416599999994,
"system": 2.1666564599999996,
"min": 4.49888312374,
"max": 5.00351916274
},
{
"command": "pnpr@HEAD",
"mean": 3.77138086644,
"stddev": 0.3627782472331101,
"median": 3.59396622024,
"user": 2.0588505599999998,
"system": 2.09789916,
"min": 3.4897627727400002,
"max": 4.61497259174
},
{
"command": "pnpr@main",
"mean": 4.05296414654,
"stddev": 0.7637395735545658,
"median": 3.8097408767400003,
"user": 2.3658671599999996,
"system": 2.35874956,
"min": 3.63871890674,
"max": 6.17119413674
}
]
}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. Comparable to that scenario head-to-head.
BENCHMARK_REPORT.json{
"results": [
{
"command": "pacquet@HEAD",
"mean": 0.20177326128307696,
"stddev": 0.01606538942424954,
"median": 0.19525328936000003,
"user": 0.2744386815384615,
"system": 0.23999796923076921,
"min": 0.18449489136000002,
"max": 0.23567216136000002
},
{
"command": "pacquet@main",
"mean": 0.1875347608215385,
"stddev": 0.010803622210116411,
"median": 0.18365603536000003,
"user": 0.2570375276923077,
"system": 0.22046258461538465,
"min": 0.16591932936,
"max": 0.20660783836000002
},
{
"command": "pnpr@HEAD",
"mean": 0.2156233365138462,
"stddev": 0.014788052707543449,
"median": 0.21263089236000002,
"user": 0.27889037384615384,
"system": 0.21583927692307694,
"min": 0.19842754136000001,
"max": 0.25360409536
},
{
"command": "pnpr@main",
"mean": 0.21954548069333338,
"stddev": 0.015675436405264455,
"median": 0.21959072986,
"user": 0.2768863033333333,
"system": 0.22957536666666667,
"min": 0.19678507736,
"max": 0.24248534036000002
}
]
} |
Summary
Related to #14352. A fresh profile puts the largest remaining resolution cost in the
link:re-rendering introduced by #14396's rel-space fast paths: the importer-side anchor — the consuming project's directory expressed as a suffix of the lockfile root — was re-derived (absolute-path validation plus prefix strip) once per dependency edge at all three rendering sites, though both anchors are constant per importer. On the reproduction that's ~87k derivations of a value with 6,833 distinct results.ImporterAnchorderives the suffix once and serves the per-edge renderings.TreeCtxholds one per importer for the walk's canonical-resolution rendering and thepkgIdWithPatchHashfold — two anchors, one per lockfile-dir spelling those sites used, so the cache changes no behavior even where the spellings differ — and the peer pass builds one per importer around its direct-deps loop. A disarmed anchor (dot-carrying, non-absolute, or outside-root inputs) renders nothing, keeping every absolute-space fallback exactly where it was. A debug assertion pins the one equivalence this relies on: aworkspace:edge never runs under the per-edge project-dir override, which fires forfile:specifiers only — exercised by the whole debug-mode suite.PathNodegives the graph sequencer's interner byte-based path hashing/equality (Path's ownHash/Eqwalk component by component), used by the plan ordering and the cycle search.Measurements
On the issue's reproduction (6,833 projects, 87,630
workspace:*edges; warm non-noop lockfile-only update per its README protocol; M-series Mac):resolutionstage (median of 8, σ ≈ 4 ms)The written
pnpm-lock.yamlis byte-identical, and all 406 resolver + scheduler tests pass (the anchor-API rewrite included).Cumulative for #14352: the warm lockfile-only update has gone from ~2.43 s (before #14379) to ~1.21 s, versus the ~1.6 s the issue reports for Yarn 4.18 on the same protocol.
Squash Commit Body
Checklist
already linked to it solves it.
pnpm/port, or the description notes what still needs porting. (Rust-onlyinternal perf work with no user-visible behavior change; no TypeScript-side
port is needed.)
pnpm changeset) if this PR changes any publishedpackage. Keep it short and written for pnpm users — it becomes a release note.
Written by an agent (Claude Code, claude-fable-5).
Need help on this PR? Tag
@codesmith-botwith what you need. Autofix is disabled.Summary by CodeRabbit
Performance
Bug Fixes