Repository navigation
perf(resolver): shrink the peer walk's per-occurrence state - #13844
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)
🚧 Files skipped from review as they are similar to previous changes (1)
📝 WalkthroughWalkthroughThe resolver lazily stores lockfile state, shares realized child maps through ChangesPeer resolution memory optimization
Estimated code review effort: 3 (Moderate) | ~20 minutes Possibly related PRs
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 |
PR Summary by Qodoperf(resolver): reduce peer-walk memory per occurrence
AI Description
Diagram
High-Level Assessment
Files changed (11)
|
Confidence Score: 5/5The PR appears safe to merge. No blocking failure remains. Reviews (4): Last reviewed commit: "test(resolver): assert the pending-edge ..." | Re-trigger Greptile |
Code Review by Qodo
1. Key set retains allocation
|
PR Code Suggestions ✨Warning
No code suggestions found for the PR. |
There was a problem hiding this comment.
Actionable comments posted: 2
🤖 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 @.changeset/peer-resolution-memory.md:
- Around line 1-2: Update the changeset package key from "pnpm" to "pacquet" so
the Rust resolver change under pnpm/crates targets the required Rust wrapper
release.
- Line 5: Rewrite the changeset entry to describe the user-facing outcome:
reduced peak memory usage during peer dependency resolution. Remove references
to internal occurrence expansion, peer dependency graph cycles, and per-node
state while keeping the note concise.
🪄 Autofix
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: 39e46fdb-ea96-40a2-8691-45d719a6345a
📒 Files selected for processing (11)
.changeset/peer-resolution-memory.mdpnpm/crates/resolving-deps-resolver/src/resolve_dependency_tree/walk.rspnpm/crates/resolving-deps-resolver/src/resolve_dependency_tree/workspace_ctx.rspnpm/crates/resolving-deps-resolver/src/resolve_dependency_tree/workspace_ctx/tests.rspnpm/crates/resolving-deps-resolver/src/resolve_peers.rspnpm/crates/resolving-deps-resolver/src/resolve_peers/cache.rspnpm/crates/resolving-deps-resolver/src/resolve_peers/finalize.rspnpm/crates/resolving-deps-resolver/src/resolve_peers/test_support.rspnpm/crates/resolving-deps-resolver/src/resolve_peers/tests.rspnpm/crates/resolving-deps-resolver/src/resolve_peers/walker.rspnpm/crates/resolving-deps-resolver/src/resolved_tree.rs
|
Filed the lockfile nondeterminism noted in the Correctness section separately as #13846 — four consecutive stock runs of the same install produce four distinct lockfiles, with the resolved package set identical and the churn confined to That is what forced the pairwise-distance comparison in this PR instead of a straight lockfile diff. |
Resolving peer dependencies realizes one tree node per distinct root-to-package path. In a workspace whose peer graph is highly cyclic that count is enormous — resolving the bit monorepo's env packages realizes 2,008,313 occurrences to produce a 6,133-node graph — so every byte held per occurrence, and every allocation made per visit, is paid two million times. Three changes, none of which alter what the walk resolves: - `DependenciesTreeNode` kept four wanted-lockfile carry-over fields inline. All four are `None` on a fresh resolution, which is every node the resolver produces today, yet they cost ~88 bytes on each node. Moving them behind a boxed `LockedResolution` takes the node from 144 to 64 bytes and the tree's table from 676 MB to 356 MB. - `TreeChildren::Realized` held the children map by value, so `realize_children` cloned the whole `BTreeMap` — every key `String` included — on each revisit of an already-realized node, and stored a second copy on the node. It is immutable once built, so share it through an `Arc` instead. - `add_graph_child_or_pending` buffered a pending edge per occurrence. A parent reached through many occurrences pushes the identical `(parent_dep_path, alias, child_node_id)` triple repeatedly, and replaying a duplicate is a no-op: it resolves the same `DepPath` and `or_insert`s the same slot. Dropping repeats takes the buffer from 2,224,865 entries to 114,778. Replaying the same install through @pnpm/napi, peak RSS drops from 3670 MB to 3224 MB (-12%, n=3 each, non-overlapping) with no change in wall time. The resulting lockfile stays within the engine's existing run-to-run variance: two stock runs differ from each other by 197 diff lines, while stock and patched differ by 173 and 88, churning the same packages either way. This does not address the underlying expansion — 91% of full walks (171,508 of 188,707) end in a cycle, and cycle-resolved walks are deliberately never cached (#5108), so the peers cache hits 155 times in 188,862 lookups and nearly every occurrence re-walks its subtree. Refs #13681
a452962 to
3623678
Compare
|
Rebased onto Changeset now targets Added regression coverage for the dedup invariant (@greptile-apps' P2), plus four more. None of these three savings changes observable resolution, so nothing in the existing suite notices if they regress — which is exactly why they needed tests rather than a narrative comment. I verified each one fails when its fix is reverted: neutering the guard turns The dedup test pins both halves deliberately, since only one of them is the risky direction: repeats collapse, but two distinct triples sharing a Note the footprint assertion is a new convention here — there are no other Re-measured after the rebase, since 324 tests pass; clippy |
|
The P2 has been addressed thoroughly. All three tests cover the right cases:
On the footprint assertion — keep it. It's the only thing that actually guards the biggest saving, and the The new changeset is correctly targeting |
Each of the three savings has an invariant that is easy to undo by accident, and none of them changes observable resolution, so nothing in the existing suite notices if they regress. - `tree_node_keeps_its_per_occurrence_footprint_small` fails the moment a field is inlined back onto the node. 56 bytes is the current layout, not a budget with room in it. - `repeated_pending_peer_edges_are_buffered_once` pins both halves of the dedup: repeats collapse, but two distinct triples sharing a `(parent, alias)` slot are both kept, since dropping the second would change which edge `patch_pending_peer_edges` lands on. - `pending_peer_edges_replay_after_a_drain` pins the guard's lifetime to the buffer's. - `realized_children_are_shared_across_visits` asserts pointer equality, so a revisit reusing the map rather than cloning it is checked rather than assumed. - `locked_resolution_is_unallocated_until_written` covers the accessors and the lazy allocation behind them. Also retargets the changeset at `pacquet` — `pnpm` is the TypeScript CLI — and rewrites it in terms of what a user sees, per review feedback, and satisfies the repo's dylint config: `LockedResolution`'s derives follow the configured prefix order, and the multi-line assertions carry the trailing comma the macro lint requires.
3623678 to
994a009
Compare
Dismissed because a newer commit was pushed; Greptile will re-review the current head.
PR Code Suggestions ✨Warning
No code suggestions found for the PR. |
Micro-Benchmark ResultsLinux |
|
Code review by qodo was updated up to the latest commit 994a009 |
PR Code Suggestions ✨Warning
No code suggestions found for the PR. |
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #13844 +/- ##
=======================================
Coverage 88.23% 88.24%
=======================================
Files 627 627
Lines 103279 103300 +21
=======================================
+ Hits 91126 91153 +27
+ Misses 12153 12147 -6 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
…tches The buffer-length assertions pinned an internal detail, not the thing that matters: whether collapsing repeats can change the graph. They also could not tell the two dedup strategies apart, because when both candidate children resolve, first-wins holds either way. Leaving the first triple unresolved separates them. `or_insert` fills the slot from the first *resolvable* triple, so the edge must come from the second — and deduplicating by `(parent, alias)` rather than by the whole triple drops that triple and leaves the slot empty. Reverted against a slot-keyed guard the assertion reports `None` where the edge should be. `the_first_resolvable_pending_edge_keeps_the_slot` covers the other direction, so neither half of `or_insert` can drift unnoticed.
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 38691ca |
PR Code Suggestions ✨Warning
No code suggestions found for the PR. |
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.5709458213000005,
"stddev": 0.1173376953389847,
"median": 2.5338566305000003,
"user": 1.96149834,
"system": 1.5844570800000002,
"min": 2.4424706695,
"max": 2.7842322305000002,
"times": [
2.6017304675000004,
2.7842322305000002,
2.4994838575,
2.4792912425000004,
2.5176331705000004,
2.4515363405,
2.4424706695,
2.6707842455,
2.5500800905000003,
2.7122158985
]
},
{
"command": "pacquet@main",
"mean": 2.4895951974000003,
"stddev": 0.1265404080373695,
"median": 2.4541343490000003,
"user": 1.8589337400000001,
"system": 1.40934568,
"min": 2.3722304135,
"max": 2.7448606125,
"times": [
2.4173524435000004,
2.4647833215,
2.5003756975,
2.3722304135,
2.4657813775000004,
2.7448606125,
2.4176558735,
2.4434853765,
2.3809494935,
2.6884773645
]
},
{
"command": "pnpr@HEAD",
"mean": 1.6643331737,
"stddev": 0.10688969571096266,
"median": 1.6552068895,
"user": 1.10560634,
"system": 1.15961318,
"min": 1.5461372974999998,
"max": 1.7885242504999999,
"times": [
1.7696176314999998,
1.5697511995,
1.7792846735,
1.5461372974999998,
1.5510101515,
1.7885242504999999,
1.6551517055,
1.7808765345000002,
1.5477162195,
1.6552620735
]
},
{
"command": "pnpr@main",
"mean": 1.5312805293999998,
"stddev": 0.1590581286872212,
"median": 1.4770682705,
"user": 1.2298809400000001,
"system": 1.30265648,
"min": 1.3699502645,
"max": 1.8291126695,
"times": [
1.8291126695,
1.6878611435,
1.4792424525,
1.5294633475,
1.7119445955,
1.3833203775,
1.3699502645,
1.4748940885,
1.3745474654999998,
1.4724688895
]
}
]
}Scenario: Isolated linker: fresh restore, hot cache + hot store
BENCHMARK_REPORT.json{
"results": [
{
"command": "pacquet@HEAD",
"mean": 0.30789919556,
"stddev": 0.021232284952859472,
"median": 0.30425560716,
"user": 0.25708855999999997,
"system": 0.6075276599999999,
"min": 0.26437648866,
"max": 0.33420860866,
"times": [
0.32479166566,
0.29293416066,
0.30347810066,
0.29716267866,
0.30503311366,
0.32567444566000003,
0.32948517766,
0.33420860866,
0.26437648866,
0.30184751566
]
},
{
"command": "pacquet@main",
"mean": 0.27308300616000003,
"stddev": 0.014595306917981932,
"median": 0.27495514366000007,
"user": 0.23001275999999998,
"system": 0.5598438599999999,
"min": 0.25282507266000004,
"max": 0.29596298466000004,
"times": [
0.28700438266,
0.25618514966,
0.25809621166,
0.28441915366000003,
0.28082198166,
0.27870017366000005,
0.27121011366000003,
0.29596298466000004,
0.25282507266000004,
0.26560483766000004
]
},
{
"command": "pnpr@HEAD",
"mean": 0.27742999536,
"stddev": 0.00560588281978445,
"median": 0.27754771166000003,
"user": 0.23945735999999992,
"system": 0.5338871599999999,
"min": 0.27086182866,
"max": 0.28642456366,
"times": [
0.27900259166,
0.27228119666,
0.28278574366000003,
0.27783963566000003,
0.27217650966,
0.27086182866,
0.27179469166000003,
0.28387740466,
0.27725578766000003,
0.28642456366
]
},
{
"command": "pnpr@main",
"mean": 0.26652235436000005,
"stddev": 0.010922990757655076,
"median": 0.26235636516000005,
"user": 0.21006526,
"system": 0.52254046,
"min": 0.25690962166000003,
"max": 0.28873237166000004,
"times": [
0.26193150066000004,
0.26296628666000005,
0.27077024666000005,
0.28275986566,
0.25847832966,
0.26230020466000004,
0.26241252566,
0.25796259066000005,
0.28873237166000004,
0.25690962166000003
]
}
]
}Scenario: Isolated linker: fresh install, cold cache + cold store
BENCHMARK_REPORT.json{
"results": [
{
"command": "pacquet@HEAD",
"mean": 2.7822375160999995,
"stddev": 0.04903983391962854,
"median": 2.7723022388,
"user": 1.7052531599999998,
"system": 1.44013532,
"min": 2.7203708638,
"max": 2.8711360318,
"times": [
2.7574691907999997,
2.7760580038,
2.7203708638,
2.7700732938,
2.7483669298,
2.7354222068,
2.8458441577999998,
2.8231032988,
2.8711360318,
2.7745311837999997
]
},
{
"command": "pacquet@main",
"mean": 2.7977229467999996,
"stddev": 0.018235473826337795,
"median": 2.7927490942999995,
"user": 1.77364676,
"system": 1.4938860200000001,
"min": 2.7712698378,
"max": 2.8268659858,
"times": [
2.7830305118,
2.8127985958,
2.7926909147999996,
2.7928072738,
2.7809902768,
2.7712698378,
2.8153078868,
2.7876242778,
2.8138439068,
2.8268659858
]
},
{
"command": "pnpr@HEAD",
"mean": 1.8019253747999997,
"stddev": 0.0918247385655768,
"median": 1.8189332023000002,
"user": 1.22143906,
"system": 1.3287908199999998,
"min": 1.6125932558,
"max": 1.8947790188000002,
"times": [
1.8250672288,
1.8113542708,
1.7998851288,
1.8742735548,
1.6125932558,
1.8253519528,
1.8912550898000002,
1.6718950718,
1.8947790188000002,
1.8127991758000002
]
},
{
"command": "pnpr@main",
"mean": 1.6547800295000001,
"stddev": 0.12737832085191045,
"median": 1.6564993638,
"user": 1.16467736,
"system": 1.32241012,
"min": 1.4759505058,
"max": 1.8534892138,
"times": [
1.6882508538,
1.5509598278,
1.8534892138,
1.4929092788,
1.8074460298000001,
1.4759505058,
1.6559227308000002,
1.7589439788,
1.6068518788000001,
1.6570759968
]
}
]
}Scenario: Isolated linker: fresh install, hot cache + hot store
BENCHMARK_REPORT.json{
"results": [
{
"command": "pacquet@HEAD",
"mean": 0.4755038540200001,
"stddev": 0.027219365120774792,
"median": 0.47075422002,
"user": 0.58653986,
"system": 0.7379799799999999,
"min": 0.43555241952,
"max": 0.52386140152,
"times": [
0.46965873252,
0.46633480952,
0.48129256352000005,
0.46501897652,
0.47651437852,
0.52386140152,
0.51683000452,
0.47184970752000005,
0.44812554652000003,
0.43555241952
]
},
{
"command": "pacquet@main",
"mean": 0.4687435142200001,
"stddev": 0.03365229963299555,
"median": 0.45926256552000005,
"user": 0.6043740599999999,
"system": 0.7293739799999999,
"min": 0.42856426252,
"max": 0.52558558052,
"times": [
0.43367217852,
0.44387608352,
0.42856426252,
0.46990230052000004,
0.45287166052000005,
0.46547350152000005,
0.52558558052,
0.45305162952000005,
0.50350370452,
0.5109342405200001
]
},
{
"command": "pnpr@HEAD",
"mean": 0.34849785542000006,
"stddev": 0.036339633978452676,
"median": 0.33451071052000003,
"user": 0.26566506,
"system": 0.5672457799999999,
"min": 0.31145943352,
"max": 0.44022333352000004,
"times": [
0.36221129152000003,
0.44022333352000004,
0.32667127552,
0.36913899352,
0.33591200252000003,
0.31145943352,
0.33138770552,
0.33125389452000004,
0.33310941852000003,
0.34361120552
]
},
{
"command": "pnpr@main",
"mean": 0.32966394422,
"stddev": 0.018531696064904988,
"median": 0.32818568102,
"user": 0.24522506000000002,
"system": 0.5310368799999999,
"min": 0.31038273152,
"max": 0.36451882652,
"times": [
0.33722457952,
0.31382367452000004,
0.31149630252000005,
0.33890943252,
0.31038273152,
0.31914678252,
0.31387832652000003,
0.33971133852,
0.36451882652,
0.34754744752
]
}
]
}Scenario: Isolated linker: fresh install, cold cache + hot store
BENCHMARK_REPORT.json{
"results": [
{
"command": "pacquet@HEAD",
"mean": 1.9554782460600002,
"stddev": 0.03053973954337285,
"median": 1.94822242546,
"user": 0.8869208400000002,
"system": 0.8443067799999999,
"min": 1.9056647739600001,
"max": 2.02217961796,
"times": [
1.94088018496,
1.94755003796,
1.9056647739600001,
2.02217961796,
1.94301451396,
1.95734242396,
1.97612994496,
1.93987987096,
1.9488948129600001,
1.97324627896
]
},
{
"command": "pacquet@main",
"mean": 1.96224782026,
"stddev": 0.043946329963963165,
"median": 1.9523251944600002,
"user": 0.9134117399999999,
"system": 0.8805790800000001,
"min": 1.9042078579600001,
"max": 2.06510533896,
"times": [
1.94685276496,
1.9234551909600002,
1.9042078579600001,
1.99743742396,
1.95045150796,
1.96504929296,
1.9541988809600002,
2.06510533896,
1.9679281339599999,
1.94779180996
]
},
{
"command": "pnpr@HEAD",
"mean": 0.32476567606,
"stddev": 0.009493993125063752,
"median": 0.32311683446,
"user": 0.23869493999999997,
"system": 0.53922128,
"min": 0.31533262996,
"max": 0.34797291396,
"times": [
0.31989742796,
0.31926377796,
0.32524263496,
0.32716117996,
0.32099103396,
0.32598028096,
0.34797291396,
0.33001725696,
0.31533262996,
0.31579762396
]
},
{
"command": "pnpr@main",
"mean": 0.32833921015999995,
"stddev": 0.008594412274516777,
"median": 0.33170739896,
"user": 0.23212833999999996,
"system": 0.5543141800000001,
"min": 0.31398555896,
"max": 0.33984944596,
"times": [
0.32763628396,
0.33984944596,
0.31495558096,
0.31398555896,
0.33083839096,
0.33346576896,
0.33432306996,
0.33335522096,
0.33257640696,
0.32240637396
]
}
]
}Scenario: Isolated linker: fresh resolve, hot cache, offline
BENCHMARK_REPORT.json{
"results": [
{
"command": "pacquet@HEAD",
"mean": 0.23714888540181817,
"stddev": 0.017751221202365237,
"median": 0.23192421622000003,
"user": 0.18903731818181815,
"system": 0.06549597636363637,
"min": 0.20624306022000002,
"max": 0.26337343222000004,
"times": [
0.26337343222000004,
0.23332757422000003,
0.20624306022000002,
0.23192421622000003,
0.23138406022000002,
0.22958571122000002,
0.21960464422000003,
0.25739711922,
0.25908737622,
0.24767803422000004,
0.22903251122
]
},
{
"command": "pacquet@main",
"mean": 0.28272593242,
"stddev": 0.029657034382549276,
"median": 0.29040777972,
"user": 0.23935420000000002,
"system": 0.08654474,
"min": 0.22005246422000002,
"max": 0.31689736422000003,
"times": [
0.28168474522000003,
0.30870723222,
0.30163803522000004,
0.30110202922,
0.28765499622,
0.31689736422000003,
0.29316056322,
0.22005246422000002,
0.25074265222000003,
0.26561924222000005
]
},
{
"command": "pnpr@HEAD",
"mean": 0.09357935066827584,
"stddev": 0.0038968256703343493,
"median": 0.09313601822,
"user": 0.022020982758620692,
"system": 0.013345753793103448,
"min": 0.08762900722,
"max": 0.10084706922,
"times": [
0.09634095122,
0.10084706922,
0.10029400022,
0.08947289422,
0.09006572722,
0.09667619122,
0.09219532022,
0.09086063122,
0.09317708522,
0.09187404722,
0.09716780522,
0.09448974222,
0.08874104922,
0.09036594222,
0.09313601822,
0.09346252122,
0.09654304022,
0.09034737622,
0.09339872122000001,
0.09731214622,
0.09175937022,
0.09764980022,
0.09287969622,
0.09935408422,
0.09980216622,
0.08909677722,
0.08780731322,
0.08762900722,
0.09105467522
]
},
{
"command": "pnpr@main",
"mean": 0.09254592361393939,
"stddev": 0.003081567468482739,
"median": 0.09285398722,
"user": 0.024310015151515152,
"system": 0.010898632727272727,
"min": 0.08601870122000001,
"max": 0.09898799622,
"times": [
0.08601870122000001,
0.08628436022,
0.08820916822,
0.08727836022,
0.08662788622,
0.09898799622,
0.09625897722,
0.09347649822,
0.08952638422,
0.09282453222,
0.09216367022000001,
0.09302544922,
0.09545148922,
0.09371086822000001,
0.09290795922,
0.09285398722,
0.09331152722,
0.09712483422,
0.09288679022,
0.09253064022,
0.09280508622,
0.09648616422,
0.09152983922,
0.09292022222,
0.09481064522,
0.09141115622,
0.09275500122000001,
0.09129713222000001,
0.09179940522,
0.09198189822,
0.09489573522,
0.09543202222,
0.09443109222
]
}
]
}Scenario: Isolated linker: peer-heavy resolve, hot cache, offline
BENCHMARK_REPORT.json{
"results": [
{
"command": "pacquet@HEAD",
"mean": 0.6697992148555555,
"stddev": 0.07293605792436787,
"median": 0.6789624853,
"user": 0.6661654155555554,
"system": 0.12793461777777773,
"min": 0.5539851623,
"max": 0.7711014003,
"times": [
0.6789624853,
0.6897907963,
0.6957282753,
0.7711014003,
0.6408855833,
0.7680569403,
0.5539851623,
0.6392851453,
0.5903971453
]
},
{
"command": "pacquet@main",
"mean": 0.6443039886333333,
"stddev": 0.08525281284203705,
"median": 0.6616270353,
"user": 0.6091350822222222,
"system": 0.12313284,
"min": 0.49267641130000006,
"max": 0.7536393223,
"times": [
0.6616270353,
0.7536393223,
0.7094153783,
0.6426639263,
0.5197157173,
0.6865872153,
0.6801243593,
0.6522865323,
0.49267641130000006
]
},
{
"command": "pnpm@HEAD",
"mean": 3.1240896187444442,
"stddev": 0.12432165252226833,
"median": 3.1522124753,
"user": 4.778671415555555,
"system": 0.2866716177777778,
"min": 2.8826945873,
"max": 3.2783853923,
"times": [
3.2780472473,
3.0195092013,
3.1768251033,
2.8826945873,
3.0857487923,
3.2783853923,
3.1523087153,
3.0910750543,
3.1522124753
]
}
]
}Scenario: Isolated linker: fresh restore, cold cache + cold store + cold pnpr
BENCHMARK_REPORT.json{
"results": [
{
"command": "pacquet@HEAD",
"mean": 4.549861299940001,
"stddev": 0.11750719371624571,
"median": 4.51824477014,
"user": 2.1091045799999995,
"system": 1.4870235,
"min": 4.455839070640001,
"max": 4.8674406576400004,
"times": [
4.53007317164,
4.5796886616400005,
4.542393440640001,
4.54782161564,
4.50453518264,
4.49045159764,
4.50641636864,
4.455839070640001,
4.8674406576400004,
4.47395323264
]
},
{
"command": "pacquet@main",
"mean": 4.590633926440001,
"stddev": 0.1419752618368678,
"median": 4.55441885514,
"user": 2.11717028,
"system": 1.5785854000000001,
"min": 4.46937636364,
"max": 4.94845002764,
"times": [
4.58013770564,
4.51867829964,
4.5452696686400005,
4.70104049664,
4.46937636364,
4.52229298464,
4.5839108066400005,
4.94845002764,
4.47361486964,
4.56356804164
]
},
{
"command": "pnpr@HEAD",
"mean": 3.6017872101400004,
"stddev": 0.10647763085331845,
"median": 3.5466401316400002,
"user": 1.4458236799999997,
"system": 1.4495283,
"min": 3.49348087264,
"max": 3.80111235864,
"times": [
3.5465320486400005,
3.80111235864,
3.49348087264,
3.5315190236400005,
3.54674821464,
3.5374357086400003,
3.4980724656400004,
3.7047571616400004,
3.6467100526400005,
3.7115041946400003
]
},
{
"command": "pnpr@main",
"mean": 3.7473027116400006,
"stddev": 0.14475151332901967,
"median": 3.67056418414,
"user": 1.77256268,
"system": 1.7259240999999999,
"min": 3.61740096264,
"max": 3.9784853686400004,
"times": [
3.9784853686400004,
3.61740096264,
3.64622506164,
3.9394965506400004,
3.69490330664,
3.64387914064,
3.8131915166400003,
3.8953345556400003,
3.6181026006400003,
3.6260080526400005
]
}
]
} |
|
| Project | pnpm's project |
| Branch | pr/13844 |
| 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 | 1,612.59 ms |
| isolated-linker.fresh-install.cold-cache.hot-store | 📈 view plot | 315.33 ms |
| isolated-linker.fresh-install.hot-cache.hot-store | 📈 view plot | 311.46 ms |
| isolated-linker.fresh-resolve.hot-cache.offline | 📈 view plot | 87.63 ms |
| isolated-linker.fresh-restore.cold-cache.cold-store | 📈 view plot | 1,546.14 ms |
| isolated-linker.fresh-restore.cold-cache.cold-store.cold-pnpr | 📈 view plot | 3,493.48 ms |
| isolated-linker.fresh-restore.hot-cache.hot-store | 📈 view plot | 270.86 ms |
…em (#13855) Follow-up to #13844 on the same workload from #13681. A workspace has a few thousand distinct `pkgIdWithPatchHash` values, but the peer walk realizes one occurrence node per distinct root-to-package path — **2,007,292 of them for a 6,133-node graph**. Every one of those nodes owned a fresh `String` copy of its package id, and every parent-context snapshot copied it again. ### Changes - **`DependenciesTreeNode::resolved_package_id` and `ChildEdge::pkg_id` become `Arc<str>`.** `realize_children` now hands over a refcount instead of allocating, and the node shrinks from 56 to 48 bytes. The maps keyed by package id move to `Arc<str>` keys with it — `Arc<str>: Borrow<str>` keeps `&str` lookups working, and `Arc<str>` hashes as its `str`, so iteration order is unchanged. - **`ParentPkgInfo::pkg_id` follows.** Those snapshots held **1,327,035 entries** across the walk, each with its own copy of an id that already existed on the tree node it was read from. - **`DepPath` gains `From<Arc<str>>`.** It already wraps an `Arc<str>`, so these conversions stop round-tripping through `String` and reallocating. ### Result | | peak RSS | | --- | --- | | `main` | 3306 / 3236 / 3250 MB | | this branch | 3008 / 3086 / 3044 MB | **3264 → 3046 MB, −6.7%**, alternating A/B to control for drift, non-overlapping, 3 of 3. Cumulative with #13844 the same install has gone **3670 → 3046 MB (−17%)**. (The first version of this PR measured −5%. Review caught that the conversion had left `Arc::from` calls on paths that previously did no allocation at all — comparisons in the cache-matching loop, a double allocation in `packages.insert`, a `&str → String → Arc<str>` round-trip. Removing them is what took it to −6.7%.) ### Correctness The lockfile is **byte-identical** — `main` twice and this branch once all produced the same file, and the package sets match exactly. (Worth noting given #13846: on this run the engine happened to be deterministic, so the control was clean; that is not always true.) 326 tests pass, plus `cargo clippy --all-targets`, `cargo fmt` and `cargo dylint` clean across the workspace. Two tests cover the change: the existing footprint assertion drops from 56 to 48 bytes, and `realizing_children_shares_the_edge_package_id` asserts pointer equality through `realize_children_with` — the path that creates the two million occurrences — so a future copy fails rather than silently costing memory. I verified it fails when that path is made to copy; the first version of it did not, because it only checked that the constructor kept its argument.
…truncation (#13859) The third and largest piece of #13681, addressing what the first two PRs (#13844, #13855) deliberately left alone: the occurrence explosion itself. ### The problem A walk that re-enters a package already on its ancestor chain resolves against a truncated subtree, so its verdict has never been cached — reusing it where the subtree is intact drops `transitivePeerDependencies` depending on traversal order (#5108). On a peer-cyclic graph this rule makes the peers cache inert. Resolving [bit](https://github.com/teambit/bit)'s env packages: ``` full walks: 188,707 (91% end in a cycle) peers-cache hits: 155 of 188,862 lookups (0.08%) occurrence nodes: 2,008,130 for a 6,133-node graph ``` ### The insight, measured before designed The truncation is not arbitrary: `realize_children_with` drops exactly the edges `forms_cycle` finds in the occurrence's own ancestor ids. So a truncated verdict is a function of *(package, peer context, the chain entries the gate actually weighs)* — and everything else in the chain is noise. I instrumented the workload to check how much noise: | candidate key | distinct keys / 171,508 cycle walks | | --- | --- | | full ancestor chain | 68,184 (2.5×) — and implemented honestly, memory got *worse* | | chain ∩ reachable-set | 68,180 — useless, the cluster is one giant SCC | | **chain ∩ consulted ids** | **~1,900 (91×)** | ### The mechanism - Every full walk keeps a `ConsultedPkgs` frame — a bitset over interned package ids. Realization marks the package whose children are realized plus every child edge target (precisely the `forms_cycle` arguments); reusing an already-realized children map marks the same ids, since the map embodies the same answers. Finished walks fold their frame into their parent's; a cache hit folds the stored entry's set in. An outer frame therefore covers the dependence of everything under it. - Cycle-resolved verdicts are now stored, tagged with a `CycleTruncationKey`: the consulted set plus the occurrence's ancestor ids restricted to it (base entries first — `forms_cycle` treats the halves differently, so the boundary is part of the key). - `find_hit` hands a tagged verdict only to an occurrence whose ancestors, restricted to the entry's consulted set, are exactly the recorded chain. Equal restrictions ⇒ every gate answer equal ⇒ same realization, same truncation, same verdict, by induction on the walk. Non-matching occurrences — in particular ones whose ancestors don't truncate the subtree at all, the #5108 shape — re-walk exactly as before. ### Results Same replayed install as the previous PRs (5 importers, 3,807 merged packages), alternating A/B: | | peak RSS | wall time | | --- | --- | --- | | `main` | 3043 / 3056 / 3042 MB | 59 / 39 / 42 s | | this branch | 1405 / 1416 / 1415 MB | 20 / 25 / 20 s | **3047 → 1412 MB (−54%), roughly 2× faster.** Walk counts: full walks 188,707 → 33,648; cycle walks 171,508 → 16,563; the keyed entries hit 44,999 times. Cumulative across the three PRs the install has gone **3670 → 1412 MB (−62%)**. ### Correctness This is the change #5108 exists to be afraid of, so I want to be explicit about the evidence and its limits. - **328 tests pass**, including new ones that pin the key's semantics from both directions: unconsulted ancestors are noise (reuse happens), while order changes, extra occurrences, base/appended boundary moves, and — critically — *an occurrence whose ancestors don't truncate the subtree* all refuse reuse. - **Repeat installs never churn.** Fixed-point checked both ways: the unmodified engine, handed this branch's lockfile as `wanted`, preserves it byte for byte; this branch preserves `main`'s lockfile byte for byte. Lockfile churn on repeat installs is the #5108 regression, and it cannot happen here. - **Cold output is deterministic** — three cold runs, byte-identical. - **Cold output differs from `main` in 13 snapshot entries** (52 diff lines of ~86k), all in the `@teambit/component → command-bar/pubsub/ui` cluster — the exact entries that already flip between *identical stock runs* (#13846, 96–197-line diffs). The branch picks a different valid peer variant there; the fixed-point check is what shows it is valid. I want to flag this honestly rather than bury it: if byte-identical cold output against current `main` is a hard requirement even inside the known-nondeterministic cluster, this needs a maintainer call. - `cargo clippy --all-targets`, `cargo fmt`, and `cargo dylint` clean across the workspace.
Resolving peer dependencies realizes one tree node per distinct root-to-package path. In a workspace whose peer graph is highly cyclic that count is enormous: resolving the bit monorepo's env packages realizes 2,008,313 occurrences to produce a 6,133-node graph. Every byte held per occurrence, and every allocation made per visit, is therefore paid two million times.
This PR attacks the per-occurrence cost. It does not change what the walk resolves.
Changes
1.
DependenciesTreeNodecarried four wanted-lockfile fields inline.previous_dep_path,locked_peer_context,dependency_names_whose_current_provider_must_winandlocked_peer_namesare allNoneon a fresh resolution — which is every node the resolver produces today, as three of them are marked "the resolver does not capture this yet" — yet they cost ~88 bytes on every node. Moving them behind a boxedLockedResolutiontakes the node from 144 to 64 bytes, and the tree's hash table from 676 MB to 356 MB.2.
TreeChildren::Realizedheld its children map by value.realize_childrentherefore cloned the entireBTreeMap, every keyStringincluded, on each revisit of an already-realized node, and stored a second copy on the node itself. The map is immutable once built, so it is now shared through anArc.3.
add_graph_child_or_pendingbuffered one pending edge per occurrence. A parent reached through many occurrences pushes the identical(parent_dep_path, alias, child_node_id)triple over and over, and replaying a duplicate is a no-op — it resolves the sameDepPathandor_inserts the same slot. Dropping exact repeats takes the buffer from 2,224,865 entries to 114,778.Result
Replaying the same install through
@pnpm/napi(5 importers, 3,807 merged packages):3656 → 3235 MB, -11.5%, n=3 each, non-overlapping ranges, no change in wall time. (Re-measured against
mainafter rebasing; the earlier numbers were against the published12.0.0-rc.1and were materially the same.)Byte attribution over the walker's fields, before → after:
dependencies_tree(2.0M entries)pending_peer_edgesCorrectness
cargo test -p pacquet-resolving-deps-resolver: 324 passed.cargo check --workspace --all-targets,cargo clippy --all-targetsandcargo fmtare clean.Five of those tests are new, because none of these savings changes observable resolution — so without them nothing in the suite notices a regression. I checked each one actually fails when its fix is reverted: dropping the dedup guard turns
repeated_pending_peer_edges_are_buffered_onceintoleft: 3, right: 1, and inlining a field back onto the node trips the footprint assertion.tree_node_keeps_its_per_occurrence_footprint_small— 56 bytes is the current layout, not a budget with room in it.repeated_pending_peer_edges_are_buffered_once— pins both halves: repeats collapse, but two distinct triples sharing a(parent, alias)slot are both kept, since dropping the second would change which edgepatch_pending_peer_edgeslands on.pending_peer_edges_replay_after_a_drain— the guard's lifetime is the buffer's.realized_children_are_shared_across_visits— pointer equality, so map reuse is checked rather than assumed.locked_resolution_is_unallocated_until_written— the accessors and their lazy allocation.The lockfile stays within the engine's existing run-to-run variance. Worth flagging on its own: the engine is not deterministic across runs today. Two stock runs of the identical install differ from each other by 197 diff lines; stock vs. this branch differs by 173 and 88. All pairs churn the same packages (
classnames,tippy.js,lodash,postcss), so this branch sits inside the existing envelope rather than adding to it — but the envelope should probably not exist. I can open a separate issue for that.What this does not fix
The underlying expansion. Instrumenting the walk on this workload:
91% of full walks end in a cycle, and a cycle-resolved walk deliberately caches nothing (#5108 — its truncated subtree makes its peer sets non-authoritative). Only 10,393 walks ever store a
PeersCacheItem, sofind_hithits 155 times in 188,862 lookups (0.08%) and nearly every occurrence re-walks its whole subtree.That is the real driver of the 2M occurrences, and fixing it — caching cycle-resolved verdicts under a key that captures the truncation, so they are reused only where valid — would be worth far more than this PR. I did not attempt it here because getting it wrong produces wrong lockfiles rather than merely slow ones. Happy to take it on with guidance on the intended invariant.
Refs #13681
Need help on this PR? Tag
@codesmith-botwith what you need. Autofix is disabled.Summary by CodeRabbit
Performance
Bug Fixes
Release