Skip to content

refactor(resolving-deps-resolver): split resolve_node into its sequential phases - #13564

Merged
zkochan merged 1 commit into
mainfrom
fix-13553
Aug 1, 2026
Merged

zkochan merged 1 commit into
mainfrom
fix-13553

Conversation

@zkochan

@zkochan zkochan commented Aug 1, 2026 •

Copy link
Copy Markdown
Member

Summary

Walker::resolve_node was 549 lines — by a wide margin the largest function in
resolving-deps-resolver (next is resolve_node_seed at 321; the crate median is
13). #13551 split the surrounding file into modules but deliberately left
function bodies untouched; this is the remaining piece.

Lifts the three phases the issue identified as having clean seams:

  1. Graph-entry / NodeRecord capture → Walker::record_walked_node in
    resolve_peers/finalize.rs, next to the post-walk passes that consume those
    records, taking a borrowed WalkedNode context.
  2. Building the descendants' ParentRefs (locked-peer scoping → provider
    children → locked pins) → Walker::build_child_parent_refs, returning the
    shared map, the node's own contribution, and whether anything changed.
  3. Own-peer resolution (resolve, fold with the children's, render the
    depPath) → Walker::resolve_node_peers.

The early-return short-circuits stay inline, as the issue asked: as
Option<NodeOutput>-returning helpers they make the control flow harder to
follow, not easier. resolve_node is now 378 lines — linear short-circuits plus
the child walk. (The issue's ~290 estimate counted the removed bodies but not the
call sites the extraction adds back.)

Also folds in the adjacent micro-cleanup the issue called out:
Walker::deferred_child_resolution did two pure_pkgs hash lookups where one
if let chain does.

Verification:

  • just ready green — 7541 tests passed, 0 failures.
  • Peer-heavy benchmark (isolated-linker.peer-heavy-resolve.hot-cache.offline,
    --runs=9, HEAD vs. its parent), two passes: 1.04× ± 0.28 and 1.02× ± 0.20 in
    favour of the parent — well inside the fixture's known ~15% run-to-run spread
    (test(pacquet): stabilize the peer-heavy benchmark and stop its gate dropping data #13559), i.e. no measurable change. Both passes also cleared the
    harness's peer-heavy lockfile parity check.

Closes #13553.

Squash Commit Body

Walker::resolve_node was 549 lines — by a wide margin the largest function in
the crate (next is resolve_node_seed at 321, the median is 13). Nesting was
never the problem: real block depth peaks at 5, in the two-pass child loop that
is legitimately nested. Length was, because eleven sequential phases shared one
large local context.

Lift the three phases that have clean seams into named helpers:

- The graph-entry / NodeRecord capture moves to finalize.rs as
  Walker::record_walked_node, next to the post-walk passes that consume those
  records, taking a borrowed WalkedNode context.
- Building the ParentRefs map descendants see — locked-peer scoping, provider
  children, locked pins — becomes Walker::build_child_parent_refs, returning
  the shared map, the node's own contribution, and whether anything changed.
- The node's own peer resolution, its fold with the children's, and the depPath
  it renders to become Walker::resolve_node_peers.

The early-return short-circuits (context-free depPath, cycle re-entry, fast
cache hit, peersCache hit) stay inline: as Option<NodeOutput>-returning helpers
they would make the control flow harder to follow, not easier. resolve_node is
now 378 lines of linear short-circuits plus the child walk.

No allocation, cloning, or traversal change. The extracted phases take borrowed
context structs, following the CacheHitContext / DeferredChildContext
precedent, so no borrow conflict is resolved with a clone. The one behavioral
identity worth naming: resolve_node_peers folds the node's own resolved peers
into auto_install_resolved_peers after its loop instead of during it — the two
maps agree because resolve_one_peer only ever inserts under the peer name it
was called for.

Also fold in the adjacent micro-cleanup the issue called out:
Walker::deferred_child_resolution did two pure_pkgs hash lookups where one
if-let chain does.

Closes pnpm/pnpm#13553.

Checklist

  • I checked the referenced issue and verified that none of the PRs
    already linked to it solves it.
  • The change is implemented in both the TypeScript CLI and the Rust
    pnpm/ port, or the description notes what still needs porting.
  • Added a changeset (pnpm changeset) if this PR changes any published
    package. Keep it short and written for pnpm users — it becomes a release note.
  • Added or updated tests.
  • Updated the documentation if needed.

Written by an agent (Claude Code, claude-opus-5[1m]).


View with [code]smith Autofix with [code]smith
Need help on this PR? Tag @codesmith-bot with what you need. Autofix is disabled.

Summary by CodeRabbit

  • Improvements
    • Improved dependency resolution for packages with peer dependencies.
    • Enhanced handling of dependency graph relationships and transitive peer dependencies.
    • Streamlined cached resolution paths to improve consistency and efficiency.
    • Strengthened graph rebuilding and node tracking during dependency resolution.

…tial phases

Walker::resolve_node was 549 lines — by a wide margin the largest function in
the crate (next is resolve_node_seed at 321, the median is 13). Nesting was
never the problem: real block depth peaks at 5, in the two-pass child loop that
is legitimately nested. Length was, because eleven sequential phases shared one
large local context.

Lift the three phases that have clean seams into named helpers:

- The graph-entry / NodeRecord capture moves to finalize.rs as
  Walker::record_walked_node, next to the post-walk passes that consume those
  records, taking a borrowed WalkedNode context.
- Building the ParentRefs map descendants see — locked-peer scoping, provider
  children, locked pins — becomes Walker::build_child_parent_refs, returning
  the shared map, the node's own contribution, and whether anything changed.
- The node's own peer resolution, its fold with the children's, and the depPath
  it renders to become Walker::resolve_node_peers.

The early-return short-circuits (context-free depPath, cycle re-entry, fast
cache hit, peersCache hit) stay inline: as Option<NodeOutput>-returning helpers
they would make the control flow harder to follow, not easier. resolve_node is
now 378 lines of linear short-circuits plus the child walk.

No allocation, cloning, or traversal change. The extracted phases take borrowed
context structs, following the CacheHitContext / DeferredChildContext
precedent, so no borrow conflict is resolved with a clone. The one behavioral
identity worth naming: resolve_node_peers folds the node's own resolved peers
into auto_install_resolved_peers after its loop instead of during it — the two
maps agree because resolve_one_peer only ever inserts under the peer name it
was called for.

Also fold in the adjacent micro-cleanup the issue called out:
Walker::deferred_child_resolution did two pure_pkgs hash lookups where one
if-let chain does.

Closes #13553.
Copilot AI review requested due to automatic review settings August 1, 2026 15:38
@coderabbitai

coderabbitai Bot commented Aug 1, 2026 •

Copy link
Copy Markdown
Contributor

Review Change Stack

📝 Walkthrough

Walkthrough

The PR splits peer-node resolution into parent-reference, peer-resolution, and walked-node recording phases. It adds internal state structures for phase boundaries and simplifies the pure-package cache lookup.

Changes

Peer resolution refactor

Layer / File(s) Summary
Extract peer-resolution phases
pnpm/crates/resolving-deps-resolver/src/resolve_peers/cache.rs, pnpm/crates/resolving-deps-resolver/src/resolve_peers/walker.rs
resolve_node now delegates parent-reference construction and peer resolution to dedicated helpers. Intermediate state uses internal context structures.
Record walked nodes
pnpm/crates/resolving-deps-resolver/src/resolve_peers/finalize.rs, pnpm/crates/resolving-deps-resolver/src/resolve_peers/walker.rs
WalkedNode and record_walked_node centralize graph-edge construction, peer-edge tracking, node-record storage, and minimum-depth merging.

Estimated code review effort: 3 (Moderate) | ~25 minutes

Assessment against linked issues

Objective Addressed Explanation
Split resolve_node into sequential phases and move graph-entry recording into finalization [#13553] ✅
Use a single pure_pkgs lookup in deferred_child_resolution [#13553] ✅

Possibly related issues

  • #13548 — The changes implement the related resolve_peers module and walker/finalization split.
  • #13555 — The changes modify the Walker final graph-construction path covered by this issue.

Possibly related PRs

  • pnpm/pnpm#13551 — This PR continues changes in the same cache.rs, finalize.rs, and walker.rs modules.
  • pnpm/pnpm#13560 — This PR is connected to the walked-node final-graph recording logic.
  • pnpm/pnpm#13545 — Both PRs modify Rust peer-resolution walker and cache state handling.

Suggested labels: product: pacquet

Suggested reviewers: copilot

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fix-13553

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@qodo-code-review

Copy link
Copy Markdown

PR Summary by Qodo

Split Walker::resolve_node into explicit phases (parent refs, peers, graph capture)

✨ Enhancement 🕐 40+ Minutes

Grey Divider

AI Description

• Extract resolve_node’s sequential phases into named helpers to reduce cognitive load.
• Move per-node graph/record capture into finalize.rs next to post-walk rebuild passes.
• Simplify deferred_child_resolution pure-package detection to avoid duplicate map lookups.
Diagram

graph TD
  A["Walker::resolve_node"] --> B["build_child_parent_refs"] --> C["resolve_node_peers"] --> D["record_walked_node"] --> E["Graph + NodeRecords"]
  A -.-> F["deferred_child_resolution cache"]
Loading
High-Level Assessment

The following are alternative approaches to this PR:

1. Single ResolveNodeContext state object
  • ➕ Further reduces parameter plumbing between helpers
  • ➕ Makes phase boundaries explicit via one shared struct
  • ➖ Risk of recreating the original “giant local context” problem in a new form
  • ➖ Can make ownership/borrowing in Rust more complex than passing targeted references
2. Keep graph capture in walker.rs for locality
  • ➕ All per-node work remains in one file for linear reading
  • ➕ Avoids introducing a cross-module WalkedNode data type
  • ➖ Separates record generation from the finalize passes that consume it
  • ➖ Encourages future drift between capture and post-walk rebuild invariants

Recommendation: Current approach is a strong tradeoff: each extracted helper has a clean seam (descendant ParentRefs, peer resolution/depPath rendering, and graph/record capture), and moving capture to finalize.rs improves cohesion with the post-walk passes. The added context structs (WalkedNode, NodePeersContext) already capture most benefits of a full state object without re-centralizing everything.

Files changed (3) +383 / -231

Refactor (3) +383 / -231
cache.rsAvoid double lookup when classifying pure deferred child resolutions +3/-5

Avoid double lookup when classifying pure deferred child resolutions

• Refactors 'deferred_child_resolution' to use a single 'if let' chain for 'pure_pkgs' lookup and peer-deps emptiness check. This keeps behavior the same while reducing hash-map lookups and branching.

pnpm/crates/resolving-deps-resolver/src/resolve_peers/cache.rs

finalize.rsAdd WalkedNode + record_walked_node for per-node graph/record capture +150/-6

Add WalkedNode + record_walked_node for per-node graph/record capture

• Expands module scope to include the per-node graph-entry capture performed during the walk. Introduces 'WalkedNode' as a borrowed context bundle and implements 'Walker::record_walked_node' to populate 'graph' and 'node_records' consistently for later finalize passes.

pnpm/crates/resolving-deps-resolver/src/resolve_peers/finalize.rs

walker.rsSplit resolve_node into build_child_parent_refs and resolve_node_peers phases +230/-220

Split resolve_node into build_child_parent_refs and resolve_node_peers phases

• Extracts descendant ParentRefs construction into 'build_child_parent_refs' and peer-resolution/depPath rendering into 'resolve_node_peers'. Replaces inline graph/record construction with a call to 'record_walked_node', and adds small internal structs to clarify phase inputs/outputs.

pnpm/crates/resolving-deps-resolver/src/resolve_peers/walker.rs

@greptile-apps

greptile-apps Bot commented Aug 1, 2026

Copy link
Copy Markdown
Contributor

Confidence Score: 5/5

The PR appears safe to merge, with the extracted phases preserving the original peer-resolution and graph-recording behavior.

The moved logic receives the same values, performs mutations in the same order, and produces equivalent parent-reference maps, peer maps, depPaths, cache state, and graph records; no actionable regression was identified.

Reviews (1): Last reviewed commit: "refactor(resolving-deps-resolver): split..." | Re-trigger Greptile

@qodo-code-review

Copy link
Copy Markdown

Code Review by Qodo

🐞 Bugs (0) 📘 Rule violations (0) 📎 Requirement gaps (0)

Grey Divider

Great, no issues found!

Qodo reviewed your code and found no material issues that require review

Grey Divider

To customize comments, go to the Qodo configuration screen, or learn more in the docs.

Qodo Logo

@qodo-code-review

Copy link
Copy Markdown

PR Code Suggestions ✨

Warning

/improve is deprecated. Use /agentic_review instead (removal date not yet scheduled).

No code suggestions found for the PR.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🧹 Nitpick comments (1)
pnpm/crates/resolving-deps-resolver/src/resolve_peers/finalize.rs (1)

119-165: 🚀 Performance & Scalability | 🔵 Trivial | 💤 Low value

Consider computing previously_resolved_children once.

Lines 121 and 161 call previously_resolved_children with the same three arguments. The method rebuilds a BTreeMap and clones every alias and NodeId on each call. The extraction now places both calls in one function, so a single binding removes one full rebuild. record_edges then needs one map clone instead, which is cheaper than the repeated traversal. The resolver is a hot path, so this is worth doing while the code is being moved.

♻️ Proposed consolidation
         let mut graph_children = BTreeMap::new();
-        for (alias, child_node_id) in
-            self.previously_resolved_children(parent_node_ids, parent_pkg_ids_chain, &pkg.id)
-        {
+        let previously_resolved =
+            self.previously_resolved_children(parent_node_ids, parent_pkg_ids_chain, &pkg.id);
+        for (alias, child_node_id) in previously_resolved.clone() {
             self.add_graph_child_or_pending(&mut graph_children, dep_path, alias, child_node_id);
         }
-        let mut record_edges =
-            self.previously_resolved_children(parent_node_ids, parent_pkg_ids_chain, &pkg.id);
+        let mut record_edges = previously_resolved;
         record_edges.extend(children.clone());
🤖 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/finalize.rs` around
lines 119 - 165, Compute previously_resolved_children once before the
graph_children construction and store the resulting map in a local binding.
Reuse that binding when populating graph_children, then clone the map when
initializing record_edges before extending it with children and
own_resolved_peers; preserve the existing edge contents and ordering.
🤖 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/finalize.rs`:
- Around line 119-165: Compute previously_resolved_children once before the
graph_children construction and store the resulting map in a local binding.
Reuse that binding when populating graph_children, then clone the map when
initializing record_edges before extending it with children and
own_resolved_peers; preserve the existing edge contents and ordering.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro Plus

Run ID: 194ab2cf-c01f-4dc2-846e-cf136ebdc1a2

📥 Commits

Reviewing files that changed from the base of the PR and between fa8d383 and 42e2b53.

📒 Files selected for processing (3)
  • pnpm/crates/resolving-deps-resolver/src/resolve_peers/cache.rs
  • pnpm/crates/resolving-deps-resolver/src/resolve_peers/finalize.rs
  • pnpm/crates/resolving-deps-resolver/src/resolve_peers/walker.rs

@github-actions github-actions Bot added the reviewed: coderabbit CodeRabbit submitted an approving review label Aug 1, 2026

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Refactors the Rust resolving-deps-resolver peer-resolution walker by extracting large, sequential chunks of Walker::resolve_node into focused helper functions, reducing function length while keeping the walk’s control flow and behavior intact.

Changes:

  • Extracts descendant ParentRefs construction into Walker::build_child_parent_refs and node-local peer resolution/depPath rendering into Walker::resolve_node_peers.
  • Moves graph-entry / NodeRecord capture into Walker::record_walked_node (in finalize.rs) via a WalkedNode context struct.
  • Simplifies deferred_child_resolution to avoid a redundant pure_pkgs lookup.

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated no comments.

File Description
pnpm/crates/resolving-deps-resolver/src/resolve_peers/walker.rs Splits resolve_node into named phases and routes graph/node-record capture through record_walked_node.
pnpm/crates/resolving-deps-resolver/src/resolve_peers/finalize.rs Introduces WalkedNode and implements Walker::record_walked_node for graph entry + NodeRecord capture.
pnpm/crates/resolving-deps-resolver/src/resolve_peers/cache.rs Uses a let-chain to reuse the pure_pkgs.get() result and avoid double hashing.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@github-actions

github-actions Bot commented Aug 1, 2026

Copy link
Copy Markdown
Contributor

Micro-Benchmark Results

Linux

group                                            main                                   pr
-----                                            ----                                   --
lockfile/parse_pnpm_lock                         1.00     11.7±0.07ms    31.9 MB/sec    1.00     11.8±0.03ms    31.8 MB/sec
packument/parse                                  1.00     36.1±0.05µs  1836.6 MB/sec    1.01     36.6±0.12µs  1814.0 MB/sec
tarball/download_dependency                      1.00      2.2±0.07ms  1946.1 KB/sec    1.02      2.3±0.05ms  1916.3 KB/sec
tarball_batch/cold_store_many_medium_tarballs    1.00    174.5±1.32ms 91.7 KElem/sec    1.00    173.8±3.35ms 92.1 KElem/sec

@codecov-commenter

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 98.71245% with 3 lines in your changes missing coverage. Please review.
✅ Project coverage is 87.95%. Comparing base (fa8d383) to head (42e2b53).

Files with missing lines Patch % Lines
...resolving-deps-resolver/src/resolve_peers/cache.rs 33.33% 2 Missing ⚠️
...esolving-deps-resolver/src/resolve_peers/walker.rs 99.31% 1 Missing ⚠️
Additional details and impacted files
@@           Coverage Diff           @@
##             main   #13564   +/-   ##
=======================================
  Coverage   87.94%   87.95%           
=======================================
  Files         556      556           
  Lines       97218    97290   +72     
=======================================
+ Hits        85502    85574   +72     
  Misses      11716    11716           

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@github-actions

github-actions Bot commented Aug 1, 2026

Copy link
Copy Markdown
Contributor

Integrated-Benchmark Report (Linux)

Commit: 42e2b538bda1

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

Command Mean [s] Min [s] Max [s] Relative
pacquet@HEAD 2.537 ± 0.164 2.363 2.793 1.62 ± 0.17
pacquet@main 2.541 ± 0.136 2.358 2.685 1.62 ± 0.16
pnpr@HEAD 1.616 ± 0.136 1.372 1.783 1.03 ± 0.12
pnpr@main 1.564 ± 0.130 1.372 1.761 1.00
BENCHMARK_REPORT.json
{
  "results": [
    {
      "command": "pacquet@HEAD",
      "mean": 2.5366197360599996,
      "stddev": 0.16396173579577786,
      "median": 2.5614080367599996,
      "user": 1.6620065,
      "system": 1.4438008999999998,
      "min": 2.36291397726,
      "max": 2.79345854326,
      "times": [
        2.64904344626,
        2.58708531226,
        2.74626997826,
        2.5720632752599997,
        2.55075279826,
        2.36291397726,
        2.37725212426,
        2.36295369226,
        2.36440421326,
        2.79345854326
      ]
    },
    {
      "command": "pacquet@main",
      "mean": 2.54123696046,
      "stddev": 0.13570920999032632,
      "median": 2.55552455476,
      "user": 1.5166585,
      "system": 1.3346324999999997,
      "min": 2.3584795972599997,
      "max": 2.68498503326,
      "times": [
        2.68498503326,
        2.46970722426,
        2.45135933526,
        2.67089170526,
        2.4430647572599997,
        2.65607660926,
        2.36366960926,
        2.67279384826,
        2.64134188526,
        2.3584795972599997
      ]
    },
    {
      "command": "pnpr@HEAD",
      "mean": 1.6160081144600003,
      "stddev": 0.13613010894989158,
      "median": 1.6625394417600001,
      "user": 1.1143355000000001,
      "system": 1.1525181,
      "min": 1.3722566212600003,
      "max": 1.7829520432600001,
      "times": [
        1.6997013152600002,
        1.4463259512600002,
        1.7829520432600001,
        1.6420486172600002,
        1.7059770222600001,
        1.3722566212600003,
        1.47150269726,
        1.66833768326,
        1.71423799326,
        1.6567412002600002
      ]
    },
    {
      "command": "pnpr@main",
      "mean": 1.56410710066,
      "stddev": 0.13000624178104034,
      "median": 1.5617223407600003,
      "user": 1.0973198,
      "system": 1.1572128999999998,
      "min": 1.3724774892600002,
      "max": 1.76072519726,
      "times": [
        1.6571963662600002,
        1.4458713572600002,
        1.4759312962600002,
        1.4350913602600002,
        1.68525687426,
        1.68507638426,
        1.76072519726,
        1.3724774892600002,
        1.57488434526,
        1.5485603362600002
      ]
    }
  ]
}

Scenario: Isolated linker: fresh restore, hot cache + hot store

Command Mean [ms] Min [ms] Max [ms] Relative
pacquet@HEAD 267.9 ± 6.4 259.1 282.4 1.01 ± 0.03
pacquet@main 265.2 ± 6.4 255.6 278.4 1.00
pnpr@HEAD 273.9 ± 9.0 262.0 294.4 1.03 ± 0.04
pnpr@main 266.9 ± 7.4 256.3 276.5 1.01 ± 0.04
BENCHMARK_REPORT.json
{
  "results": [
    {
      "command": "pacquet@HEAD",
      "mean": 0.26786260784000004,
      "stddev": 0.006385520380675129,
      "median": 0.26679712144,
      "user": 0.21325618,
      "system": 0.5662082199999999,
      "min": 0.25910149994000004,
      "max": 0.28240671694,
      "times": [
        0.25910149994000004,
        0.26361814894,
        0.26540538194,
        0.27132969194,
        0.27175150494000005,
        0.26486324294,
        0.26835758794000003,
        0.26360344194,
        0.26818886094000005,
        0.28240671694
      ]
    },
    {
      "command": "pacquet@main",
      "mean": 0.26515284394000005,
      "stddev": 0.00636214590386498,
      "median": 0.26442702094000003,
      "user": 0.20737537999999994,
      "system": 0.5415349199999999,
      "min": 0.25559139394,
      "max": 0.27841333194,
      "times": [
        0.27195305394,
        0.26158083494,
        0.26160776494000004,
        0.26718046294000003,
        0.26078618894000005,
        0.26515541094000006,
        0.25559139394,
        0.26369863094,
        0.26556136594,
        0.27841333194
      ]
    },
    {
      "command": "pnpr@HEAD",
      "mean": 0.27389463654,
      "stddev": 0.009037955012320983,
      "median": 0.27310427144000005,
      "user": 0.22649518,
      "system": 0.53683192,
      "min": 0.26201796894,
      "max": 0.29441171894,
      "times": [
        0.26201796894,
        0.27278623194,
        0.26578806394000004,
        0.26677034094,
        0.27295274594,
        0.27325579694,
        0.28092309494,
        0.27396502094,
        0.29441171894,
        0.27607538194000003
      ]
    },
    {
      "command": "pnpr@main",
      "mean": 0.26690346184,
      "stddev": 0.007445017610083496,
      "median": 0.26945110644000003,
      "user": 0.20734328,
      "system": 0.51834232,
      "min": 0.25631692194000005,
      "max": 0.27654475694,
      "times": [
        0.27654475694,
        0.27234602394,
        0.26084648294,
        0.26913485094000006,
        0.26976736194,
        0.27375296994000003,
        0.25968161694,
        0.25631692194000005,
        0.25789680194000003,
        0.27274683094
      ]
    }
  ]
}

Scenario: Isolated linker: fresh install, cold cache + cold store

Command Mean [s] Min [s] Max [s] Relative
pacquet@HEAD 2.622 ± 0.027 2.574 2.670 1.64 ± 0.15
pacquet@main 2.612 ± 0.016 2.578 2.630 1.63 ± 0.15
pnpr@HEAD 1.600 ± 0.142 1.426 1.799 1.00
pnpr@main 1.614 ± 0.139 1.453 1.815 1.01 ± 0.12
BENCHMARK_REPORT.json
{
  "results": [
    {
      "command": "pacquet@HEAD",
      "mean": 2.62247140292,
      "stddev": 0.02657543292316169,
      "median": 2.62461895792,
      "user": 1.5266627199999998,
      "system": 1.3834747200000002,
      "min": 2.57410748642,
      "max": 2.6699865564200005,
      "times": [
        2.61758532942,
        2.6375754024200004,
        2.62670576642,
        2.63678604642,
        2.5976160654200005,
        2.57410748642,
        2.6699865564200005,
        2.6225321494200005,
        2.63910317342,
        2.60271605342
      ]
    },
    {
      "command": "pacquet@main",
      "mean": 2.61226957402,
      "stddev": 0.015982554640511723,
      "median": 2.6156347459200004,
      "user": 1.50075982,
      "system": 1.3490272200000002,
      "min": 2.57839721242,
      "max": 2.6297883634200003,
      "times": [
        2.6276146344200004,
        2.62223135342,
        2.6168513194200003,
        2.60632452742,
        2.57839721242,
        2.62284803942,
        2.59402469842,
        2.6101974194200004,
        2.6297883634200003,
        2.61441817242
      ]
    },
    {
      "command": "pnpr@HEAD",
      "mean": 1.60013076332,
      "stddev": 0.14213346603148272,
      "median": 1.59919636542,
      "user": 1.05143292,
      "system": 1.19387392,
      "min": 1.42569728942,
      "max": 1.79932221342,
      "times": [
        1.52922387842,
        1.6104699634200002,
        1.42569728942,
        1.78853746942,
        1.4460933464199999,
        1.64299419142,
        1.58792276742,
        1.43562218342,
        1.73542433042,
        1.79932221342
      ]
    },
    {
      "command": "pnpr@main",
      "mean": 1.6135558142200002,
      "stddev": 0.1392131667279271,
      "median": 1.5924176399199998,
      "user": 1.04575272,
      "system": 1.19896052,
      "min": 1.45298696842,
      "max": 1.8149467424199999,
      "times": [
        1.52369104642,
        1.45298696842,
        1.5880303894199999,
        1.5968048904199998,
        1.72473393542,
        1.8149467424199999,
        1.45955438542,
        1.46936343242,
        1.79438075542,
        1.71106559642
      ]
    }
  ]
}

Scenario: Isolated linker: fresh install, hot cache + hot store

Command Mean [ms] Min [ms] Max [ms] Relative
pacquet@HEAD 416.7 ± 7.6 397.8 423.9 1.34 ± 0.04
pacquet@main 403.9 ± 6.7 391.9 414.2 1.30 ± 0.03
pnpr@HEAD 317.3 ± 5.7 309.1 326.6 1.02 ± 0.03
pnpr@main 311.8 ± 6.1 299.0 319.8 1.00
BENCHMARK_REPORT.json
{
  "results": [
    {
      "command": "pacquet@HEAD",
      "mean": 0.41668811442000003,
      "stddev": 0.007555873723221158,
      "median": 0.41793608102,
      "user": 0.5480385799999999,
      "system": 0.7179017599999999,
      "min": 0.39781623252000003,
      "max": 0.42389295152,
      "times": [
        0.41323025552000003,
        0.39781623252000003,
        0.41827654752000004,
        0.42036048052,
        0.42389295152,
        0.41479364952000003,
        0.41567353652,
        0.42361052152,
        0.42163135452,
        0.41759561452
      ]
    },
    {
      "command": "pacquet@main",
      "mean": 0.40385547052000004,
      "stddev": 0.006703899990773348,
      "median": 0.40389230251999997,
      "user": 0.53433478,
      "system": 0.70147246,
      "min": 0.39192761452,
      "max": 0.41419179652000004,
      "times": [
        0.39929876352,
        0.39942397952,
        0.40002756552,
        0.40442999452,
        0.40485779152,
        0.41274171552,
        0.41419179652000004,
        0.40335461052,
        0.40830087352,
        0.39192761452
      ]
    },
    {
      "command": "pnpr@HEAD",
      "mean": 0.31726750982,
      "stddev": 0.0056877516204784815,
      "median": 0.31669934002,
      "user": 0.22115468,
      "system": 0.5484001600000001,
      "min": 0.30913441052,
      "max": 0.32664018352,
      "times": [
        0.31883466552,
        0.31366999052,
        0.31493540352,
        0.31995974452000003,
        0.32664018352,
        0.31843945152,
        0.31093953952000003,
        0.31495922852,
        0.32516248052,
        0.30913441052
      ]
    },
    {
      "command": "pnpr@main",
      "mean": 0.31182034382,
      "stddev": 0.006051504873275873,
      "median": 0.31294105802,
      "user": 0.20498988,
      "system": 0.5494460600000001,
      "min": 0.29899522852,
      "max": 0.31975134152,
      "times": [
        0.31081398252000003,
        0.31413039752,
        0.31731769852,
        0.31975134152,
        0.31029596852,
        0.31175171852,
        0.31542307152,
        0.31448012652,
        0.30524390452,
        0.29899522852
      ]
    }
  ]
}

Scenario: Isolated linker: fresh install, cold cache + hot store

Command Mean [s] Min [s] Max [s] Relative
pacquet@HEAD 1.751 ± 0.008 1.741 1.766 5.61 ± 0.07
pacquet@main 1.750 ± 0.009 1.736 1.764 5.61 ± 0.07
pnpr@HEAD 0.312 ± 0.004 0.306 0.317 1.00
pnpr@main 0.315 ± 0.004 0.309 0.323 1.01 ± 0.02
BENCHMARK_REPORT.json
{
  "results": [
    {
      "command": "pacquet@HEAD",
      "mean": 1.7510197084599999,
      "stddev": 0.00782730550117651,
      "median": 1.7497980267600002,
      "user": 0.7353836799999999,
      "system": 0.7902086999999998,
      "min": 1.74075771376,
      "max": 1.7656986667599999,
      "times": [
        1.7656986667599999,
        1.7493151577600001,
        1.74075771376,
        1.74238358576,
        1.75028089576,
        1.74419760176,
        1.74866219776,
        1.75574234876,
        1.7537192017599998,
        1.75943971476
      ]
    },
    {
      "command": "pacquet@main",
      "mean": 1.7504426723599997,
      "stddev": 0.0085175578174428,
      "median": 1.75074953926,
      "user": 0.7653818799999998,
      "system": 0.7529739999999998,
      "min": 1.73610369776,
      "max": 1.7641876567600001,
      "times": [
        1.7568368027599999,
        1.75861429076,
        1.75412593676,
        1.74755292876,
        1.7641876567600001,
        1.73610369776,
        1.74363165476,
        1.75394614976,
        1.7432093397600001,
        1.7462182657599998
      ]
    },
    {
      "command": "pnpr@HEAD",
      "mean": 0.31206779116,
      "stddev": 0.0037119920444754055,
      "median": 0.31222559626,
      "user": 0.21362877999999993,
      "system": 0.5489993999999998,
      "min": 0.30598756876000005,
      "max": 0.31721001276000005,
      "times": [
        0.31274258976,
        0.31176746376000003,
        0.31653207676,
        0.31263062876000003,
        0.31182056376,
        0.30598756876000005,
        0.31457701576,
        0.30637775276,
        0.31721001276000005,
        0.31103223876
      ]
    },
    {
      "command": "pnpr@main",
      "mean": 0.31516894136,
      "stddev": 0.004235183127154506,
      "median": 0.31518317126000006,
      "user": 0.20181317999999998,
      "system": 0.5670211,
      "min": 0.30913146976,
      "max": 0.32262379876,
      "times": [
        0.31217885776000004,
        0.31896774276,
        0.31455757776000004,
        0.31042672876000005,
        0.30913146976,
        0.31871933576,
        0.31682752276000004,
        0.32262379876,
        0.31580876476,
        0.31244761476000005
      ]
    }
  ]
}

Scenario: Isolated linker: fresh resolve, hot cache, offline

Command Mean [ms] Min [ms] Max [ms] Relative
pacquet@HEAD 189.1 ± 5.4 178.9 196.3 2.16 ± 0.07
pacquet@main 188.9 ± 5.6 180.2 201.2 2.16 ± 0.07
pnpr@HEAD 87.4 ± 1.6 83.6 91.4 1.00 ± 0.02
pnpr@main 87.4 ± 1.2 85.3 89.6 1.00
BENCHMARK_REPORT.json
{
  "results": [
    {
      "command": "pacquet@HEAD",
      "mean": 0.18912750864666666,
      "stddev": 0.005358353193703929,
      "median": 0.19076400198000001,
      "user": 0.17006995333333333,
      "system": 0.07743232666666668,
      "min": 0.17888575198,
      "max": 0.19634395998,
      "times": [
        0.18414066898,
        0.19479055498,
        0.18843869198000002,
        0.18173982698,
        0.17888575198,
        0.19280300198,
        0.19454688598,
        0.19369918998,
        0.18359029098000001,
        0.19634395998,
        0.19004072998000002,
        0.18424403398,
        0.19193579898000002,
        0.19076400198000001,
        0.19094924098000002
      ]
    },
    {
      "command": "pacquet@main",
      "mean": 0.18891894797999997,
      "stddev": 0.005559890092865042,
      "median": 0.18943461798,
      "user": 0.16803488666666672,
      "system": 0.07831846,
      "min": 0.18021827298,
      "max": 0.20121418198000002,
      "times": [
        0.18952857498,
        0.18908770498,
        0.19271326298,
        0.18943461798,
        0.18960676298,
        0.18682255998,
        0.18467250998,
        0.19371181298,
        0.19261700198,
        0.18771854598,
        0.19340995498,
        0.20121418198000002,
        0.18161090498000002,
        0.18141754998,
        0.18021827298
      ]
    },
    {
      "command": "pnpr@HEAD",
      "mean": 0.08743521813151515,
      "stddev": 0.0015958600241565307,
      "median": 0.08713533498,
      "user": 0.02231980787878788,
      "system": 0.008028967878787879,
      "min": 0.08363676198,
      "max": 0.09135121098000001,
      "times": [
        0.08629780398,
        0.08745020998,
        0.08593443998,
        0.08363676198,
        0.08816767298,
        0.08704947398000001,
        0.08707105498,
        0.09130191898000001,
        0.09061116497999999,
        0.08700982798000001,
        0.08536675698000001,
        0.08818658998000001,
        0.08740936198000002,
        0.08970881198,
        0.09135121098000001,
        0.08567644198000002,
        0.08713533498,
        0.08693685998,
        0.08870352498,
        0.08647736398,
        0.08695365298000002,
        0.08804208598000002,
        0.08675815298,
        0.08792574698,
        0.08725342897999999,
        0.08624770998,
        0.08753668198,
        0.08829262898000001,
        0.08643101598,
        0.08774697098,
        0.08662716498,
        0.08758364098000002,
        0.08648072898
      ]
    },
    {
      "command": "pnpr@main",
      "mean": 0.08736287394969697,
      "stddev": 0.001243866333644927,
      "median": 0.08727401598000001,
      "user": 0.02061526242424242,
      "system": 0.009272777575757575,
      "min": 0.08525554698000001,
      "max": 0.08962658798,
      "times": [
        0.08678801997999999,
        0.08577593898,
        0.08682069098,
        0.08856267998,
        0.08789726298,
        0.08556427998000002,
        0.08742285698000002,
        0.08775160898,
        0.08711424598,
        0.08692407598000002,
        0.08818559698,
        0.08739557598,
        0.08648449798000002,
        0.08661964098,
        0.08840012198,
        0.08907633798,
        0.08691069098000001,
        0.08942264298,
        0.08868355598,
        0.08870457598,
        0.08525554698000001,
        0.08529056398000001,
        0.08682958798000001,
        0.08727401598000001,
        0.08695522498,
        0.08771317698,
        0.08817137098,
        0.08536665698000001,
        0.08776126698,
        0.08708495097999999,
        0.08962658798,
        0.08562218798000001,
        0.08951880298
      ]
    }
  ]
}

Scenario: Isolated linker: peer-heavy resolve, hot cache, offline

Command Mean [s] Min [s] Max [s] Relative
pacquet@HEAD 1.587 ± 0.363 1.078 2.413 1.00
pacquet@main 1.675 ± 0.501 1.019 2.448 1.06 ± 0.40
pnpm@HEAD 2.943 ± 0.073 2.840 3.063 1.85 ± 0.43
BENCHMARK_REPORT.json
{
  "results": [
    {
      "command": "pacquet@HEAD",
      "mean": 1.5866591262511112,
      "stddev": 0.36321730907020716,
      "median": 1.53122665814,
      "user": 1.4825131666666664,
      "system": 0.20418441333333337,
      "min": 1.07768312914,
      "max": 2.41339054514,
      "times": [
        1.71417514614,
        2.41339054514,
        1.41073060914,
        1.46285352214,
        1.67727812014,
        1.53122665814,
        1.3897162871400002,
        1.6028781191400001,
        1.07768312914
      ]
    },
    {
      "command": "pacquet@main",
      "mean": 1.675165267251111,
      "stddev": 0.5006962950118337,
      "median": 1.75514957014,
      "user": 1.569011611111111,
      "system": 0.20839563555555554,
      "min": 1.01935173714,
      "max": 2.44754694114,
      "times": [
        2.22056408314,
        1.25824768914,
        1.01935173714,
        1.75514957014,
        2.44754694114,
        2.00336683414,
        1.0783615501400001,
        1.51325474714,
        1.7806442531400002
      ]
    },
    {
      "command": "pnpm@HEAD",
      "mean": 2.9428498251399997,
      "stddev": 0.07334738010663884,
      "median": 2.93024626414,
      "user": 4.5326445,
      "system": 0.27396596888888886,
      "min": 2.84048429114,
      "max": 3.06333840714,
      "times": [
        3.02024016314,
        2.88402330514,
        3.06333840714,
        2.84048429114,
        2.89490092514,
        2.93524372814,
        3.01141391814,
        2.93024626414,
        2.90575742414
      ]
    }
  ]
}

Scenario: Isolated linker: fresh restore, cold cache + cold store + cold pnpr

Command Mean [s] Min [s] Max [s] Relative
pacquet@HEAD 4.548 ± 0.111 4.427 4.775 1.29 ± 0.04
pacquet@main 4.466 ± 0.040 4.427 4.564 1.27 ± 0.03
pnpr@HEAD 3.525 ± 0.065 3.458 3.650 1.00
pnpr@main 3.578 ± 0.144 3.448 3.821 1.01 ± 0.04
BENCHMARK_REPORT.json
{
  "results": [
    {
      "command": "pacquet@HEAD",
      "mean": 4.548073903380001,
      "stddev": 0.11135516706673187,
      "median": 4.54414049758,
      "user": 1.74758192,
      "system": 1.35151822,
      "min": 4.42739480058,
      "max": 4.77528453358,
      "times": [
        4.50901978558,
        4.77528453358,
        4.42739480058,
        4.43904034758,
        4.61738119358,
        4.61876386158,
        4.57926120958,
        4.44932744858,
        4.4584804695799995,
        4.60678538358
      ]
    },
    {
      "command": "pacquet@main",
      "mean": 4.46636631158,
      "stddev": 0.04041600746635626,
      "median": 4.45513724458,
      "user": 1.71715402,
      "system": 1.42290492,
      "min": 4.42686232258,
      "max": 4.56397777458,
      "times": [
        4.4588349775800005,
        4.45143951158,
        4.50389980858,
        4.46937089558,
        4.46393362258,
        4.44828247458,
        4.56397777458,
        4.43449159458,
        4.42686232258,
        4.44257013358
      ]
    },
    {
      "command": "pnpr@HEAD",
      "mean": 3.52543465288,
      "stddev": 0.06506632140408841,
      "median": 3.49998586958,
      "user": 1.21576862,
      "system": 1.29201012,
      "min": 3.45847423458,
      "max": 3.64985845158,
      "times": [
        3.5620635155800002,
        3.56666926758,
        3.59572352958,
        3.51961621558,
        3.64985845158,
        3.48013105058,
        3.48035552358,
        3.45847423458,
        3.4656780615800002,
        3.47577667858
      ]
    },
    {
      "command": "pnpr@main",
      "mean": 3.5781310190799998,
      "stddev": 0.14376946293647838,
      "median": 3.51146010608,
      "user": 1.2174785199999998,
      "system": 1.27040532,
      "min": 3.44791301858,
      "max": 3.82085620058,
      "times": [
        3.70398129858,
        3.45646157958,
        3.4577862765800003,
        3.49046367658,
        3.49158645358,
        3.5313337585799998,
        3.82085620058,
        3.5845696935799998,
        3.79635823458,
        3.44791301858
      ]
    }
  ]
}

@github-actions

github-actions Bot commented Aug 1, 2026

Copy link
Copy Markdown
Contributor

🐰 Bencher Report

Projectpnpm's project
Branchpr/13564
Testbedpacquet
Click to view all benchmark results
BenchmarkLatencyBenchmark Result
milliseconds (ms)
(Result Δ%)
Upper Boundary
milliseconds (ms)
(Limit %)
isolated-linker.fresh-install.cold-cache.cold-store📈 view plot
🚷 view threshold
2,574.11 ms
(-3.98%)Baseline: 2,680.82 ms
3,216.98 ms
(80.02%)
isolated-linker.fresh-install.cold-cache.hot-store📈 view plot
🚷 view threshold
1,740.76 ms
(-4.33%)Baseline: 1,819.57 ms
2,183.48 ms
(79.72%)
isolated-linker.fresh-install.hot-cache.hot-store📈 view plot
🚷 view threshold
397.82 ms
(-15.85%)Baseline: 472.75 ms
567.30 ms
(70.12%)
isolated-linker.fresh-resolve.hot-cache.offline📈 view plot
🚷 view threshold
178.89 ms
(-18.88%)Baseline: 220.51 ms
264.61 ms
(67.60%)
isolated-linker.fresh-restore.cold-cache.cold-store📈 view plot
🚷 view threshold
2,362.91 ms
(-2.83%)Baseline: 2,431.78 ms
2,918.13 ms
(80.97%)
isolated-linker.fresh-restore.cold-cache.cold-store.cold-pnpr📈 view plot
🚷 view threshold
4,427.39 ms
(-2.16%)Baseline: 4,525.34 ms
5,430.41 ms
(81.53%)
isolated-linker.fresh-restore.hot-cache.hot-store📈 view plot
🚷 view threshold
259.10 ms
(-8.64%)Baseline: 283.59 ms
340.31 ms
(76.14%)
isolated-linker.peer-heavy-resolve.hot-cache.offline📈 view plot
🚷 view threshold
1,077.68 ms
🐰 View full continuous benchmarking report in Bencher

@github-actions

github-actions Bot commented Aug 1, 2026

Copy link
Copy Markdown
Contributor

🐰 Bencher Report

Projectpnpm's project
Branchpr/13564
Testbedpnpr

⚠️ 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-thresholds flag.

Click to view all benchmark results
BenchmarkLatencymilliseconds (ms)
isolated-linker.fresh-install.cold-cache.cold-store📈 view plot
⚠️ NO THRESHOLD
1,425.70 ms
isolated-linker.fresh-install.cold-cache.hot-store📈 view plot
⚠️ NO THRESHOLD
305.99 ms
isolated-linker.fresh-install.hot-cache.hot-store📈 view plot
⚠️ NO THRESHOLD
309.13 ms
isolated-linker.fresh-resolve.hot-cache.offline📈 view plot
⚠️ NO THRESHOLD
83.64 ms
isolated-linker.fresh-restore.cold-cache.cold-store📈 view plot
⚠️ NO THRESHOLD
1,372.26 ms
isolated-linker.fresh-restore.cold-cache.cold-store.cold-pnpr📈 view plot
⚠️ NO THRESHOLD
3,458.47 ms
isolated-linker.fresh-restore.hot-cache.hot-store📈 view plot
⚠️ NO THRESHOLD
262.02 ms
🐰 View full continuous benchmarking report in Bencher

@zkochan
zkochan merged commit fea49c1 into main Aug 1, 2026
36 checks passed
@zkochan
zkochan deleted the fix-13553 branch August 1, 2026 16:11
zkochan added a commit that referenced this pull request Aug 1, 2026
…nce per node (#13565)

record_walked_node called previously_resolved_children twice with identical
arguments — once to seed the graph children, once to seed the record edges.
Each call rescans the ancestor pkg-id chain and, on a match, re-realizes every
matching occurrence's children, so the second one was pure repeat work in the
peer-resolution hot path.

Build the record edges first and iterate them by reference for the graph
children. The clone count is unchanged — the per-entry clones in the loop
replace the ones the second call made while rebuilding the map — while one
chain scan and one realize_children pass go away, and the common case (the
node's package is not in its own ancestor chain, so the map is empty) now does
strictly less work.

Raised by CodeRabbit on #13564. Its suggested fix cloned the map into
the first loop instead, which trades one cost for another; building the record
edges first removes the call without adding a clone.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

product: pacquet reviewed: coderabbit CodeRabbit submitted an approving review

Projects

None yet

Development

Successfully merging this pull request may close these issues.

refactor(pacquet): split resolve_node into its sequential phases

3 participants