Repository navigation
perf(resolver): share package ids across the occurrences that name them - #13855
Conversation
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 on the workload in #13681. Every one of those nodes owned a fresh `String` copy of its package id, and every parent-context snapshot copied it again. Holding the id as `Arc<str>` instead makes `realize_children` hand over a refcount rather than allocate, and shrinks the node 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 for the same reason: 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 the conversions on this path stop round-tripping through `String` and reallocating. Peak RSS 3231 -> 3068 MB (-5%, n=3 each, alternating A/B, non-overlapping) on the same replayed install, with a byte-identical lockfile. Refs #13681
PR Summary by Qodoperf(resolver): share package ids across peer-walk occurrences
AI Description
Diagram
High-Level Assessment
Files changed (20)
|
|
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 (2)
💤 Files with no reviewable changes (1)
🚧 Files skipped from review as they are similar to previous changes (1)
📝 WalkthroughWalkthroughThe resolver now stores package identifiers in shared ChangesShared package identifier storage
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 |
Confidence Score: 5/5The PR appears safe to merge. No blocking failure remains. Reviews (4): Last reviewed commit: "test(resolver): assert id sharing throug..." | Re-trigger Greptile |
Code Review by Qodo
1.
|
Micro-Benchmark ResultsLinux |
PR Code Suggestions ✨Warning
Explore these optional code suggestions:
|
|||||||||||||
There was a problem hiding this comment.
Actionable comments posted: 4
🧹 Nitpick comments (2)
pnpm/crates/resolving-deps-resolver/src/resolve_peers/cache.rs (1)
295-296: 🚀 Performance & Scalability | 🔵 Trivial | ⚡ Quick winCompare package IDs as borrowed strings.
Use
resolved_package_id.as_ref()at both cache-comparison sites to avoid allocating temporaryArc<str>values.🤖 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_peers/cache.rs` around lines 295 - 296, Update both cache-comparison sites in the peer resolution logic to compare package IDs as borrowed strings using resolved_package_id.as_ref() against child_pkg_id. Remove the temporary Arc<str> conversions while preserving the existing FastCacheMatch::NoMatch behavior.Sources: Coding guidelines, Path instructions
pnpm/crates/resolving-deps-resolver/src/resolve_dependency_tree/walk.rs (1)
457-461: 🚀 Performance & Scalability | 🔵 Trivial | ⚡ Quick winReuse one package-ID Arc for the map key and package record.
Both insertion paths allocate independent Arc-backed storage for the same package ID.
pnpm/crates/resolving-deps-resolver/src/resolve_dependency_tree/walk.rs#L457-L461: create oneArc<str>fromid.as_str()and useArc::clonefor the map key andResolvedPackage.id.pnpm/crates/resolving-deps-resolver/src/resolve_dependency_tree/reuse.rs#L580-L584: apply the same shared-Arc construction to reused packages.As per path instructions, pacquet Rust code must preserve ownership while sharing identifiers and use explicit
Arc::cloneoperations.🤖 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 457 - 461, In walk.rs lines 457-461, create one Arc<str> from id.as_str() and use explicit Arc::clone operations for both the packages map key and ResolvedPackage.id; apply the same shared-Arc construction in reuse.rs lines 580-584 for reused packages, preserving ownership without independently allocating the package ID.Source: Path instructions
🔇 Additional comments (20)
pnpm/crates/resolving-deps-resolver/src/resolve_peers/cache.rs (1)
212-212: LGTM!Also applies to: 243-243, 350-350, 377-380, 556-568, 583-583, 632-636, 648-648, 677-677
pnpm/crates/resolving-deps-resolver/src/resolve_peers/context.rs (1)
57-57: LGTM!Also applies to: 89-96, 208-208, 294-302, 330-330
pnpm/crates/resolving-deps-resolver/src/resolve_peers/finalize.rs (1)
199-199: LGTM!Also applies to: 399-399, 631-633, 647-647
pnpm/crates/resolving-deps-resolver/src/resolve_peers/walker.rs (1)
161-186: LGTM!Also applies to: 455-455, 540-543, 582-582, 617-617, 682-683, 698-701, 804-804, 837-856, 1031-1031, 1327-1327
pnpm/crates/resolving-deps-resolver/src/resolve_dependency_tree/workspace_ctx/tests.rs (1)
27-27: LGTM!Also applies to: 37-47, 78-97, 170-170, 198-199, 224-224, 270-270, 314-315, 328-328, 349-349, 370-384, 469-469, 493-493, 647-647, 691-691
pnpm/crates/resolving-deps-resolver/src/resolve_peers/cache/tests.rs (1)
24-24: LGTM!Also applies to: 55-55
pnpm/crates/resolving-deps-resolver/src/resolve_peers/discovery/tests.rs (1)
16-16: LGTM!Also applies to: 44-50
pnpm/crates/resolving-deps-resolver/src/resolve_peers/finalize/tests.rs (1)
29-31: LGTM!Also applies to: 101-101, 174-174, 187-187, 203-206, 315-315, 324-324, 343-349, 365-367
pnpm/crates/resolving-deps-resolver/src/resolve_peers/test_support.rs (1)
21-21: LGTM!Also applies to: 63-63, 73-73
pnpm/crates/resolving-deps-resolver/src/resolve_peers/tests.rs (1)
17-301: LGTM!Also applies to: 358-677, 727-1035, 1126-1357, 1415-1664, 1831-1911
pnpm/crates/resolving-deps-resolver/src/resolve_workspace/tests.rs (1)
462-462: LGTM!Also applies to: 638-638, 3099-3099
pnpm/crates/resolving-deps-resolver/src/tests.rs (1)
248-248: LGTM!Also applies to: 320-320, 421-421, 566-566, 637-641, 2290-2290, 2386-2386, 2407-2407
.changeset/shared-package-ids.md (1)
1-5: LGTM!pnpm/crates/deps-path/src/dep_path.rs (1)
38-44: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win
⚠️ Unverified finding
Sandbox verification was unavailable.Use the standard derived conversion for
From<Arc<str>>.This implementation only forwards the wrapped value. Use
derive_more::Fromfor the mechanical conversion. Keep manual implementations for validation or normalization logic.As per coding guidelines, use
derive_more::Fromandderive_more::Intofor mechanical branded-string conversions.pnpm/crates/resolving-deps-resolver/src/resolved_tree.rs (2)
29-29: 🎯 Functional Correctness | 🔴 Critical | ⚡ Quick win
⚠️ Unverified finding
Sandbox verification was unavailable.Update remaining
Stringconstruction sites for the newArc<str>contract.The supplied
pnpm/crates/package-manager/src/dependencies_graph_to_lockfile/tests.rs:1238-1327fixture still passesStringvalues toResolvedTree.packages,ResolvedTree.children_by_id,ResolvedPackage.id,ChildEdge.pkg_id, andDependenciesTreeNode::new. Rust does not perform these conversions implicitly. Those callers will fail to compile until they constructArc<str>values.The supplied downstream snippet shows the un-migrated constructors.
Also applies to: 45-45, 149-149, 263-263
29-29: LGTM!Also applies to: 45-45, 149-149, 239-241
pnpm/crates/resolving-deps-resolver/src/resolved_tree/tests.rs (1)
30-38: LGTM!Also applies to: 42-65
pnpm/crates/resolving-deps-resolver/src/resolve_dependency_tree/walk.rs (1)
446-446: LGTM!Also applies to: 642-642, 759-759, 838-845, 1287-1287, 1313-1313
pnpm/crates/resolving-deps-resolver/src/resolve_dependency_tree/workspace_ctx.rs (1)
234-234: LGTM!Also applies to: 256-271, 539-541, 573-573, 592-601, 684-692, 791-794, 804-804, 929-934, 954-955, 1016-1022, 1061-1061, 1286-1286, 1313-1313, 1417-1420
pnpm/crates/resolving-deps-resolver/src/resolve_importer.rs (1)
1229-1229: LGTM!
🤖 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_dependency_tree/reuse.rs`:
- Line 645: Update the initializer assigning pkg_id in the dependency-tree reuse
loop to pass dep.id directly to Arc::from instead of cloning it. Preserve the
existing ownership flow, matching the consuming pattern used by walk.rs.
In
`@pnpm/crates/resolving-deps-resolver/src/resolve_dependency_tree/workspace_ctx.rs`:
- Around line 1479-1484: Make occurrence IDs reuse the child-edge Arc allocation
throughout the production and realization paths: in workspace_ctx.rs lines
1479-1484, pass the owned Arc<str> into insert_tree_node and clone it for both
the DependenciesTreeNode and reverse index; in resolved_tree.rs lines 55-58,
preserve the sharing contract only after this existing Arc is reused; in
resolved_tree/tests.rs lines 67-85, exercise the production insertion path and
assert pointer equality between the child edge and occurrence node, including
package-ID sharing across occurrences.
In `@pnpm/crates/resolving-deps-resolver/src/resolve_peers/cache.rs`:
- Line 463: Update DeferredChildResolution::Materialize to store Arc<str>; when
creating the deferred resolution, clone edge.pkg_id and pass that Arc directly
to DependenciesTreeNode::new instead of converting through String. Add a
regression test that verifies the child edge and materialized occurrence share
the allocation using Arc::ptr_eq.
In `@pnpm/crates/resolving-deps-resolver/src/resolved_tree/tests.rs`:
- Around line 67-85: Replace the constructor-only test in
realizing_an_occurrence_shares_the_package_id with a fixture that records a
child edge and inserts the occurrence through
WorkspaceTreeCtx::insert_tree_node. Retrieve the resulting node and compare its
package ID Arc with the recorded edge ID using Arc::ptr_eq, preserving the
assertion that the production insertion path shares storage.
---
Nitpick comments:
In `@pnpm/crates/resolving-deps-resolver/src/resolve_dependency_tree/walk.rs`:
- Around line 457-461: In walk.rs lines 457-461, create one Arc<str> from
id.as_str() and use explicit Arc::clone operations for both the packages map key
and ResolvedPackage.id; apply the same shared-Arc construction in reuse.rs lines
580-584 for reused packages, preserving ownership without independently
allocating the package ID.
In `@pnpm/crates/resolving-deps-resolver/src/resolve_peers/cache.rs`:
- Around line 295-296: Update both cache-comparison sites in the peer resolution
logic to compare package IDs as borrowed strings using
resolved_package_id.as_ref() against child_pkg_id. Remove the temporary Arc<str>
conversions while preserving the existing FastCacheMatch::NoMatch behavior.
🪄 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: 448f2e7f-dfb3-4fbe-bdda-577dc7007919
📒 Files selected for processing (20)
.changeset/shared-package-ids.mdpnpm/crates/deps-path/src/dep_path.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_importer.rspnpm/crates/resolving-deps-resolver/src/resolve_peers/cache.rspnpm/crates/resolving-deps-resolver/src/resolve_peers/cache/tests.rspnpm/crates/resolving-deps-resolver/src/resolve_peers/context.rspnpm/crates/resolving-deps-resolver/src/resolve_peers/discovery/tests.rspnpm/crates/resolving-deps-resolver/src/resolve_peers/finalize.rspnpm/crates/resolving-deps-resolver/src/resolve_peers/finalize/tests.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/resolve_workspace/tests.rspnpm/crates/resolving-deps-resolver/src/resolved_tree.rspnpm/crates/resolving-deps-resolver/src/resolved_tree/tests.rspnpm/crates/resolving-deps-resolver/src/tests.rs
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.5824254279599996,
"stddev": 0.19129961750943308,
"median": 2.48341527326,
"user": 2.1958743000000003,
"system": 1.6626986000000001,
"min": 2.39513209376,
"max": 2.86486152176,
"times": [
2.86486152176,
2.45136730676,
2.83642284676,
2.43609280876,
2.66970780176,
2.4240809027599997,
2.39513209376,
2.80534628176,
2.51546323976,
2.4257794757599997
]
},
{
"command": "pacquet@main",
"mean": 2.6608980320599995,
"stddev": 0.17664491126907292,
"median": 2.67985899876,
"user": 2.3591946,
"system": 1.7146127999999998,
"min": 2.4295236177599997,
"max": 2.9347039367599996,
"times": [
2.8130234487599997,
2.47319354976,
2.7998135977599996,
2.4295236177599997,
2.60028359876,
2.60564360776,
2.43862510576,
2.9347039367599996,
2.76009546776,
2.75407438976
]
},
{
"command": "pnpr@HEAD",
"mean": 1.5948613108600003,
"stddev": 0.17436878490698582,
"median": 1.59962727526,
"user": 1.6191290999999999,
"system": 1.4661944,
"min": 1.39642978776,
"max": 1.8292723157600002,
"times": [
1.7050226747600001,
1.7809797517600001,
1.4531496837600002,
1.4109989737600002,
1.4942318757600002,
1.7452943247600001,
1.71544839676,
1.39642978776,
1.8292723157600002,
1.4177853237600002
]
},
{
"command": "pnpr@main",
"mean": 1.54589014326,
"stddev": 0.18616723856874257,
"median": 1.4394451377600002,
"user": 1.5050656999999998,
"system": 1.3707460999999996,
"min": 1.3771295467600002,
"max": 1.8335910287600001,
"times": [
1.4003740077600002,
1.4002451577600001,
1.8037637997600002,
1.4785162677600001,
1.3771295467600002,
1.39756837176,
1.8335910287600001,
1.3915582637600001,
1.71037767576,
1.6657773127600002
]
}
]
}Scenario: Isolated linker: fresh restore, hot cache + hot store
BENCHMARK_REPORT.json{
"results": [
{
"command": "pacquet@HEAD",
"mean": 0.26517939606,
"stddev": 0.008965886945696411,
"median": 0.26522222356,
"user": 0.23749225999999996,
"system": 0.53550238,
"min": 0.25044997256,
"max": 0.28571929856000006,
"times": [
0.26703159356,
0.26356157056,
0.25902068856000005,
0.25044997256,
0.26629919956000003,
0.28571929856000006,
0.26812348856,
0.26015629556000003,
0.26728660556,
0.26414524756
]
},
{
"command": "pacquet@main",
"mean": 0.26437865286,
"stddev": 0.010845953684513611,
"median": 0.26407568006000004,
"user": 0.23065296000000002,
"system": 0.5382645800000001,
"min": 0.25119361956,
"max": 0.27999872156000005,
"times": [
0.25119361956,
0.27551196556,
0.25868867256000005,
0.25128161156,
0.27999872156000005,
0.27280590356,
0.25482948156,
0.25712722356,
0.27288664156000003,
0.26946268756
]
},
{
"command": "pnpr@HEAD",
"mean": 0.28872838966000003,
"stddev": 0.012074868013815103,
"median": 0.28495116556,
"user": 0.23821486000000003,
"system": 0.5538143800000002,
"min": 0.27489456656000005,
"max": 0.31275317856,
"times": [
0.30308971656000006,
0.29050465756000005,
0.28201730056,
0.27850899756,
0.28683029156,
0.28307203956000004,
0.31275317856,
0.29639385256,
0.27921929556,
0.27489456656000005
]
},
{
"command": "pnpr@main",
"mean": 0.33091331796000006,
"stddev": 0.054231353886346666,
"median": 0.31263285656000006,
"user": 0.29951676000000005,
"system": 0.6417544800000001,
"min": 0.27851354056000005,
"max": 0.44255741356000006,
"times": [
0.33310443156,
0.44255741356000006,
0.34973785456000006,
0.30808845556000003,
0.40522095756000004,
0.29367444256,
0.31717725756000004,
0.27851354056000005,
0.29371691956,
0.28734190656
]
}
]
}Scenario: Isolated linker: fresh install, cold cache + cold store
BENCHMARK_REPORT.json{
"results": [
{
"command": "pacquet@HEAD",
"mean": 2.9568738887999997,
"stddev": 0.06644344041993927,
"median": 2.9635562136999996,
"user": 2.57480164,
"system": 2.0255803599999997,
"min": 2.8145939997,
"max": 3.0388403437,
"times": [
2.8145939997,
2.9538012596999996,
2.9733111677,
3.0277336886999997,
2.9915432426999997,
2.9294636857,
2.9238669237,
2.9107532407,
3.0388403437,
3.0048313356999996
]
},
{
"command": "pacquet@main",
"mean": 2.8918528041,
"stddev": 0.0920677236643219,
"median": 2.8920658847,
"user": 2.40625324,
"system": 1.87055446,
"min": 2.7328466937,
"max": 3.0446020007,
"times": [
2.9830864307,
3.0446020007,
2.9462834197,
2.8070194517,
2.8217019487,
2.8559985467,
2.8782510627,
2.9428577796999997,
2.9058807066999996,
2.7328466937
]
},
{
"command": "pnpr@HEAD",
"mean": 1.7372788020999999,
"stddev": 0.16544161511256683,
"median": 1.7520310102,
"user": 1.6285056400000002,
"system": 1.5475408599999998,
"min": 1.4962221917,
"max": 1.9285075127000002,
"times": [
1.8204378077,
1.5721192537000002,
1.9285075127000002,
1.4962221917,
1.7201101257,
1.5097256647000001,
1.7136274147000001,
1.9049775237000002,
1.9231086317000001,
1.7839518947000002
]
},
{
"command": "pnpr@main",
"mean": 1.6686939846000002,
"stddev": 0.20040937294896055,
"median": 1.6254303602000002,
"user": 1.61998614,
"system": 1.50374886,
"min": 1.4702308707,
"max": 1.9907846057,
"times": [
1.7876182687,
1.9583375727,
1.9907846057,
1.7215267527000002,
1.4702308707,
1.5202630747,
1.7454647147,
1.4709682487,
1.4924117697000001,
1.5293339677000002
]
}
]
}Scenario: Isolated linker: fresh install, hot cache + hot store
BENCHMARK_REPORT.json{
"results": [
{
"command": "pacquet@HEAD",
"mean": 0.51314622278,
"stddev": 0.036290355391139846,
"median": 0.51382658858,
"user": 0.679053,
"system": 0.8313810799999999,
"min": 0.45954400358,
"max": 0.57251115358,
"times": [
0.52503278458,
0.51242553558,
0.48833282758,
0.55503356958,
0.53766642858,
0.51522764158,
0.49867839158000005,
0.57251115358,
0.45954400358,
0.46700989158
]
},
{
"command": "pacquet@main",
"mean": 0.45754960588000004,
"stddev": 0.043399552826835434,
"median": 0.45553696408,
"user": 0.5822697,
"system": 0.7325527799999999,
"min": 0.40601303158,
"max": 0.53117599458,
"times": [
0.50254881158,
0.46159661458,
0.53117599458,
0.49906327258,
0.47013933858,
0.44947731358000004,
0.41511703558,
0.40601303158,
0.40807195958000003,
0.43229268658000003
]
},
{
"command": "pnpr@HEAD",
"mean": 0.29872216358000003,
"stddev": 0.013390248844475474,
"median": 0.29361124808,
"user": 0.2056899,
"system": 0.50902308,
"min": 0.28713570858,
"max": 0.32961661758,
"times": [
0.32961661758,
0.30367076858000003,
0.28977868458,
0.28740541458,
0.29526784058,
0.28870257258,
0.29195465558,
0.30575890158,
0.30793047158000003,
0.28713570858
]
},
{
"command": "pnpr@main",
"mean": 0.30382648878,
"stddev": 0.018145368552529646,
"median": 0.29539725958,
"user": 0.21828849999999997,
"system": 0.50338248,
"min": 0.28955183958,
"max": 0.33681318158,
"times": [
0.29164046858000003,
0.28970536358,
0.29548937458,
0.28955183958,
0.33681318158,
0.33156046858,
0.29991277658,
0.29005972758,
0.29530514458,
0.31822654258
]
}
]
}Scenario: Isolated linker: fresh install, cold cache + hot store
BENCHMARK_REPORT.json{
"results": [
{
"command": "pacquet@HEAD",
"mean": 2.12675014942,
"stddev": 0.22597742276951424,
"median": 2.1186399216200003,
"user": 1.1945696,
"system": 1.1715296799999997,
"min": 1.86740390612,
"max": 2.63682712812,
"times": [
1.86740390612,
1.88440262312,
1.96978970012,
2.63682712812,
2.20716327612,
2.00623719512,
2.0624375281200003,
2.21589203612,
2.1748423151200003,
2.24250578612
]
},
{
"command": "pacquet@main",
"mean": 2.00213588822,
"stddev": 0.03951002512325133,
"median": 1.99917019012,
"user": 1.0760977,
"system": 1.0263455799999999,
"min": 1.94960910812,
"max": 2.0793227041200004,
"times": [
2.0145550681200004,
2.0793227041200004,
2.04235189312,
2.01364111112,
1.97854286112,
1.98469926912,
1.94960910812,
2.0207006571200004,
1.97236350112,
1.9655727091200001
]
},
{
"command": "pnpr@HEAD",
"mean": 0.31967645672,
"stddev": 0.02553372892295883,
"median": 0.30715231212000005,
"user": 0.2187074,
"system": 0.56299638,
"min": 0.29152174512,
"max": 0.36408153912,
"times": [
0.36408153912,
0.35283828712000004,
0.33124852612,
0.30876103112000003,
0.30266165512000004,
0.29804755612,
0.29152174512,
0.30115873112,
0.30554359312,
0.34090190312
]
},
{
"command": "pnpr@main",
"mean": 0.30404087112000006,
"stddev": 0.012088089151992054,
"median": 0.30487445812,
"user": 0.1943276,
"system": 0.53978228,
"min": 0.28760444712,
"max": 0.32716294112,
"times": [
0.32716294112,
0.30954397512000004,
0.28811044012000003,
0.29513627312,
0.30240063212,
0.28760444712,
0.31327962112,
0.30009140112,
0.30734828412000004,
0.30973069612000004
]
}
]
}Scenario: Isolated linker: fresh resolve, hot cache, offline
BENCHMARK_REPORT.json{
"results": [
{
"command": "pacquet@HEAD",
"mean": 0.2665720220133334,
"stddev": 0.03600989663198067,
"median": 0.27005935848000007,
"user": 0.22028032666666666,
"system": 0.08835091333333334,
"min": 0.19466452048000002,
"max": 0.3257278114800001,
"times": [
0.19466452048000002,
0.23054253448,
0.22240286048000002,
0.24785154648000002,
0.3257278114800001,
0.29390801948000006,
0.25179452448000006,
0.29702458748000005,
0.29859690948000006,
0.28919920548000005,
0.28531115348,
0.29867092048000005,
0.27005935848000007,
0.23529113348000003,
0.25753524448000004
]
},
{
"command": "pacquet@main",
"mean": 0.23158917097999998,
"stddev": 0.011878748893002127,
"median": 0.23118088148000002,
"user": 0.17006194333333333,
"system": 0.05506527999999999,
"min": 0.20533731848,
"max": 0.25180789648,
"times": [
0.23136120548000003,
0.23441268948000002,
0.23076718648000002,
0.24058096648000002,
0.23100055748,
0.21984354748,
0.24169883248000001,
0.25180789648,
0.22625726348000003,
0.20533731848,
0.23977306348000002,
0.22622952448
]
},
{
"command": "pnpr@HEAD",
"mean": 0.0902959892864516,
"stddev": 0.0032118572005253323,
"median": 0.09028880248,
"user": 0.02149469870967742,
"system": 0.011942503870967743,
"min": 0.08567021048000001,
"max": 0.09730420548,
"times": [
0.09028880248,
0.09217580448,
0.09476116148000001,
0.09486711248,
0.08799776848,
0.09318029948,
0.08991806248,
0.09131892148000001,
0.09108115848000001,
0.09243223448,
0.08896244448,
0.09730420548,
0.08567021048000001,
0.08763257548,
0.08639637848000001,
0.09055986548,
0.09275383948,
0.09020897048,
0.09606618648000001,
0.08679551448,
0.08738420448,
0.09270393548,
0.08787923348,
0.08612584848,
0.08706604248000001,
0.09051285448,
0.08688498348000001,
0.09168647448,
0.09438662748,
0.08710571148,
0.08706823548
]
},
{
"command": "pnpr@main",
"mean": 0.09132190699612906,
"stddev": 0.003246680019051491,
"median": 0.09093812148000001,
"user": 0.020092247096774193,
"system": 0.014072296129032262,
"min": 0.08526660748,
"max": 0.10148473748,
"times": [
0.08897146148,
0.08648933748,
0.09261697148,
0.09153498848000001,
0.09435949848,
0.08526660748,
0.09326723148,
0.09509999148,
0.08888454148000001,
0.09000992348,
0.09231374548,
0.09127949648,
0.09173982948,
0.09665198248000001,
0.09067947348000001,
0.09186604048000001,
0.08950605348,
0.09017547448,
0.08778753748000001,
0.09160787148,
0.09623380048,
0.08795129548000001,
0.10148473748,
0.09032827548,
0.09090328148,
0.09074804248,
0.08666406548000001,
0.09177675848,
0.09093812148000001,
0.09324765748000001,
0.09059502348000001
]
}
]
}Scenario: Isolated linker: peer-heavy resolve, hot cache, offline
BENCHMARK_REPORT.json{
"results": [
{
"command": "pacquet@HEAD",
"mean": 0.522471818208889,
"stddev": 0.07012572870694073,
"median": 0.5159445743200001,
"user": 0.48876868,
"system": 0.1247643711111111,
"min": 0.39730032732,
"max": 0.61686227532,
"times": [
0.61686227532,
0.5159445743200001,
0.5466010953200001,
0.49168602932,
0.39730032732,
0.5654197453200001,
0.47346511832,
0.60950589732,
0.48546130132
]
},
{
"command": "pacquet@main",
"mean": 0.5642204309866667,
"stddev": 0.13677191684973747,
"median": 0.5360882143200001,
"user": 0.5305029022222222,
"system": 0.12637492666666666,
"min": 0.40119556832000003,
"max": 0.8135356763200001,
"times": [
0.48436365732000003,
0.8135356763200001,
0.48404148732,
0.5394244863200001,
0.44169616532,
0.40119556832000003,
0.70675356432,
0.5360882143200001,
0.6708850593200001
]
},
{
"command": "pnpm@HEAD",
"mean": 3.0754828942088888,
"stddev": 0.1919495538315992,
"median": 3.02906105332,
"user": 4.299499902222221,
"system": 0.3282845933333333,
"min": 2.87999365632,
"max": 3.4641336793199997,
"times": [
2.90384879532,
2.87999365632,
3.02906105332,
2.97039594132,
3.06453669432,
3.31395943832,
3.05001366232,
3.4641336793199997,
3.00340312732
]
}
]
}Scenario: Isolated linker: fresh restore, cold cache + cold store + cold pnpr
BENCHMARK_REPORT.json{
"results": [
{
"command": "pacquet@HEAD",
"mean": 4.60464550444,
"stddev": 0.10814208271684489,
"median": 4.61350525374,
"user": 2.09966264,
"system": 1.54828044,
"min": 4.43168778024,
"max": 4.77057975524,
"times": [
4.77057975524,
4.43168778024,
4.604345920239999,
4.76505236624,
4.635461622239999,
4.629726896239999,
4.48523874124,
4.55871706524,
4.62266458724,
4.54298031024
]
},
{
"command": "pacquet@main",
"mean": 4.52356369344,
"stddev": 0.10641545223129419,
"median": 4.4887690962399995,
"user": 1.9402475399999997,
"system": 1.51530294,
"min": 4.423369860239999,
"max": 4.779433023239999,
"times": [
4.47673136424,
4.431578947239999,
4.779433023239999,
4.45898582124,
4.607368312239999,
4.56746102224,
4.481488381239999,
4.49604981124,
4.423369860239999,
4.51317039124
]
},
{
"command": "pnpr@HEAD",
"mean": 3.59315848404,
"stddev": 0.13098607155860043,
"median": 3.56165428774,
"user": 1.3246142399999996,
"system": 1.24538374,
"min": 3.45065249124,
"max": 3.8244311412400003,
"times": [
3.51346196224,
3.47567664324,
3.63073208124,
3.54567531224,
3.45065249124,
3.57763326324,
3.67485192524,
3.77500148924,
3.46346853124,
3.8244311412400003
]
},
{
"command": "pnpr@main",
"mean": 3.51299876474,
"stddev": 0.05928373193187056,
"median": 3.49312531874,
"user": 1.32723544,
"system": 1.26024554,
"min": 3.4545847642400003,
"max": 3.6302940932400003,
"times": [
3.52251659124,
3.4695599292400003,
3.46977539524,
3.46203787124,
3.6302940932400003,
3.49455743224,
3.59284688524,
3.54212148024,
3.4545847642400003,
3.4916932052400003
]
}
]
} |
|
| Project | pnpm's project |
| Branch | pr/13855 |
| 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,496.22 ms |
| isolated-linker.fresh-install.cold-cache.hot-store | 📈 view plot | 291.52 ms |
| isolated-linker.fresh-install.hot-cache.hot-store | 📈 view plot | 287.14 ms |
| isolated-linker.fresh-resolve.hot-cache.offline | 📈 view plot | 85.67 ms |
| isolated-linker.fresh-restore.cold-cache.cold-store | 📈 view plot | 1,396.43 ms |
| isolated-linker.fresh-restore.cold-cache.cold-store.cold-pnpr | 📈 view plot | 3,450.65 ms |
| isolated-linker.fresh-restore.hot-cache.hot-store | 📈 view plot | 274.89 ms |
… sites
CI caught three things the resolver-only check did not:
- `pacquet-package-manager`'s lockfile fixture builds a `ResolvedTree`
directly, so it needs the shared id type too.
- Two `use std::sync::Arc` lines sat beside an existing `use std::{...}`,
which the repo's import lint rejects.
- The fixture's `Arc` clones need `Arc::<str>::clone`, per
`clippy::clone_on_ref_ptr`.
My local run had been checking two crates and silently skipping every
test target: `pretty_assertions` was corrupt in this machine's cargo
registry, so `--all-targets` failed to compile a dependency and I read
that as unrelated noise. Re-extracting it surfaced the real errors.
|
Code review by qodo was updated up to the latest commit 012a3c2 |
PR Code Suggestions ✨Warning
No code suggestions found for the PR. |
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #13855 +/- ##
==========================================
+ Coverage 88.24% 88.25% +0.01%
==========================================
Files 627 627
Lines 103300 103370 +70
==========================================
+ Hits 91152 91230 +78
+ Misses 12148 12140 -8 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
…hare Review caught that the conversion to `Arc<str>` had left `Arc::from` calls on paths that previously did no allocation at all, which is the opposite of the point. - `find_fast_hit`'s package-id checks built a whole `Arc<str>` per comparison, in the cache-matching loop. Comparing through `&*` is what was meant. - `packages.insert` allocated the id twice — once for the key, once for `ResolvedPackage::id` — where one shared allocation serves both. - `deferred_child_resolution` took `&str` and rebuilt an `Arc` its only caller already held; it now takes `&Arc<str>` and carries the caller's allocation through `Materialize`. - `insert_tree_node` went `&str -> String -> Arc<str>`, and two `ChildEdge` builders cloned a `String` before converting it. - One `Arc::clone` fed straight into `to_string`, bumping a refcount for nothing. `DepPath`'s `From<Arc<str>>` is now derived. Per `pnpm/CLAUDE.md`, `derive_more::From` is the convention when the conversion only wraps the inner field; the `String` and `&str` conversions stay handwritten because they allocate. The measured win improves with these: peak RSS 3264 -> 3046 MB (-6.7%, n=3 alternating A/B, was -5% before), lockfile unchanged.
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 0517cb7 |
…ions of nodes The previous test handed an `Arc` to `DependenciesTreeNode::new` and asserted it came back, which only proves the constructor keeps its argument. It would pass while every occurrence still owned a separate copy of its package id — the exact thing this change is about. `realize_children_with` is where the millions of occurrences are created, so the test now realizes a recorded child edge through it and compares the edge's `Arc` with the resulting node's. Reverted against a realization that copies the id, it fails.
PR Code Suggestions ✨Warning
No code suggestions found for the PR. |
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 4caa998 |
PR Code Suggestions ✨Warning
No code suggestions found for the PR. |
…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.
Follow-up to #13844 on the same workload from #13681.
A workspace has a few thousand distinct
pkgIdWithPatchHashvalues, 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 freshStringcopy of its package id, and every parent-context snapshot copied it again.Changes
DependenciesTreeNode::resolved_package_idandChildEdge::pkg_idbecomeArc<str>.realize_childrennow hands over a refcount instead of allocating, and the node shrinks from 56 to 48 bytes. The maps keyed by package id move toArc<str>keys with it —Arc<str>: Borrow<str>keeps&strlookups working, andArc<str>hashes as itsstr, so iteration order is unchanged.ParentPkgInfo::pkg_idfollows. 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.DepPathgainsFrom<Arc<str>>. It already wraps anArc<str>, so these conversions stop round-tripping throughStringand reallocating.Result
main3264 → 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::fromcalls on paths that previously did no allocation at all — comparisons in the cache-matching loop, a double allocation inpackages.insert, a&str → String → Arc<str>round-trip. Removing them is what took it to −6.7%.)Correctness
The lockfile is byte-identical —
maintwice 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 fmtandcargo dylintclean 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_idasserts pointer equality throughrealize_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.What this still does not fix
The occurrence count itself, which is the remaining ~85%. As measured in #13681, 91% of full walks end in a cycle and cycle-resolved walks are never cached (#5108), so
find_hitsucceeds 155 times in 188,862 lookups and nearly every occurrence re-walks its subtree. Everything sized by that 2M count — the tree,node_dep_paths,visited_this_call, the three per-node peer maps — stays proportional to it.Fixing that means caching cycle-resolved verdicts under a key that captures which ancestor repetition truncated the subtree. I have not attempted it because getting the invariant wrong produces wrong lockfiles rather than merely slow ones, and #5108 suggests it is subtle. Still happy to take it on with a steer on the intended rule.
Refs #13681
Need help on this PR? Tag
@codesmith-botwith what you need. Autofix is disabled.Summary by CodeRabbit
Performance Improvements
Bug Fixes
Tests