Repository navigation
perf(resolver): cache cycle-truncated peer verdicts, scoped to their truncation - #13859
Conversation
…truncation A walk that re-enters a package already on its ancestor chain resolves against a truncated subtree, so its verdict was never cached (#5108: reusing it where the subtree is intact drops transitivePeerDependencies depending on traversal order). On a peer-cyclic graph that rule makes the peers cache inert: resolving the bit monorepo's env packages, 91% of 188,707 full walks ended in a cycle, the cache hit 155 times in 188,862 lookups, and the walk realized 2,008,130 occurrence nodes for a 6,133-node graph. The truncation is not arbitrary, though. `realize_children_with` drops exactly the edges `forms_cycle` finds in the occurrence's own ancestor ids, so the verdict is a function of (package, peer context, the chain entries the gate weighs). Everything else in the chain is noise. This change makes that precise and caches on it: - Every full walk keeps a `ConsultedPkgs` frame — a bitset over interned package ids — and realization marks the package whose children are being 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, and a cache hit folds the stored entry's set into the running frame, so an outer frame always covers the dependence of everything under it. - A cycle-resolved verdict is now stored, tagged with a `CycleTruncationKey`: its consulted set plus the occurrence's ancestor ids restricted to it, base entries first. `forms_cycle` treats the base and appended halves differently, so the boundary is part of the key. - `find_hit` hands a tagged verdict only to an occurrence whose ancestor ids, restricted to the entry's consulted set, are exactly the recorded chain. Equal restrictions mean every gate answer the walk depends on is equal, which by induction means the same realization, the same truncation, and the same verdict. Occurrences that don't match — in particular ones whose ancestors don't truncate the subtree at all — re-walk, exactly as before. The fast cache paths have no ancestor ids to compare and skip tagged entries entirely. - The bit index and the interned consulted sets live in `PeerDiscoveryCaches`, since the cache items they interpret already persist across discovery and main walks. On the workload above, full walks drop from 188,707 to 33,648 and cycle-resolved walks from 171,508 to 16,563; the keyed entries are hit 44,999 times. Peak RSS falls from 3047 MB to 1412 MB (-54%, n=3 each, alternating A/B, non-overlapping) and wall time roughly halves. Output changes only within the resolver's existing order-sensitivity envelope (#13846): 13 snapshot entries in the same @teambit cluster that already flips between identical stock runs pick a different valid peer variant. Both directions were checked as fixed points — the unmodified engine, handed this branch's lockfile as wanted, preserves it byte for byte, and this branch preserves the unmodified engine's lockfile byte for byte — so repeat installs never churn, which is the regression #5108 guards. Cold output is deterministic across runs. Refs #13681
|
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 tracks consulted packages during peer walks and caches cycle-truncated resolutions with matching ancestor-chain context. Cache lookup rejects incompatible cycle verdicts, while reusable consulted-package sets persist through discovery caches. ChangesScoped cycle verdict caching
Estimated code review effort: 4 (Complex) | ~45 minutes Sequence Diagram(s)sequenceDiagram
participant Walker
participant AncestorIds
participant PeerDiscoveryCaches
participant PeersCache
Walker->>AncestorIds: Read base and appended ancestor IDs
Walker->>PeerDiscoveryCaches: Record consulted packages and intern sets
Walker->>PeersCache: Look up resolution with cycle context
PeersCache-->>Walker: Return a matching cached verdict
Walker->>PeersCache: Store a cycle key on an eligible truncated 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 |
PR Summary by QodoCache cycle-truncated peer-resolution verdicts keyed by consulted ancestors
AI Description
Diagram
High-Level Assessment
Files changed (6)
|
Confidence Score: 4/5The PR is not yet safe to merge because an already-realized provider preview can still produce an incompletely scoped cycle-cache verdict. The realized preview branch returns before recording the package and child IDs, and the immediately following cache-hit path can exit without reaching the realization branch where those inputs are marked, leaving incorrect peer-verdict reuse reachable. Files Needing Attention: pnpm/crates/resolving-deps-resolver/src/resolve_peers/cache.rs, pnpm/crates/resolving-deps-resolver/src/resolve_peers/walker.rs
|
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #13859 +/- ##
==========================================
+ Coverage 88.26% 88.29% +0.03%
==========================================
Files 627 627
Lines 103370 103689 +319
==========================================
+ Hits 91235 91550 +315
- Misses 12135 12139 +4 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
Micro-Benchmark ResultsLinux |
There was a problem hiding this comment.
🧹 Nitpick comments (3)
pnpm/crates/resolving-deps-resolver/src/resolve_peers/cache.rs (1)
388-394: 📐 Maintainability & Code Quality | 🔵 Trivial | 💤 Low valueCorrect the comment: this path does have an ancestor chain.
parent_idsis in scope from the enclosing signature, andfind_fast_hitonly calls this for aTreeChildren::Lazynode. Soparent_idsis the same pre-realization chain thatresolve_nodecaptures astruncation_ids. The comment says no chain exists, which is not accurate.Skipping keyed entries is sound, because it only loses hits. Two options:
- Minimum: reword the comment to state that the fast path deliberately stays on unkeyed entries.
- Optional follow-up: pass
parent_idstoCycleTruncationKey::matcheshere. That would recover fast-path hits on the peer-cyclic graphs this PR targets. Keep it out of this PR if you want to limit scope.♻️ Proposed comment correction
self.peers_cache.get(pkg_id)?.iter().find(|item| { - // The fast paths have no ancestor chain to compare, so they - // stay on the entries that never needed one. + // The fast paths deliberately stay on entries that never needed + // an ancestor chain. `parent_ids` could validate a keyed entry, + // but the fast path is kept free of that comparison. item.cycle_key.is_none()This follows the coding guideline: "Comments should document contracts, non-obvious invariants, workarounds, deliberate exceptions, or unavoidable technical constraints, and should describe current behavior rather than historical implementation details."
🤖 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 388 - 394, Correct the comment immediately above the cycle_key check in find_fast_hit to state that the fast path deliberately considers only entries without a cycle key, rather than claiming no ancestor chain exists. Keep the existing matching behavior unchanged; do not add parent_ids to CycleTruncationKey::matches unless expanding scope.Source: Coding guidelines
pnpm/crates/resolving-deps-resolver/src/resolve_peers/cache/tests.rs (1)
110-160: 🎯 Functional Correctness | 🔵 Trivial | ⚡ Quick winAdd a boundary case with
base_len > 0.The assertions are behavioral and exercise
find_hiton the production path. Coverage of matching and non-matching consulted chains is complete.One boundary shape is missing.
keyed_itemhardcodesbase_len = 0, so every recorded key holds its whole chain in the appended half. Line 152 therefore only tests one direction of thebase_lencheck: recorded0against a current chain with two consulted base ids. A key withbase_len > 0, and a mixed base-plus-appended key, stay unexercised.Walker::build_cycle_keyproducesbase_len > 0whenever a consulted id sits in the base half, so this shape occurs in real walks.Let
keyed_itemtake a base/appended split, then assert that a key recorded withbase_len > 0rejects the same ids moved into the appended half.💚 Proposed test extension
fn keyed_item( walker: &mut crate::resolve_peers::walker::Walker<'_>, - chain: &[&str], + base: &[&str], + appended: &[&str], ) -> PeersCacheItem { // Consulted set = exactly the ids in `chain`, registered through the // walker's bit index the way a real walk would. let mut bits = ConsultedPkgs::default(); - for id in chain { + for id in base.iter().chain(appended) { let next = walker.consulted_bit_by_pkg.len() as u32; let bit = *walker.consulted_bit_by_pkg.entry(Arc::from(*id)).or_insert(next); bits.set(bit); } PeersCacheItem { dep_path: DepPath::from("[email protected]"), resolved_peers: Arc::new(HashMap::default()), missing_peers: Arc::new(HashMap::default()), missing_peers_of_children: Arc::new(HashMap::default()), subtree_missing_by_pkg: None, cycle_key: Some(CycleTruncationKey::new( Arc::new(bits), - chain.iter().map(|id| Arc::from(*id)).collect(), - 0, + base.iter().chain(appended).map(|id| Arc::from(*id)).collect(), + u32::try_from(base.len()).expect("test chain fits in u32"), )), } }Then add a test for the recorded-base direction:
/// A key recorded with consulted ids in the base half must reject the /// same ids in the appended half: `forms_cycle` answers the two halves /// differently, so `base_len` is part of the key in both directions. #[test] fn a_cycle_verdict_is_scoped_to_the_base_appended_boundary() { let mut tree = ResolvedTree::default(); let mut walker = walker_for_tests(&mut tree); let item = keyed_item(&mut walker, &["[email protected]"], &["[email protected]"]); walker.peers_cache.insert("[email protected]".to_string(), vec![item]); let refs = HashMap::default(); assert!( walker .find_hit(&refs, "[email protected]", Some(&ancestors(&["[email protected]"], &["[email protected]"]))) .is_some(), "the same base/appended split reuses the verdict", ); assert!( walker .find_hit(&refs, "[email protected]", Some(&ancestors(&[], &["[email protected]", "[email protected]"]))) .is_none(), "moving a consulted id out of the base half is a different truncation", ); }This follows the path instructions, which require "regression tests for matching and non-matching keys" and state "Add tests that cover the cache-key boundary cases and verify they fail without the fix."
🤖 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/tests.rs` around lines 110 - 160, Add coverage for the base/appended boundary in `a_cycle_verdict_is_scoped_to_ancestors_that_truncate_identically`: change `keyed_item` to accept separate base and appended ids, then add `a_cycle_verdict_is_scoped_to_the_base_appended_boundary` using a non-empty base. Assert the matching split reuses the verdict while moving the consulted base id into the appended half returns no hit.Source: Path instructions
pnpm/crates/resolving-deps-resolver/src/resolve_peers/walker.rs (1)
277-302: 🚀 Performance & Scalability | 🔵 Trivial | 💤 Low valueOptional: reuse the interned
Arc<str>and cut one clone from the interning path.The key construction is correct and mirrors
CycleTruncationKey::matchesin filter order andbase_lenaccounting.Two contained allocation nits on a hot path:
Arc::from(id)at Lines 285 and 291 allocates a newArc<str>for each consulted chain entry.consulted_bit_by_pkgalready holds anArc<str>for that id, and theconsultedclosure just looked it up. Switch the closure toget_key_valueand clone the existingArc.- The interning block at Lines 294-300 clones
frametwice on the miss path. The entry API needs one clone.⚡ Proposed allocation reuse
fn build_cycle_key(&mut self, ids: &AncestorIds, frame: &ConsultedPkgs) -> CycleTruncationKey { - let consulted = |bit_by_pkg: &HashMap<Arc<str>, u32>, id: &str| { - bit_by_pkg.get(id).is_some_and(|bit| frame.contains(*bit)) - }; + // Yields the interned key so the chain shares the bit map's + // allocation instead of making a new one per entry. + let consulted = |bit_by_pkg: &'_ HashMap<Arc<str>, u32>, id: &str| { + bit_by_pkg + .get_key_value(id) + .filter(|(_, bit)| frame.contains(**bit)) + .map(|(interned, _)| Arc::clone(interned)) + }; let mut chain: Vec<Arc<str>> = Vec::new(); let mut base_len = 0u32; for id in ids.base_ids() { - if consulted(&self.consulted_bit_by_pkg, id) { - chain.push(Arc::from(id)); + if let Some(interned) = consulted(&self.consulted_bit_by_pkg, id) { + chain.push(interned); base_len += 1; } } for id in ids.appended_ids() { - if consulted(&self.consulted_bit_by_pkg, id) { - chain.push(Arc::from(id)); + if let Some(interned) = consulted(&self.consulted_bit_by_pkg, id) { + chain.push(interned); } } - let shared = if let Some(hit) = self.consulted_sets.get(frame) { - Arc::clone(hit) - } else { - let arc = Arc::new(frame.clone()); - self.consulted_sets.insert(frame.clone(), Arc::clone(&arc)); - arc - }; + let shared = Arc::clone( + self.consulted_sets + .entry(frame.clone()) + .or_insert_with(|| Arc::new(frame.clone())), + ); CycleTruncationKey::new(shared, chain, base_len) }The
entryform still clonesframefor the key on both paths, so if the hit rate is high, keep the currentget-first shape and apply only change 1.This follows the path instruction from
pnpm/CODE_STYLE_GUIDE.md: "choose owned versus borrowed types to avoid unnecessary cloning" and "preferArc::clonefor reference-counted 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/walker.rs` around lines 277 - 302, Update build_cycle_key so the consulted lookup returns the existing Arc<str> via get_key_value, then push an Arc::clone of that key instead of constructing Arc::from(id) for both base_ids and appended_ids. Preserve the current filtering order and base_len accounting; leave the consulted_sets interning block unchanged unless a one-clone entry-API change can be made without cloning frame on cache hits.Source: Path instructions
🤖 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.
Nitpick comments:
In `@pnpm/crates/resolving-deps-resolver/src/resolve_peers/cache.rs`:
- Around line 388-394: Correct the comment immediately above the cycle_key check
in find_fast_hit to state that the fast path deliberately considers only entries
without a cycle key, rather than claiming no ancestor chain exists. Keep the
existing matching behavior unchanged; do not add parent_ids to
CycleTruncationKey::matches unless expanding scope.
In `@pnpm/crates/resolving-deps-resolver/src/resolve_peers/cache/tests.rs`:
- Around line 110-160: Add coverage for the base/appended boundary in
`a_cycle_verdict_is_scoped_to_ancestors_that_truncate_identically`: change
`keyed_item` to accept separate base and appended ids, then add
`a_cycle_verdict_is_scoped_to_the_base_appended_boundary` using a non-empty
base. Assert the matching split reuses the verdict while moving the consulted
base id into the appended half returns no hit.
In `@pnpm/crates/resolving-deps-resolver/src/resolve_peers/walker.rs`:
- Around line 277-302: Update build_cycle_key so the consulted lookup returns
the existing Arc<str> via get_key_value, then push an Arc::clone of that key
instead of constructing Arc::from(id) for both base_ids and appended_ids.
Preserve the current filtering order and base_len accounting; leave the
consulted_sets interning block unchanged unless a one-clone entry-API change can
be made without cloning frame on cache hits.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Pro Plus
Run ID: bb0eadc7-b8b0-4dc3-94f1-0a8c74bd3362
📒 Files selected for processing (6)
.changeset/cycle-verdict-cache.mdpnpm/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/discovery.rspnpm/crates/resolving-deps-resolver/src/resolve_peers/walker.rspnpm/crates/resolving-deps-resolver/src/resolved_tree.rs
Code Review by Qodo
1. Realized cycles skip caching
|
PR Code Suggestions ✨Warning
No code suggestions found for the PR. |
- The fast-path comment claimed no ancestor chain exists there; it does — `parent_ids` is the same pre-realization chain `resolve_node` captures. Skipping keyed entries is a deliberate scope choice that only loses hits, and the comment now says so. - `build_cycle_key` allocated a fresh `Arc<str>` per consulted chain entry when the bit index already owns one — `get_key_value` shares it — and the set interner cloned the frame twice on a miss. Keying the interner as a `HashSet<Arc<ConsultedPkgs>>` (lookup through `Borrow<ConsultedPkgs>`) gets a miss down to one clone and a hit to none. - `keyed_item` hardcoded `base_len = 0`, leaving mixed base/appended keys — which `build_cycle_key` produces whenever a consulted id sits in the dependency walk's base half — untested. The helper now takes the split, and `a_mixed_base_and_appended_key_pins_the_boundary` covers both directions of the boundary. - Dropped the test doc comment that restated the assertions. Output verified unchanged: same lockfile byte for byte, peak RSS still ~1.4 GB on the #13681 workload.
|
All three review points addressed in 8990508: Fast-path comment corrected. You are right that
Both allocation nits fixed. The chain now shares the bit index's Verified unchanged behaviour: 329 tests pass, and the #13681 workload produces a byte-identical lockfile at the same ~1.4 GB peak. |
|
Code review by qodo was updated up to the latest commit 8990508 |
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.5385175738399997,
"stddev": 0.1769960046967517,
"median": 2.47046723554,
"user": 1.5704387199999998,
"system": 1.3017284999999996,
"min": 2.35457605104,
"max": 2.78132338204,
"times": [
2.36846702004,
2.41358473304,
2.74665724304,
2.66373005204,
2.37717243204,
2.52734973804,
2.35457605104,
2.78132338204,
2.40786772704,
2.74444736004
]
},
{
"command": "pacquet@main",
"mean": 2.4819060194399998,
"stddev": 0.15116202855896227,
"median": 2.4301380980400005,
"user": 1.55086832,
"system": 1.3431959,
"min": 2.35638793604,
"max": 2.77059522904,
"times": [
2.36871283204,
2.38286028404,
2.4445692930400003,
2.36014399604,
2.73158718704,
2.77059522904,
2.35638793604,
2.51272708504,
2.47576944904,
2.4157069030400002
]
},
{
"command": "pnpr@HEAD",
"mean": 1.4793338228400001,
"stddev": 0.12293143540640086,
"median": 1.43325185554,
"user": 1.04963062,
"system": 1.1964244999999998,
"min": 1.3571634870400002,
"max": 1.7201813080400001,
"times": [
1.42248991704,
1.3627466510400001,
1.60173474204,
1.3571634870400002,
1.4034894430400002,
1.51261782504,
1.4440137940400002,
1.3769556600400001,
1.7201813080400001,
1.5919454010400003
]
},
{
"command": "pnpr@main",
"mean": 1.5056082670400002,
"stddev": 0.17237876472689678,
"median": 1.4156702980400002,
"user": 1.0823826200000002,
"system": 1.1653497999999998,
"min": 1.35841462904,
"max": 1.80634556604,
"times": [
1.5647667150400002,
1.80634556604,
1.5440306990400001,
1.39080355804,
1.3911721000400001,
1.3670140530400001,
1.39670036204,
1.4346402340400002,
1.8021947540400003,
1.35841462904
]
}
]
}Scenario: Isolated linker: fresh restore, hot cache + hot store
BENCHMARK_REPORT.json{
"results": [
{
"command": "pacquet@HEAD",
"mean": 0.26309396726,
"stddev": 0.005846213168925492,
"median": 0.26256758666,
"user": 0.22249433999999998,
"system": 0.5261377,
"min": 0.25558967716000003,
"max": 0.27410553916,
"times": [
0.25558967716000003,
0.26911584016,
0.26430132016,
0.26070282616,
0.26647139916,
0.25810180816,
0.27410553916,
0.25666543816000004,
0.26083385316,
0.26505197116
]
},
{
"command": "pacquet@main",
"mean": 0.25320863346,
"stddev": 0.0071955499845934015,
"median": 0.25305270766000004,
"user": 0.21810944000000002,
"system": 0.5167166,
"min": 0.24300370916000003,
"max": 0.26513795316000005,
"times": [
0.25677961216,
0.25546170516000005,
0.25802427116000004,
0.26091777116000003,
0.24300370916000003,
0.25064371016000003,
0.24475019116000002,
0.24860989716000004,
0.26513795316000005,
0.24875751416000003
]
},
{
"command": "pnpr@HEAD",
"mean": 0.26962309926000005,
"stddev": 0.009597963700450235,
"median": 0.27104636816000005,
"user": 0.22113724,
"system": 0.5306225,
"min": 0.24918368416000003,
"max": 0.28106781516,
"times": [
0.28056445916,
0.28106781516,
0.24918368416000003,
0.26507550616000003,
0.26509488216000004,
0.27618485716,
0.27208879716,
0.27000393916000004,
0.27429556616,
0.26267148616
]
},
{
"command": "pnpr@main",
"mean": 0.27348659176000006,
"stddev": 0.01159092130781376,
"median": 0.27018258066,
"user": 0.21556084000000003,
"system": 0.5526660999999999,
"min": 0.25939055016,
"max": 0.30202967616000004,
"times": [
0.25939055016,
0.26953130116,
0.26608730716,
0.30202967616000004,
0.27234091216,
0.28281448916,
0.27009848716,
0.26968917816000004,
0.27026667416000005,
0.27261734216000005
]
}
]
}Scenario: Isolated linker: fresh install, cold cache + cold store
BENCHMARK_REPORT.json{
"results": [
{
"command": "pacquet@HEAD",
"mean": 2.7366620720600006,
"stddev": 0.025116547474073006,
"median": 2.7362657871600002,
"user": 1.5529059799999998,
"system": 1.3664157399999994,
"min": 2.7016087191600002,
"max": 2.7829187231600003,
"times": [
2.7465495321600004,
2.7089749861600003,
2.74404507416,
2.7016087191600002,
2.7350298491600005,
2.7183814061600002,
2.7668476541600002,
2.7829187231600003,
2.7247630511600005,
2.73750172516
]
},
{
"command": "pacquet@main",
"mean": 2.72007410356,
"stddev": 0.018050067192249067,
"median": 2.7244677411600002,
"user": 1.5564244799999998,
"system": 1.3347261399999997,
"min": 2.68969522616,
"max": 2.7476005771600005,
"times": [
2.71678737016,
2.7223773271600002,
2.7346661551600002,
2.7267730691600005,
2.72655815516,
2.73230399516,
2.68969522616,
2.7476005771600005,
2.6938644131600005,
2.71011474716
]
},
{
"command": "pnpr@HEAD",
"mean": 1.6302741390599997,
"stddev": 0.16910685384950846,
"median": 1.62291859016,
"user": 1.0905812799999999,
"system": 1.1243600399999998,
"min": 1.43560668316,
"max": 1.85864401116,
"times": [
1.43629800316,
1.8371097701599999,
1.67310521216,
1.43560668316,
1.73088534816,
1.7920887971600001,
1.57273196816,
1.5160495651600001,
1.45022203216,
1.85864401116
]
},
{
"command": "pnpr@main",
"mean": 1.5780056247600003,
"stddev": 0.13470574101842436,
"median": 1.5675885536599998,
"user": 1.03838808,
"system": 1.1844312399999997,
"min": 1.42586737116,
"max": 1.8567461951600002,
"times": [
1.8567461951600002,
1.46236994316,
1.64523389416,
1.5111480501599999,
1.45209845616,
1.62402905716,
1.48584311516,
1.67744950916,
1.42586737116,
1.6392706561600001
]
}
]
}Scenario: Isolated linker: fresh install, hot cache + hot store
BENCHMARK_REPORT.json{
"results": [
{
"command": "pacquet@HEAD",
"mean": 0.42565864248,
"stddev": 0.01147991390722532,
"median": 0.42383690268,
"user": 0.5466106,
"system": 0.6659459,
"min": 0.41236612618,
"max": 0.44585502418,
"times": [
0.41855208318000003,
0.42285063418,
0.44585502418,
0.41819657518000003,
0.42598867218,
0.42817179518000004,
0.42482317118,
0.44479903818000005,
0.41236612618,
0.41498330518000004
]
},
{
"command": "pacquet@main",
"mean": 0.42644536068,
"stddev": 0.013580286094915206,
"median": 0.42205570868000003,
"user": 0.5382541,
"system": 0.680856,
"min": 0.40944832218000005,
"max": 0.45461248418000005,
"times": [
0.42119455918000004,
0.41403834818,
0.41631441718,
0.42178251518000004,
0.43995767818000003,
0.40944832218000005,
0.43152623018,
0.42232890218,
0.43325015018,
0.45461248418000005
]
},
{
"command": "pnpr@HEAD",
"mean": 0.30719950358000003,
"stddev": 0.005306211920721491,
"median": 0.30684354468,
"user": 0.2070998,
"system": 0.5399684,
"min": 0.29725120918000003,
"max": 0.31398241818,
"times": [
0.29725120918000003,
0.30576615418,
0.31294177218,
0.30792093518,
0.31098706718,
0.30413997718,
0.31398241818,
0.30484905018,
0.31174820918,
0.30240824318000004
]
},
{
"command": "pnpr@main",
"mean": 0.31002024188,
"stddev": 0.006542539392692355,
"median": 0.30859812768000006,
"user": 0.2139819,
"system": 0.5387340999999999,
"min": 0.30141486518,
"max": 0.31960986618000004,
"times": [
0.30141486518,
0.30739506518000004,
0.30980119018,
0.31195481818000004,
0.30334390218,
0.31731355918000004,
0.31830207718000003,
0.30455067018000004,
0.31960986618000004,
0.30651640518
]
}
]
}Scenario: Isolated linker: fresh install, cold cache + hot store
BENCHMARK_REPORT.json{
"results": [
{
"command": "pacquet@HEAD",
"mean": 1.87838966858,
"stddev": 0.006473661737919479,
"median": 1.87813605688,
"user": 0.7276341599999998,
"system": 0.80106262,
"min": 1.8672732488800001,
"max": 1.8883366598800002,
"times": [
1.87980530488,
1.88054324188,
1.8672732488800001,
1.8847776508800003,
1.87646680888,
1.8742577268800003,
1.8754182188800002,
1.8883366598800002,
1.87228072088,
1.88473710388
]
},
{
"command": "pacquet@main",
"mean": 1.87282051938,
"stddev": 0.018836301455814542,
"median": 1.8755846358800001,
"user": 0.7201130599999999,
"system": 0.8172625200000001,
"min": 1.8431961118800002,
"max": 1.8966675888800002,
"times": [
1.85132248688,
1.89236904988,
1.8829583208800003,
1.8735253898800002,
1.86113793588,
1.85690694388,
1.8966675888800002,
1.87764388188,
1.8431961118800002,
1.89247748388
]
},
{
"command": "pnpr@HEAD",
"mean": 0.30207450948000003,
"stddev": 0.007543221277501779,
"median": 0.30137531888,
"user": 0.20842685999999996,
"system": 0.52696842,
"min": 0.29312401988000003,
"max": 0.31148032488,
"times": [
0.29597390688,
0.30909986988,
0.31148032488,
0.30804886388,
0.31113752988000004,
0.30478596188,
0.29312401988000003,
0.29796467588000003,
0.29354327588,
0.29558666588
]
},
{
"command": "pnpr@main",
"mean": 0.30644476758000005,
"stddev": 0.00542185326151491,
"median": 0.30633932188,
"user": 0.19240696,
"system": 0.5578378199999998,
"min": 0.29788493488,
"max": 0.31912003188000004,
"times": [
0.30273020288,
0.30768001688,
0.30613900988000003,
0.29788493488,
0.30572040388,
0.30789220588,
0.31912003188000004,
0.30310327588,
0.30763795988000003,
0.30653963388
]
}
]
}Scenario: Isolated linker: fresh resolve, hot cache, offline
BENCHMARK_REPORT.json{
"results": [
{
"command": "pacquet@HEAD",
"mean": 0.2128778216830769,
"stddev": 0.018725215547827165,
"median": 0.21422184876,
"user": 0.1505569892307692,
"system": 0.061038426153846144,
"min": 0.18840970876000002,
"max": 0.24596981476000002,
"times": [
0.21422184876,
0.24596981476000002,
0.24270900576,
0.18840970876000002,
0.19456916876000002,
0.19001052976000002,
0.19353741976000002,
0.22526131876000002,
0.21536056876,
0.21724821676,
0.21220055976000002,
0.20374508576,
0.22416843576
]
},
{
"command": "pacquet@main",
"mean": 0.21983257726,
"stddev": 0.011247414638817026,
"median": 0.22164036826,
"user": 0.16096021999999996,
"system": 0.05832850857142856,
"min": 0.19898815476,
"max": 0.23733527476000002,
"times": [
0.19898815476,
0.21950466876000002,
0.23123163176,
0.22379021476000002,
0.22377606776,
0.23282086876000002,
0.22795087476,
0.21224160676,
0.21442305676,
0.22427171976000002,
0.20237171376000002,
0.23733527476000002,
0.21888993276000002,
0.21006029576000002
]
},
{
"command": "pnpr@HEAD",
"mean": 0.08773053539636363,
"stddev": 0.001818260637874695,
"median": 0.08749455176000001,
"user": 0.02163858363636363,
"system": 0.009120484242424245,
"min": 0.08467020376,
"max": 0.09195740076,
"times": [
0.08505840276,
0.08698994376000001,
0.08826463876,
0.08688079876,
0.08907160576,
0.08500050376,
0.08749455176000001,
0.08575492276,
0.08900793676,
0.08873824976,
0.08897259976,
0.08753261376,
0.08969689076000001,
0.08594139276,
0.08804142976,
0.08589043776000001,
0.08928181176000001,
0.09099208776,
0.08710027076,
0.08500936076,
0.08875021276,
0.08718159376000001,
0.08645730276000001,
0.08710242476,
0.08682524476,
0.08851753476,
0.08467020376,
0.08715183776,
0.09065628576000001,
0.09024071376000001,
0.08809699476,
0.09195740076,
0.08677946776
]
},
{
"command": "pnpr@main",
"mean": 0.08755373260848487,
"stddev": 0.0012074230959532978,
"median": 0.08732360076000001,
"user": 0.02043894727272727,
"system": 0.01033158,
"min": 0.08585773576,
"max": 0.09133233576000001,
"times": [
0.08653018876,
0.08728402676000001,
0.08647212076,
0.08719121176,
0.08744837576,
0.08585773576,
0.08806016576,
0.08882173676,
0.09133233576000001,
0.08682911176000001,
0.08816307876,
0.09060021976,
0.08728937676000001,
0.08748974376,
0.08726304676,
0.08786985876,
0.08723454276,
0.09009543176000001,
0.08709254576,
0.08623490476000001,
0.08637375476,
0.08776096376,
0.08694825576000001,
0.08755589776,
0.08630348376000001,
0.08827987776,
0.08735350776,
0.08619699276000001,
0.08746111976,
0.08711487776,
0.08743106276,
0.08732360076000001,
0.08801002176
]
}
]
}Scenario: Isolated linker: peer-heavy resolve, hot cache, offline
BENCHMARK_REPORT.json{
"results": [
{
"command": "pacquet@HEAD",
"mean": 0.5458601094622222,
"stddev": 0.1025732557702177,
"median": 0.5168127912400001,
"user": 0.5293109733333332,
"system": 0.10435294222222222,
"min": 0.44064430924000003,
"max": 0.7725894902400001,
"times": [
0.48512500924,
0.7725894902400001,
0.5550679892400001,
0.46087626924,
0.5168127912400001,
0.5774788852400001,
0.6183193222400001,
0.48582691924000004,
0.44064430924000003
]
},
{
"command": "pacquet@main",
"mean": 0.5332349315733335,
"stddev": 0.06777027790569688,
"median": 0.5625376302400001,
"user": 0.5005445288888888,
"system": 0.11032894222222221,
"min": 0.41223593224000005,
"max": 0.6143277482400001,
"times": [
0.6143277482400001,
0.41223593224000005,
0.5775317432400001,
0.45421366624000004,
0.5047129092400001,
0.5939402862400001,
0.5625376302400001,
0.50918510524,
0.57042936324
]
},
{
"command": "pnpm@HEAD",
"mean": 3.0315460302399995,
"stddev": 0.08524559235095318,
"median": 3.01972519124,
"user": 4.64174064,
"system": 0.2827186088888889,
"min": 2.92506723524,
"max": 3.21593439124,
"times": [
3.21593439124,
3.08809155724,
3.06503402724,
3.02859727724,
2.92506723524,
2.99081776424,
2.96210108524,
2.98854574324,
3.01972519124
]
}
]
}Scenario: Isolated linker: fresh restore, cold cache + cold store + cold pnpr
BENCHMARK_REPORT.json{
"results": [
{
"command": "pacquet@HEAD",
"mean": 4.5235329567800004,
"stddev": 0.15006935921902773,
"median": 4.45719434708,
"user": 1.7411064,
"system": 1.40301744,
"min": 4.4190135140799995,
"max": 4.89589780208,
"times": [
4.45189982808,
4.89589780208,
4.62933689408,
4.46248886608,
4.42794286808,
4.59923518708,
4.48466525108,
4.43854162208,
4.4190135140799995,
4.42630773508
]
},
{
"command": "pacquet@main",
"mean": 4.542940380279999,
"stddev": 0.13433749317111787,
"median": 4.47368437858,
"user": 1.7896817999999999,
"system": 1.3629667399999998,
"min": 4.43546577808,
"max": 4.83612366808,
"times": [
4.47239983408,
4.59534857108,
4.60590398208,
4.43546577808,
4.44148694708,
4.44112173008,
4.44685233208,
4.47496892308,
4.83612366808,
4.67973203708
]
},
{
"command": "pnpr@HEAD",
"mean": 3.61365417218,
"stddev": 0.14718813006176856,
"median": 3.6081675560799997,
"user": 1.2119615,
"system": 1.20977014,
"min": 3.44233162008,
"max": 3.84653325908,
"times": [
3.81521250508,
3.6118216720799996,
3.7235100120799998,
3.4629151710799997,
3.44233162008,
3.4840554290799997,
3.84653325908,
3.6615987680799997,
3.60451344008,
3.48404984508
]
},
{
"command": "pnpr@main",
"mean": 3.5497577247799996,
"stddev": 0.08339040850955814,
"median": 3.5338581085799996,
"user": 1.248741,
"system": 1.3040229399999999,
"min": 3.44978694208,
"max": 3.6819412260799997,
"times": [
3.48060193408,
3.50784035408,
3.4740589360799996,
3.63719479808,
3.55987586308,
3.64494731008,
3.58219826308,
3.44978694208,
3.6819412260799997,
3.4791316210799996
]
}
]
} |
|
| Project | pnpm's project |
| Branch | pr/13859 |
| 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,435.61 ms |
| isolated-linker.fresh-install.cold-cache.hot-store | 📈 view plot | 293.12 ms |
| isolated-linker.fresh-install.hot-cache.hot-store | 📈 view plot | 297.25 ms |
| isolated-linker.fresh-resolve.hot-cache.offline | 📈 view plot | 84.67 ms |
| isolated-linker.fresh-restore.cold-cache.cold-store | 📈 view plot | 1,357.16 ms |
| isolated-linker.fresh-restore.cold-cache.cold-store.cold-pnpr | 📈 view plot | 3,442.33 ms |
| isolated-linker.fresh-restore.hot-cache.hot-store | 📈 view plot | 249.18 ms |
… bound The keyed matching had thorough unit coverage, but nothing guarded the side where the dangerous bugs live: what the walk *collects*. During development, a frame pushed after the provider preview made every key miss the walk's own peer-provider consultations — and the entire existing suite passed while real installs produced wrong lockfiles. These two tests close that class. - `one_context_keeps_both_truncations_of_a_cycle_package_apart` drives `resolve_peers` over a ring where the same package is cycle-truncated two different ways in one install: re-entered through the full lap it loses its `w`-consuming edge, reached under a direct entry on a later ring member it keeps it. A key that under-collects merges the two and one variant disappears from the graph — #5108 as a fixture. Verified failing against a key that skips the chain comparison. - `cycle_re_walks_collapse_instead_of_multiplying_occurrences` pins the perf property itself, deterministically: per-entry `w` versions block every untruncated verdict from transferring across entries, `home` edges make each lap re-enter the cycle many times, and fanout under the transferable members gives each avoided re-walk children worth counting. The cached walk realizes ~2,230 occurrence nodes; with cycle-verdict reuse disabled it realizes ~4,360. The bound sits at 3,000, between the two. No wall clocks, no platform noise. Building the fixture also reproduced a resolver bug that predates this branch: a keyless verdict recorded under a truncating chain plainly matches a context where the subtree is intact, and a `w` variant silently disappears. The fixture only works around it (consumers on the odd ring members keep every keyless item context-specific); the bug is tracked separately. Also rewords three comments that described the change relative to the previous behavior instead of stating the current contract.
Dismissed because a newer commit was pushed; Greptile will re-review the current head.
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 f5020a4 |
PR Code Suggestions ✨Warning
No code suggestions found for the PR. |
Break dependency cycles canonically during peer resolution: each strongly connected component's members sort by package id and every intra-SCC edge whose target is not canonically later is cut, the same cut at every occurrence. The SCC becomes a DAG: no walk path revisits a package, every peer verdict is a plain (package, context) function, and the lockfile is identical however the walk is ordered (Closes #13846, Closes #13865). A cut back-edge is still a real dependency edge: it is realized against a shared record-only occurrence of its target, walked once at importer context by the drivers, with peer-issue emission suppressed (every real position reports its own state). Back-edge targets nothing reaches forward are queued from the realized-children skip so they stay in the graph. The shared occurrences persist across peer-hoist discovery rounds. The #13859 cycle-truncation verdict keys had nothing left to scope and are deleted, as is the interim hoisted-region rule this branch previously carried. Single-importer bit fixture: 0.66 s / 0.60 GB / 9.6k walks vs main's 1.61 s / 0.82 GB / ~27k; 5-importer: 0.73 s / 0.61 GB vs 2.57 s / 0.92 GB; lockfiles 23-37% smaller and byte-identical across runs and orderings.
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
transitivePeerDependenciesdepending on traversal order (#5108). On a peer-cyclic graph this rule makes the peers cache inert. Resolving bit's env packages:The insight, measured before designed
The truncation is not arbitrary:
realize_children_withdrops exactly the edgesforms_cyclefinds 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:The mechanism
ConsultedPkgsframe — a bitset over interned package ids. Realization marks the package whose children are realized plus every child edge target (precisely theforms_cyclearguments); 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.CycleTruncationKey: the consulted set plus the occurrence's ancestor ids restricted to it (base entries first —forms_cycletreats the halves differently, so the boundary is part of the key).find_hithands 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 not expected updates in lockfile #5108 shape — re-walk exactly as before.Results
Same replayed install as the previous PRs (5 importers, 3,807 merged packages), alternating A/B:
main3047 → 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.
wanted, preserves it byte for byte; this branch preservesmain's lockfile byte for byte. Lockfile churn on repeat installs is the not expected updates in lockfile #5108 regression, and it cannot happen here.mainin 13 snapshot entries (52 diff lines of ~86k), all in the@teambit/component → command-bar/pubsub/uicluster — the exact entries that already flip between identical stock runs (Lockfile is not reproducible: four identical installs produce four different lockfiles #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 currentmainis a hard requirement even inside the known-nondeterministic cluster, this needs a maintainer call.cargo clippy --all-targets,cargo fmt, andcargo dylintclean across the workspace.What I'd take a steer on
The one hole I know of and did not close: keyless (non-cycle) items whose subtrees contain cycle-resolved descendants re-entering ancestors above them embed chain-dependence today, on
main, and are reused with ctx checks only. That is pre-existing behavior — this PR neither introduces nor widens it — and I suspect it is the root of #13846. Happy to attack it as a follow-up with the same consulted-set machinery (tagging any item whose frame intersects its chain).Refs #13681
Need help on this PR? Tag
@codesmith-botwith what you need. Autofix is disabled.Summary by CodeRabbit