Repository navigation
perf(resolving-deps-resolver): sync the discovery view from a write log - #13571
Conversation
|
Note Reviews pausedIt looks like this branch is under active development. To avoid overwhelming you with review comments due to an influx of new commits, CodeRabbit has automatically paused this review. You can configure this behavior by changing the Use the following commands to manage reviews:
Use the checkboxes below for quick actions:
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)
📝 WalkthroughWalkthroughThe resolver records workspace mutations in append-only logs. ChangesIncremental peer discovery
Estimated code review effort: 3 (Moderate) | ~25 minutes Sequence Diagram(s)sequenceDiagram
participant PeerHoistDiscovery
participant WorkspaceTreeCtx
participant SyncLog
participant ResolvedTree
PeerHoistDiscovery->>WorkspaceTreeCtx: sync_discovery_tree(tree, cursor)
WorkspaceTreeCtx->>SyncLog: read writes since cursor
SyncLog-->>WorkspaceTreeCtx: changed package, child, node, and peer-name keys
WorkspaceTreeCtx->>ResolvedTree: apply changed workspace entries
WorkspaceTreeCtx-->>PeerHoistDiscovery: synchronization result
Possibly related issues
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 |
Confidence Score: 5/5The PR appears safe to merge. The previously reported unused Reviews (6): Last reviewed commit: "test(resolving-deps-resolver): add a hoi..." | Re-trigger Greptile |
PR Summary by QodoSpeed up peer-hoist discovery sync via append-only write log
AI Description
Diagram
High-Level Assessment
Files changed (8)
|
PR Code Suggestions ✨Warning
No code suggestions found for the PR. |
There was a problem hiding this comment.
Pull request overview
Improves pacquet’s peer-hoist discovery performance by switching the persistent discovery view refresh from full-map rescans to an incremental “replay keys written since cursor” approach, reducing per-round sync costs in large workspaces.
Changes:
- Add an append-only
SyncLog+SyncCursortoWorkspaceTreeCtx, and refresh the discoveryResolvedTreeby visiting only keys written since the last cursor. - Record write keys at mutation sites (
packages,children_by_id,dependencies_tree, peer-dep-name registration) so incremental sync is correct. - Add unit tests validating wave-by-wave sync equivalence vs from-scratch rebuild and detecting unmergeable peer-split changes; add a changeset for the perf improvement.
Reviewed changes
Copilot reviewed 7 out of 7 changed files in this pull request and generated 1 comment.
Show a summary per file
| File | Description |
|---|---|
| pnpm/crates/resolving-deps-resolver/src/resolve_peers/discovery.rs.orig | Adds a duplicated “.orig” Rust source file (appears unintended). |
| pnpm/crates/resolving-deps-resolver/src/resolve_peers/discovery.rs | Threads SyncCursor through discovery’s sync/rebuild path. |
| pnpm/crates/resolving-deps-resolver/src/resolve_dependency_tree/workspace_ctx.rs | Introduces SyncLog/SyncCursor, incremental sync_discovery_tree, and write-recording helpers. |
| pnpm/crates/resolving-deps-resolver/src/resolve_dependency_tree/workspace_ctx/tests.rs | Adds sync correctness tests (currently includes a dbg! that should be removed). |
| pnpm/crates/resolving-deps-resolver/src/resolve_dependency_tree/walk.rs | Records write keys when updating packages/children/tree nodes during fresh walks. |
| pnpm/crates/resolving-deps-resolver/src/resolve_dependency_tree/reuse.rs | Records write keys when populating data during lockfile reuse walks. |
| pnpm/crates/resolving-deps-resolver/src/resolve_dependency_tree.rs | Re-exports SyncCursor for internal crate use. |
| .changeset/incremental-discovery-tree-sync.md | Changeset entry documenting the pacquet peer-resolution perf improvement. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Micro-Benchmark ResultsLinux |
Code Review by Qodo
Context used✅ Compliance rules (platform):
24 rules 1. Unbounded sync log growth
|
PR Code Suggestions ✨Warning
No code suggestions found for the PR. |
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main pnpm/pnpm#13571 +/- ##
==========================================
+ Coverage 87.97% 87.98% +0.01%
==========================================
Files 563 563
Lines 97412 97499 +87
==========================================
+ Hits 85698 85785 +87
Misses 11714 11714 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 7 out of 7 changed files in this pull request and generated no new comments.
Suppressed comments (1)
pnpm/crates/resolving-deps-resolver/src/resolve_dependency_tree/workspace_ctx/tests.rs:241
- This test passes
&mut super::SyncCursor::default()intosync_discovery_tree. Rust doesn't allow taking a mutable reference to a temporary, so this should fail to compile. Use a localmutcursor variable instead.
let mut from_scratch = crate::resolved_tree::ResolvedTree::default();
assert!(
workspace.sync_discovery_tree(&mut from_scratch, &mut super::SyncCursor::default()),
"a sync into an empty view has nothing to conflict with",
);
There was a problem hiding this comment.
Actionable comments posted: 1
🧹 Nitpick comments (3)
pnpm/crates/resolving-deps-resolver/src/resolve_dependency_tree/walk.rs (1)
460-462: 🗄️ Data Integrity & Integration | 🔵 Trivial | ⚡ Quick winRecord the package write after the insert, not before.
record_package_write(&id)at Line 461 runs beforepackages.insert(...)at Line 462, the opposite order from the branch just above it (Lines 453-457), which mutatesexisting.peer_dependenciesbefore callingrecord_package_write. This is currently safe only because thepackageslock guard spans both statements in the new-package branch. Swap the order for consistency with the sibling branch and with every other write-recording site in this PR.See the consolidated comment for the shared fix across this file and
reuse.rs.🤖 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 `@pnpm/crates/resolving-deps-resolver/src/resolve_dependency_tree/walk.rs` around lines 460 - 462, Move ctx.workspace.record_package_write(&id) to after the packages.insert(...) call in the new-package branch of the dependency-tree walk, matching the mutation-then-record order used by the sibling branch and other write-recording sites.pnpm/crates/resolving-deps-resolver/src/resolve_dependency_tree/reuse.rs (2)
581-582: 🗄️ Data Integrity & Integration | 🔵 Trivial | ⚡ Quick winRecord the package write after the insert, not before.
record_package_write(&id)runs beforepackages.insert(...). This is the opposite order used by every other write-recording site in this PR (children_by_id,dependencies_tree, and walk.rs's own "changedpeer_dependencies" branch). It is currently safe only because thepackageslock guard spans both statements. Swap the order for consistency and to remove the dependency on that lock-scope detail.See the consolidated comment for the shared fix across this file and
walk.rs.🤖 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 `@pnpm/crates/resolving-deps-resolver/src/resolve_dependency_tree/reuse.rs` around lines 581 - 582, In the package update flow, move ctx.workspace.record_package_write(&id) to execute after packages.insert completes. Preserve the existing package insertion behavior and apply this ordering consistently with the other write-recording sites referenced in the comment.
573-581: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick winReuse the existing peer-name registration helper.
This loop duplicates
register_peer_dep_namesinworkspace_ctx.rs, which walk.rs already calls for the same purpose. Call the shared helper instead of re-implementing the loop here.♻️ Proposed fix
- { - let mut all_peers = lock_recoverable(&ctx.workspace.all_peer_dep_names); - for name in peer_dependencies.keys() { - if all_peers.insert(name.clone()) { - ctx.workspace.record_peer_dep_name(name); - } - } - } + register_peer_dep_names(ctx, &peer_dependencies); ctx.workspace.record_package_write(&id);🤖 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 `@pnpm/crates/resolving-deps-resolver/src/resolve_dependency_tree/reuse.rs` around lines 573 - 581, Replace the duplicated peer-name insertion loop in the reuse flow with the existing WorkspaceContext::register_peer_dep_names helper, passing the peer dependency names from peer_dependencies. Preserve the subsequent ctx.workspace.record_package_write(&id) call and remove the direct all_peer_dep_names locking and iteration.
🤖 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 `@pnpm/crates/resolving-deps-resolver/src/resolve_peers/discovery.rs.orig`:
- Around line 1-268: Delete the stray discovery.rs.orig backup file entirely;
keep the active discovery.rs implementation unchanged.
---
Nitpick comments:
In `@pnpm/crates/resolving-deps-resolver/src/resolve_dependency_tree/reuse.rs`:
- Around line 581-582: In the package update flow, move
ctx.workspace.record_package_write(&id) to execute after packages.insert
completes. Preserve the existing package insertion behavior and apply this
ordering consistently with the other write-recording sites referenced in the
comment.
- Around line 573-581: Replace the duplicated peer-name insertion loop in the
reuse flow with the existing WorkspaceContext::register_peer_dep_names helper,
passing the peer dependency names from peer_dependencies. Preserve the
subsequent ctx.workspace.record_package_write(&id) call and remove the direct
all_peer_dep_names locking and iteration.
In `@pnpm/crates/resolving-deps-resolver/src/resolve_dependency_tree/walk.rs`:
- Around line 460-462: Move ctx.workspace.record_package_write(&id) to after the
packages.insert(...) call in the new-package branch of the dependency-tree walk,
matching the mutation-then-record order used by the sibling branch and other
write-recording sites.
🪄 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: e7b582e9-174e-492b-887c-596f08854ce4
📒 Files selected for processing (8)
.changeset/incremental-discovery-tree-sync.mdpnpm/crates/resolving-deps-resolver/src/resolve_dependency_tree.rspnpm/crates/resolving-deps-resolver/src/resolve_dependency_tree/reuse.rspnpm/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/discovery.rspnpm/crates/resolving-deps-resolver/src/resolve_peers/discovery.rs.orig
|
Thanks — Qodo's three findings and CodeRabbit's one: 1. Key-log cloning overhead — taken, fixed in 258c7de. The finding is right about the rebuild path: replaying the whole log to refill a discarded view copies every key twice, once into the log snapshot and once into the view. Rebuilds now scan the shared maps instead (Qodo's suggested direction 3), and take their cursor from the log's length before the scan, so a write landing mid-scan is either picked up by the scan and replayed harmlessly by the next sync, or missed by it and applied by the next sync. The incremental path keeps the small 2. 3. Changeset missing a CodeRabbit's Written by an agent (Claude Code, claude-opus-5). |
|
Code review by qodo was updated up to the latest commit 258c7de |
PR Code Suggestions ✨Warning
No code suggestions found for the PR. |
|
Rebuild cursor easily ignored — taken, fixed in ddcaaf0. Full gate re-run after the change: 7,549 tests pass, clippy/dylint/fmt clean. Written by an agent (Claude Code, claude-opus-5). |
|
Code review by qodo was updated up to the latest commit ddcaaf0 |
PR Code Suggestions ✨Warning
No code suggestions found for the PR. |
|
On the Codecov note — the one uncovered line is It is worth knowing what the gap means: if that call were missing, the discovery view would keep the stale split instead of reporting itself unmergeable. The sync side of exactly that case is pinned by Written by an agent (Claude Code, claude-opus-5). |
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.5889385138599996,
"stddev": 0.14536124788984822,
"median": 2.5641881816599996,
"user": 1.67312316,
"system": 1.3081888999999998,
"min": 2.36274086116,
"max": 2.78239157816,
"times": [
2.47370899716,
2.78239157816,
2.55731400016,
2.74935952616,
2.46292453916,
2.49364923716,
2.57106236316,
2.36274086116,
2.75628386216,
2.67995017416
]
},
{
"command": "pacquet@main",
"mean": 2.50531227346,
"stddev": 0.1388891433408085,
"median": 2.47083109116,
"user": 1.64097086,
"system": 1.322052,
"min": 2.34411170816,
"max": 2.74835167316,
"times": [
2.3544303851599997,
2.55433002416,
2.61770336316,
2.50138748516,
2.6704056341599998,
2.44027469716,
2.34411170816,
2.43837237416,
2.74835167316,
2.38375539016
]
},
{
"command": "pnpr@HEAD",
"mean": 1.5051756489599997,
"stddev": 0.16949365162031224,
"median": 1.4344150731599998,
"user": 1.2125289599999998,
"system": 1.1370327999999998,
"min": 1.3491484411599999,
"max": 1.79297593316,
"times": [
1.3524868021599998,
1.43771985416,
1.54418815916,
1.3491484411599999,
1.7771966521599998,
1.79297593316,
1.38067843016,
1.60871617316,
1.4311102921599999,
1.37753575216
]
},
{
"command": "pnpr@main",
"mean": 1.54209468976,
"stddev": 0.14155960795855244,
"median": 1.57434450716,
"user": 1.1942226599999999,
"system": 1.163586,
"min": 1.33815351316,
"max": 1.72791574416,
"times": [
1.72791574416,
1.35475775416,
1.64005812016,
1.5560811991599999,
1.36340266216,
1.56991554716,
1.68909149116,
1.60279739916,
1.57877346716,
1.33815351316
]
}
]
}Scenario: Isolated linker: fresh restore, hot cache + hot store
BENCHMARK_REPORT.json{
"results": [
{
"command": "pacquet@HEAD",
"mean": 0.254072092,
"stddev": 0.0048801298224362445,
"median": 0.2553057556,
"user": 0.19889653999999998,
"system": 0.51591928,
"min": 0.2460979436,
"max": 0.2597493616,
"times": [
0.2597493616,
0.24691688460000003,
0.2536378876,
0.2460979436,
0.2579119556,
0.25697362360000003,
0.25216635660000003,
0.2512049476,
0.2574082116,
0.25865374760000004
]
},
{
"command": "pacquet@main",
"mean": 0.2569926701,
"stddev": 0.008427130441134818,
"median": 0.2540347796,
"user": 0.19915953999999997,
"system": 0.52784828,
"min": 0.24819911260000002,
"max": 0.2709102306,
"times": [
0.25156694760000003,
0.2507915016,
0.25385624960000003,
0.24819911260000002,
0.2706283846,
0.2486573186,
0.2709102306,
0.2542133096,
0.2595713296,
0.26153231660000004
]
},
{
"command": "pnpr@HEAD",
"mean": 0.27506419810000005,
"stddev": 0.009694281743033467,
"median": 0.2742969046,
"user": 0.21011833999999996,
"system": 0.5191480800000001,
"min": 0.2603491496,
"max": 0.2974739046,
"times": [
0.2796194516,
0.2762412696,
0.26586552760000004,
0.2603491496,
0.27260174660000003,
0.2748541256,
0.2737396836,
0.2774429586,
0.2724541636,
0.2974739046
]
},
{
"command": "pnpr@main",
"mean": 0.2721583219,
"stddev": 0.006644998172151029,
"median": 0.2714321246,
"user": 0.20907134,
"system": 0.5103027800000001,
"min": 0.2636355636,
"max": 0.2851996526,
"times": [
0.2811894086,
0.2706210126,
0.27343314160000004,
0.2636355636,
0.2681204106,
0.2659811916,
0.2722432366,
0.26837878460000003,
0.2851996526,
0.27278081660000003
]
}
]
}Scenario: Isolated linker: fresh install, cold cache + cold store
BENCHMARK_REPORT.json{
"results": [
{
"command": "pacquet@HEAD",
"mean": 2.5891580380800003,
"stddev": 0.014797789337627909,
"median": 2.59359933808,
"user": 1.6642129799999998,
"system": 1.3317186,
"min": 2.5612367770800004,
"max": 2.60638101508,
"times": [
2.60638101508,
2.5937641960800004,
2.5928651480800005,
2.59343448008,
2.5612367770800004,
2.6007296600800003,
2.5973076820800003,
2.5767355810800003,
2.5696560550800003,
2.5994697860800002
]
},
{
"command": "pacquet@main",
"mean": 2.5756265478800007,
"stddev": 0.02135497467473969,
"median": 2.58042103558,
"user": 1.6355468799999997,
"system": 1.3322717999999998,
"min": 2.5471694530800004,
"max": 2.60981868608,
"times": [
2.54867445008,
2.5839259950800004,
2.59467717408,
2.55736105808,
2.57916509708,
2.60981868608,
2.5471694530800004,
2.55985142808,
2.5939451630800003,
2.58167697408
]
},
{
"command": "pnpr@HEAD",
"mean": 1.5990897597800002,
"stddev": 0.16446837944423007,
"median": 1.54573466108,
"user": 1.18551158,
"system": 1.1652768,
"min": 1.44520482208,
"max": 1.88054111408,
"times": [
1.5345970230800001,
1.88054111408,
1.44520482208,
1.62421197608,
1.55687229908,
1.67063600608,
1.87389166108,
1.44865517008,
1.45113400108,
1.50515352508
]
},
{
"command": "pnpr@main",
"mean": 1.61875221518,
"stddev": 0.19403810014431003,
"median": 1.5353814850799998,
"user": 1.1805049799999998,
"system": 1.1672683,
"min": 1.43462556308,
"max": 1.87711664708,
"times": [
1.45147371308,
1.5789872890799999,
1.85184769308,
1.79709471208,
1.43804104108,
1.49177568108,
1.43462556308,
1.87711664708,
1.44184103308,
1.8247187790800001
]
}
]
}Scenario: Isolated linker: fresh install, hot cache + hot store
BENCHMARK_REPORT.json{
"results": [
{
"command": "pacquet@HEAD",
"mean": 0.39891538146000005,
"stddev": 0.011215703026692616,
"median": 0.39639718466000007,
"user": 0.52390526,
"system": 0.70815248,
"min": 0.38666897566,
"max": 0.41893168166000005,
"times": [
0.38803350966000005,
0.39146970066000003,
0.38850658366,
0.40116014766,
0.39163422166000006,
0.40433598266000004,
0.40936959666000006,
0.41893168166000005,
0.38666897566,
0.40904341466000005
]
},
{
"command": "pacquet@main",
"mean": 0.38413968096,
"stddev": 0.015291789598810288,
"median": 0.38330483066000004,
"user": 0.51421186,
"system": 0.6664682800000001,
"min": 0.36492924166,
"max": 0.41591552566000006,
"times": [
0.38386339366000005,
0.38274626766000003,
0.36492924166,
0.36789461966000003,
0.39077421466000006,
0.39595520366000003,
0.38982963166000006,
0.41591552566000006,
0.36894173566000005,
0.38054697566000006
]
},
{
"command": "pnpr@HEAD",
"mean": 0.3034599780600001,
"stddev": 0.007269420338763868,
"median": 0.30221922516,
"user": 0.19432416,
"system": 0.50009958,
"min": 0.29381420066,
"max": 0.31416937266000006,
"times": [
0.30232049366,
0.29947084366000004,
0.29381420066,
0.30211795666,
0.31331774066,
0.31416937266000006,
0.29387409166000006,
0.30128623066000004,
0.31087976766000003,
0.30334908266000005
]
},
{
"command": "pnpr@main",
"mean": 0.30401003156,
"stddev": 0.004605759116568173,
"median": 0.30396187366000005,
"user": 0.18826926,
"system": 0.51121198,
"min": 0.29502666966,
"max": 0.31024568566000005,
"times": [
0.30117860066,
0.30783437666,
0.30215881766,
0.31024568566000005,
0.29502666966,
0.30916188366,
0.30039511466,
0.30617541966000006,
0.30326882866000004,
0.30465491866000005
]
}
]
}Scenario: Isolated linker: fresh install, cold cache + hot store
BENCHMARK_REPORT.json{
"results": [
{
"command": "pacquet@HEAD",
"mean": 1.7392546963200002,
"stddev": 0.00857461180969982,
"median": 1.7395408584199998,
"user": 0.7544148399999999,
"system": 0.75525204,
"min": 1.72471947592,
"max": 1.75507123292,
"times": [
1.7446446539199998,
1.7420581979199998,
1.7370235189199998,
1.75507123292,
1.74452141792,
1.74402950092,
1.72471947592,
1.7322000089199998,
1.73583567692,
1.73244327892
]
},
{
"command": "pacquet@main",
"mean": 1.72126381832,
"stddev": 0.008649702923802197,
"median": 1.72176268642,
"user": 0.71557344,
"system": 0.75861234,
"min": 1.70275841892,
"max": 1.7307137069199998,
"times": [
1.7307137069199998,
1.72803070092,
1.7159325959199998,
1.7210972869199999,
1.72915146692,
1.7196612649199998,
1.72242808592,
1.70275841892,
1.7143200079199998,
1.72854464792
]
},
{
"command": "pnpr@HEAD",
"mean": 0.29936804682000007,
"stddev": 0.008386956533125177,
"median": 0.29633554642000004,
"user": 0.18242123999999998,
"system": 0.51365414,
"min": 0.29064447392000003,
"max": 0.31467555392,
"times": [
0.31467555392,
0.29580228192,
0.29490581092,
0.29686881092000006,
0.31318721292,
0.29064447392000003,
0.30244813392000003,
0.29436586592,
0.29173964692000004,
0.29904267692000003
]
},
{
"command": "pnpr@main",
"mean": 0.29990738152,
"stddev": 0.004259560168001965,
"median": 0.30022426492000004,
"user": 0.20199664,
"system": 0.50203464,
"min": 0.29346698792000003,
"max": 0.30582974192,
"times": [
0.29996546592000006,
0.29346698792000003,
0.30048306392,
0.30401139592000004,
0.30255749292000006,
0.30344169992000003,
0.29882885592,
0.29688807692,
0.29360103392000003,
0.30582974192
]
}
]
}Scenario: Isolated linker: fresh resolve, hot cache, offline
BENCHMARK_REPORT.json{
"results": [
{
"command": "pacquet@HEAD",
"mean": 0.18168739459333333,
"stddev": 0.00464949523468522,
"median": 0.17992957446000002,
"user": 0.15916039333333332,
"system": 0.08858485999999997,
"min": 0.17533954246,
"max": 0.19101596146000002,
"times": [
0.18571715946,
0.17985732946000002,
0.17992957446000002,
0.17828024446000001,
0.19101596146000002,
0.17533954246,
0.17671337746000002,
0.17951337546,
0.19041748546,
0.18314367646000002,
0.18330065046000002,
0.17715930646,
0.18377473346,
0.17928946246000002,
0.18185903946
]
},
{
"command": "pacquet@main",
"mean": 0.183785529085,
"stddev": 0.005761543466921402,
"median": 0.18233439746000002,
"user": 0.16946681,
"system": 0.08079462249999998,
"min": 0.17610762146,
"max": 0.19548728846000002,
"times": [
0.18036226246,
0.19548728846000002,
0.18916776946,
0.18434040346,
0.17892568046000001,
0.18150765846,
0.18123548946,
0.19446397746000002,
0.17649359446000001,
0.18313585646,
0.18946830946,
0.17610762146,
0.18525730846000002,
0.18153293846000002,
0.18360419146,
0.17947811546
]
},
{
"command": "pnpr@HEAD",
"mean": 0.08929123056714283,
"stddev": 0.003614104926792856,
"median": 0.08791863946,
"user": 0.022462452857142854,
"system": 0.010285095714285713,
"min": 0.08575192246,
"max": 0.09960431746000001,
"times": [
0.09960431746000001,
0.08813529246,
0.09044800046,
0.08693309146,
0.08658992246,
0.08575192246,
0.08586617846,
0.08633123646,
0.08724356746,
0.08770198646,
0.09065795346,
0.08624578246,
0.09227970346,
0.09230167546,
0.08883298646,
0.09061270946,
0.08992131246,
0.08576378746,
0.09561504646,
0.08759514946000001,
0.08608457546,
0.09117941646,
0.09430210546000001,
0.09579117246,
0.08839688746,
0.08586658546,
0.08656797146,
0.08753411946
]
},
{
"command": "pnpr@main",
"mean": 0.08934150523419354,
"stddev": 0.0029298310686150125,
"median": 0.08980473446000001,
"user": 0.0221488664516129,
"system": 0.010351283870967742,
"min": 0.08512769146,
"max": 0.09565002846000001,
"times": [
0.09028031846000001,
0.09068843046,
0.08781066346000001,
0.09056105746,
0.08534994046,
0.09118099646,
0.09134821646,
0.08996143546,
0.08603595146,
0.08661214346,
0.08512769146,
0.08690210546,
0.09494865746,
0.09565002846000001,
0.08641970346,
0.08631480946,
0.09260548146,
0.09029706646,
0.08973608046,
0.08980473446000001,
0.09177888446,
0.09446145246,
0.08577936046,
0.08676441046,
0.08700626846000001,
0.09129536946,
0.08524560246,
0.09094768746,
0.09113332346,
0.08917603946000001,
0.08836275146
]
}
]
}Scenario: Isolated linker: peer-heavy resolve, hot cache, offline
BENCHMARK_REPORT.json{
"results": [
{
"command": "pacquet@HEAD",
"mean": 1.7828257373444447,
"stddev": 0.45974374628954506,
"median": 1.5828631589,
"user": 1.6676140244444444,
"system": 0.2473754044444444,
"min": 1.4135869879,
"max": 2.7121738219,
"times": [
2.7121738219,
1.4817500469,
1.4285540809,
1.4135869879,
2.0141991788999998,
2.2985774359,
1.4759376088999998,
1.6377893159,
1.5828631589
]
},
{
"command": "pacquet@main",
"mean": 1.6544349447888889,
"stddev": 0.5606681606712537,
"median": 1.4218021359,
"user": 1.5203441355555554,
"system": 0.23894973777777778,
"min": 1.0393971068999999,
"max": 2.6782339179,
"times": [
2.0596764819,
1.2533295948999998,
1.0393971068999999,
1.1803426238999999,
1.2608120709,
1.4218021359,
1.7823670189,
2.2139535519,
2.6782339179
]
},
{
"command": "pnpm@HEAD",
"mean": 3.141099842677778,
"stddev": 0.23989641034130216,
"median": 3.0739700399,
"user": 4.38040958,
"system": 0.30714562666666667,
"min": 2.8735771589,
"max": 3.4609766059,
"times": [
3.1987918539,
2.9149100819,
3.4116880038999997,
2.8939174179,
3.0739700399,
2.8735771589,
3.0205091059,
3.4215583159,
3.4609766059
]
}
]
}Scenario: Isolated linker: fresh restore, cold cache + cold store + cold pnpr
BENCHMARK_REPORT.json{
"results": [
{
"command": "pacquet@HEAD",
"mean": 4.53135104302,
"stddev": 0.11292030441555137,
"median": 4.49636937912,
"user": 1.8751786799999999,
"system": 1.3526438199999997,
"min": 4.41482521612,
"max": 4.74879428212,
"times": [
4.64440570012,
4.62086155812,
4.53301469012,
4.43801772112,
4.44300859712,
4.45972406812,
4.43431995912,
4.57653863812,
4.41482521612,
4.74879428212
]
},
{
"command": "pacquet@main",
"mean": 4.522927483520001,
"stddev": 0.11400992158171458,
"median": 4.494829832620001,
"user": 1.83061818,
"system": 1.3893334199999998,
"min": 4.41854584712,
"max": 4.79939221612,
"times": [
4.41854584712,
4.45529616812,
4.53935679712,
4.43709791412,
4.43692360812,
4.79939221612,
4.59194597112,
4.56105664812,
4.52838907912,
4.46127058612
]
},
{
"command": "pnpr@HEAD",
"mean": 3.5599209519199997,
"stddev": 0.11709282149440342,
"median": 3.53718107362,
"user": 1.32582858,
"system": 1.2451071199999997,
"min": 3.4420068651199998,
"max": 3.82066612912,
"times": [
3.58699583912,
3.47047415212,
3.56771455012,
3.46281961712,
3.6231866351199997,
3.46868391312,
3.82066612912,
3.65001422112,
3.4420068651199998,
3.5066475971199997
]
},
{
"command": "pnpr@main",
"mean": 3.5283977510199995,
"stddev": 0.11715727956218251,
"median": 3.4825108386199997,
"user": 1.3259221799999998,
"system": 1.2395063199999998,
"min": 3.45703077012,
"max": 3.84022204412,
"times": [
3.49333259312,
3.45703077012,
3.5962233171199998,
3.46489779212,
3.84022204412,
3.4737532081199998,
3.52833838412,
3.47330910712,
3.46560182512,
3.49126846912
]
}
]
} |
|
| Project | pnpm's project |
| Branch | pr/13571 |
| 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,481.56 ms |
| isolated-linker.fresh-install.cold-cache.hot-store | 📈 view plot | 289.95 ms |
| isolated-linker.fresh-install.hot-cache.hot-store | 📈 view plot | 287.82 ms |
| isolated-linker.fresh-resolve.hot-cache.offline | 📈 view plot | 84.84 ms |
| isolated-linker.fresh-restore.cold-cache.cold-store | 📈 view plot | 1,355.25 ms |
| isolated-linker.fresh-restore.cold-cache.cold-store.cold-pnpr | 📈 view plot | 3,447.35 ms |
| isolated-linker.fresh-restore.hot-cache.hot-store | 📈 view plot | 258.30 ms |
The peer-hoist discovery engine keeps one view of the workspace context across every hoist round, refreshing it before each pass. That refresh walked all three shared maps end to end — `children_by_id`, `packages`, `dependencies_tree` — so every round cost one scan of the whole workspace even when the round had added a handful of nodes. A resolve of the 114-project Bit workspace from https://github.com/pnpm/pnpm/issues/13505 runs 172 of those syncs in the initial rounds alone, and each `extend_tree` bumps the revision that triggers them. Have the context record which keys of those maps each write touched, and sync by visiting the keys written since the view's cursor. Only keys are recorded, never values: the sync reads each key's current value, so a key written several times, or written by concurrently-walking importers in either order, converges on the same view — and a view rebuilt from scratch replays the whole log, which visits every key ever written. The merge itself is untouched, so an unmergeable change (a children-owner handover that re-split a package's children and peers) still reports the view stale and the engine still rebuilds. On that workspace the initial rounds' sync time drops from 683ms to 215ms — the remainder is the three rebuilds, which replay the log — and the hoist loop's from 30ms to 0.3ms, taking the two phases from 3.78s + 1.28s to 2.79s + 1.03s. Related to https://github.com/pnpm/pnpm/issues/13505.
The equivalence assertion alone passes when both views are empty, which is what a sync that observes no writes produces. Related to https://github.com/pnpm/pnpm/issues/13505.
A `patch` run left `discovery.rs.orig` behind and it was committed with the sync change. Nothing compiles or reads it. Related to https://github.com/pnpm/pnpm/issues/13505.
A view discarded after an unmergeable change replayed the whole write log to refill itself, which copies every key twice — once into the log snapshot the sync reads from, once into the view. Scan the shared maps instead, and take the cursor from the log's length *before* the scan, so a write that lands mid-scan is either picked up here and replayed harmlessly by the next sync, or missed here and applied by it. The delta path is unchanged; only the from-scratch path stops going through the log. Related to https://github.com/pnpm/pnpm/issues/13505.
…lace Returning the cursor let a caller drop it, which silently costs the amortization: the next sync would start from zero and replay the whole log. Take `&mut SyncCursor` like the incremental sync does, so there is nothing to forget. Related to https://github.com/pnpm/pnpm/issues/13505.
Rebuilds stopped replaying the write log when they started scanning the shared maps; the cursor's doc still described the replay. Related to https://github.com/pnpm/pnpm/issues/13505.
ddcaaf0 to
c10cc96
Compare
Neither existing scenario runs the auto-install-peers loop: the peer-heavy one hands every importer all the framework packages up front, so no peer is ever missing and the loop converges in a single round with one context sync. Anything that changes the cost of a hoist round is therefore invisible to it — the write-log sync in this branch measures identically on it, main and branch alike (~850ms either way). Add a third scenario where the peers are not provided and the importers' direct sets differ, so each importer hoists its own missing peers across several rounds, extending the tree in between. It costs ~8x the peer-heavy scenario (6.9s vs 0.9s) because the hoist loop dominates it, which is what makes it a regression benchmark for that loop. Related to https://github.com/pnpm/pnpm/issues/13505.
|
Code review by qodo was updated up to the latest commit c10cc96 |
PR Code Suggestions ✨Warning
No code suggestions found for the PR. |
|
Code review by qodo was updated up to the latest commit cc2b8a6 |
PR Code Suggestions ✨Warning
No code suggestions found for the PR. |
|
The Bencher alert on
Four measurements, no consistent direction, spread far exceeding any effect this PR could have on that fixture — which is expected, because the fixture cannot see this change at all: it resolves to 401 graph nodes (from the engine's own I have not re-pushed to reroll the dice; that would just be gambling on the same distribution. Separately, this is the concrete case for giving the resolver a scenario that can discriminate — I'm validating one now (its own DAG at ~5,000 nodes over 120 importers that each hoist their peers), and I will not propose it until it separates a build with this fix from one without. Written by an agent (Claude Code, claude-opus-5). |
Summary
Fourth installment on the peer-phase performance work in
pnpm/tasks#16 (after #13506, #13545
and #13568), taking the issue's item 2 — amortizing the initial hoist
rounds. Related to pnpm/tasks#16; the issue stays open.
The peer-hoist discovery engine keeps one view of the workspace context across
every hoist round and refreshes it before each pass. That refresh walked all
three shared maps end to end (
children_by_id,packages,dependencies_tree), so every round cost one scan of the whole workspaceeven when the round had added a handful of nodes — and every
extend_treebumps the revision that triggers a refresh.
This PR has the context record which keys each write touched, and syncs by
visiting the keys written since the view's cursor.
The design point that makes it safe: only keys are recorded, never values.
The sync reads each key's current value, so a key written several times, or
written by concurrently-walking importers in either order, converges on the
same view. A view discarded after an unmergeable change refills itself by
scanning the shared maps once. The merge logic itself is untouched, so an unmergeable
change — a children-owner handover that re-split a package's children and
peers — still reports the view stale and the engine still rebuilds it.
Measurements, and what each one is worth
In-repo
workspace_full_resolution, newhoist-heavyscenario — the load-bearingnumber. Two binaries built from this branch and from
mainwith an identicalbenchmark file, run interleaved on an idle machine:
mainEvery pair favours the branch; ~7% off the whole resolve (the first branch run is
a warm-up).
Phase timers on the 114-project Bit workspace (resolution-only replay, warm
cache,
offline: true, input lockfile restored before each run; sameinstrumentation on both sides):
The 215 ms that remain are the three view rebuilds a children rewrite forces.
What does not demonstrate this change, stated plainly:
peer-heavyscenario of the same benchmark. main and this branchmeasure identically on it (~850 ms either way, 6 interleaved runs). It hands
every importer all the framework packages up front, so no peer is ever missing,
the auto-install-peers loop converges in one round, and the context is synced
once — the cost this PR removes is never incurred. That gap is why this PR adds
the
hoist-heavyscenario.whose run-to-run spread (±0.4 s on a ~1.7 s mean) is larger than the effect, and
it is the same fixture shape as above, so it would not show this even if it were
quiet.
here: the ranges overlap. Best-of-3 differs by ~0.7 s, consistent with the phase
timers, but three samples at that spread prove nothing on their own.
What is left in the initial rounds, measured
With the sync fixed, the remaining cost of those phases is walking, and it is
concentrated in one place. Counting discovery walks by why they ran:
A children-ownership handover flips other occurrences of the package to lazy
children, which bumps
children_rewrites; every importer whose next round seesa changed counter re-walks its entire direct forest, and the discovery engine
discards its whole cache. Three rewrites in the initial rounds cost ~3.8 s of
re-walking. Two ways to attack that, both needing a decision I did not want to
take unilaterally:
make_non_owner_nodes_lazyalready holds each rewritten node's ancestor
pkgIdWithPatchHashchain, so theset of packages whose cached verdict can be affected is computable. The catch:
find_hittakes the first compatible item in a bucket, so retainingunaffected buckets can change which item wins where a full discard would have
recomputed one — the same class of risk that made the rewrite gating in
perf(resolver): cut large-workspace peer resolution roughly in half #13506 shift bindings.
Sound (false positives only cost time) but needs a per-importer fingerprint of
the packages its walk visited, which is memory the engine does not spend today —
relevant while @pnpm/napi: install of a large graph peaks at >30 GB RSS (per-occurrence tree expansion in peer resolution + hoisted linking) #13540 is reducing peak RSS.
Squash Commit Body
Checklist
already linked to it solves it.
pnpm/port, or the description notes what still needs porting.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-opus-5).
Summary by CodeRabbit
Performance
Bug Fixes
Tests