Skip to content

perf(resolver): make multi-importer peer-hoist discovery linear - #13491

Merged
zkochan merged 6 commits into
mainfrom
perf/workspace-full-resolution
Jul 29, 2026
Merged

zkochan merged 6 commits into
mainfrom
perf/workspace-full-resolution

Conversation

@zkochan

@zkochan zkochan commented Jul 29, 2026 •

Copy link
Copy Markdown
Member

Summary

Fixes the multi-importer full-resolution regression observed when pnpm is used through @pnpm/napi by Bit.

  • add a deterministic pnpm-side benchmark reproducing the Bit-sized workload (331 importers, 5,000 shared packages, peer-hoist discovery, no lockfile reuse)
  • replace the hoist loop's per-importer, per-round full tree snapshot + full peer pass with a PeerHoistDiscovery engine shared by every hoist round of one workspace resolve: one persistent tree view incrementally synced from the workspace context, plus persistent walker caches (purePkgs, peersCache, parent contexts) so a subtree settled by one importer's pass short-circuits every compatible revisit — the same sharing the final resolve_peers_workspace pass already applies within its single call
  • rebuild the discovery view whenever the sync cannot merge safely: a children-ownership handover that rewrote existing occurrence nodes (tracked by a rewrite counter), a re-recorded child list, or a changed peer split
  • discovery mode skips DependenciesGraph construction entirely; the hoist loop only consumes missing peers and resolved providers, and each peers-cache item carries its subtree's per-package missing breakdown so the owner-scope report stays exact under cross-round cache hits
  • remove the remaining per-importer O(workspace) barrier costs: the children-owner map deep clone in record_first_walk_missing, the whole-packages rescan in the preferred-versions fold (now an append-only log read through a per-importer cursor), and the per-importer owner-scope map clones (now snapshotted once per barrier)
  • fix the environment-sensitive stderr assertions in the CLI deploy tests that fail whenever miette's wrap point lands inside the asserted phrase

Benchmark (cargo bench -p pacquet-resolving-deps-resolver --bench workspace_full_resolution):

resolver time peak RSS
before 65.1 s 3.76 GiB
after 1.55 s 1.14 GiB

On the real Bit workspace driven through @pnpm/napi, a warm repeat bd install drops from ~4 minutes to ~65 s total, of which the engine accounts for 1.5 s (frozen path); the rest is Bit's own component loading and compilation.

This is a pure engine-side performance fix with no user-visible behavior change, so no TypeScript-side port is needed.

Squash Commit Body

The auto-install-peers hoist loop cloned the workspace tree and ran a
full peer pass - DependenciesGraph construction included - once per
importer per round, making a from-scratch resolve of a large component
workspace quadratic in both time and memory (the regression Bit hit
through the napi engine).

Replace the per-round snapshot + full pass with a PeerHoistDiscovery
engine shared by every hoist round of one workspace resolve:

- discovery walks share one persistent tree view, incrementally synced
  from the workspace context; a children-ownership handover that
  rewrites existing occurrence nodes (tracked by a rewrite counter), a
  re-recorded child list, or a changed peer split discards the whole
  view instead of merging;
- the walker's purePkgs / peersCache / parent-context maps persist
  across rounds and importers, so a subtree settled by one importer's
  pass short-circuits every compatible revisit - the same sharing the
  final resolve_peers_workspace pass already applies within one call;
- discovery skips graph construction entirely: the hoist loop only
  consumes missing peers and resolved providers, and each peers-cache
  item carries its subtree's per-package missing breakdown so the
  owner-scope report stays exact under cross-round cache hits.

Also drop the remaining per-importer O(workspace) costs in the initial
barrier: record_first_walk_missing no longer deep-clones the
children-owner map, the preferred-versions fold reads an append-only
resolved-versions log through a per-importer cursor, and the
owner-scope maps are snapshotted once per barrier. The CLI deploy
tests' stderr assertions are also made robust to miette's
path-length-dependent line wrapping.

cargo bench -p pacquet-resolving-deps-resolver --bench workspace_full_resolution
(331 importers, 5,000 shared packages, peer hoisting, no lockfile):
before 65.1s / 3.76 GiB peak RSS; after 1.55s / 1.14 GiB.

Checklist

  • 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-fable-5).


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

@coderabbitai

coderabbitai Bot commented Jul 29, 2026 •

Copy link
Copy Markdown
Contributor

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro Plus

Run ID: e547bd4d-88f1-4a8b-83fc-9a543aff3a3d

📥 Commits

Reviewing files that changed from the base of the PR and between da4ea12 and a4f62a0.

📒 Files selected for processing (5)
  • .changeset/workspace-hoist-discovery-linear.md
  • pnpm/crates/resolving-deps-resolver/src/resolve_dependency_tree.rs
  • pnpm/crates/resolving-deps-resolver/src/resolve_dependency_tree/tests.rs
  • pnpm/crates/resolving-deps-resolver/src/resolve_peers.rs
  • pnpm/crates/resolving-deps-resolver/src/resolve_peers/tests.rs
🚧 Files skipped from review as they are similar to previous changes (2)
  • pnpm/crates/resolving-deps-resolver/src/resolve_dependency_tree.rs
  • pnpm/crates/resolving-deps-resolver/src/resolve_peers.rs

📝 Walkthrough

Walkthrough

Workspace peer-hoist resolution now performs persistent graph-free discovery with incremental synchronization and importer-scoped snapshots. Required rounds reuse discovery state and version cursors. A large-workspace benchmark, regression tests, release note, and deploy stderr normalization were added.

Changes

Workspace peer-hoist discovery

Layer / File(s) Summary
Incremental workspace state
pnpm/crates/resolving-deps-resolver/src/resolve_dependency_tree.rs, pnpm/crates/resolving-deps-resolver/src/resolve_dependency_tree/tests.rs, pnpm/crates/resolving-deps-resolver/src/resolved_tree.rs
Workspace contexts track revisions and newly resolved versions, synchronize discovery changes, and create reachable importer snapshots.
Persistent peer discovery engine
pnpm/crates/resolving-deps-resolver/src/resolve_peers.rs, pnpm/crates/resolving-deps-resolver/src/resolve_peers/tests.rs
Discovery-mode walkers reuse caches and subtree missing-peer data without building the final dependency graph.
Importer and workspace fixed-point integration
pnpm/crates/resolving-deps-resolver/src/resolve_importer.rs, pnpm/crates/resolving-deps-resolver/src/resolve_workspace.rs, pnpm/crates/resolving-deps-resolver/src/lib.rs
Required rounds share peer discovery, apply discovery results, inject providers by package id, and update preferred versions incrementally.
Benchmark and release validation
pnpm/crates/resolving-deps-resolver/benches/workspace_full_resolution.rs, pnpm/crates/resolving-deps-resolver/Cargo.toml, .changeset/workspace-hoist-discovery-linear.md
A 331-importer workspace benchmark and changeset document the updated resolution path and performance result.

Deploy error-output test normalization

Layer / File(s) Summary
Stable deploy error assertions
pnpm/crates/cli/tests/deploy.rs
Deploy safety tests flatten miette-wrapped stderr before checking error messages.

Estimated code review effort: 4 (Complex) | ~60 minutes

Sequence Diagram(s)

sequenceDiagram
  participant resolve_workspace
  participant ImporterHoistState
  participant PeerHoistDiscovery
  participant WorkspaceTreeCtx
  resolve_workspace->>PeerHoistDiscovery: create shared discovery engine
  resolve_workspace->>ImporterHoistState: execute required round
  ImporterHoistState->>PeerHoistDiscovery: discover peer issues and providers
  ImporterHoistState->>WorkspaceTreeCtx: read newly resolved versions
  ImporterHoistState-->>resolve_workspace: apply hoisted providers and repeat
Loading

Possibly related issues

  • pnpm/pnpm#11633: The resolver optimization and workspace benchmark advance the Rust resolution-engine roadmap described by this issue.

Possibly related PRs

  • pnpm/pnpm#13343: Changes the workspace-root dependency basis used during peer-hoisting rounds.
  • pnpm/pnpm#13387: Modifies workspace hoisted-root dependency handling in resolve_importer.rs.
  • pnpm/pnpm#13432: Updates peer-hoisting rounds and missing-scope propagation.

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 perf/workspace-full-resolution

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.

@github-actions

github-actions Bot commented Jul 29, 2026 •

Copy link
Copy Markdown
Contributor

Micro-Benchmark Results

Linux

group                                            main                                   pr
-----                                            ----                                   --
lockfile/parse_pnpm_lock                         1.00     14.5±2.06ms    25.9 MB/sec    1.06     15.3±3.92ms    24.5 MB/sec
packument/parse                                  1.00     47.6±6.89µs  1394.5 MB/sec    1.52    72.3±12.34µs   917.3 MB/sec
tarball/download_dependency                      1.00      5.3±0.78ms   825.8 KB/sec    1.11      5.8±0.65ms   743.7 KB/sec
tarball_batch/cold_store_many_medium_tarballs    1.00   251.7±37.47ms 63.6 KElem/sec    1.13   283.7±25.20ms 56.4 KElem/sec

@codecov-commenter

codecov-commenter commented Jul 29, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 96.59574% with 16 lines in your changes missing coverage. Please review.
✅ Project coverage is 87.93%. Comparing base (6eed03f) to head (a4f62a0).
⚠️ Report is 1 commits behind head on main.

Files with missing lines Patch % Lines
...rates/resolving-deps-resolver/src/resolve_peers.rs 95.00% 13 Missing ⚠️
...lving-deps-resolver/src/resolve_dependency_tree.rs 97.85% 3 Missing ⚠️
Additional details and impacted files
@@           Coverage Diff            @@
##             main   #13491    +/-   ##
========================================
  Coverage   87.92%   87.93%            
========================================
  Files         549      549            
  Lines       95561    95872   +311     
========================================
+ Hits        84018    84301   +283     
- Misses      11543    11571    +28     

☔ 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 Jul 29, 2026 •

Copy link
Copy Markdown
Contributor

Integrated-Benchmark Report (Linux)

Commit: da4ea1234b5d

Each scenario reports direct installs and pnpr installs. 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.626 ± 0.138 2.414 2.802 1.72 ± 0.18
pacquet@main 2.564 ± 0.156 2.394 2.781 1.68 ± 0.19
pnpr@HEAD 1.617 ± 0.178 1.381 1.818 1.06 ± 0.15
pnpr@main 1.526 ± 0.142 1.375 1.781 1.00
BENCHMARK_REPORT.json
{
  "results": [
    {
      "command": "pacquet@HEAD",
      "mean": 2.6262860409,
      "stddev": 0.13774241590139713,
      "median": 2.6466960695,
      "user": 1.9514065799999998,
      "system": 1.5210219999999999,
      "min": 2.4142172005,
      "max": 2.8019152785,
      "times": [
        2.6931373115,
        2.4890583295,
        2.7215094045,
        2.7092272294999997,
        2.7861772184999998,
        2.5884606505,
        2.4589029585,
        2.4142172005,
        2.8019152785,
        2.6002548275
      ]
    },
    {
      "command": "pacquet@main",
      "mean": 2.5641089590999995,
      "stddev": 0.15623489046700137,
      "median": 2.5166234725,
      "user": 1.7219431800000002,
      "system": 1.3823902,
      "min": 2.3937466955,
      "max": 2.7810623144999997,
      "times": [
        2.7588407745,
        2.5314860605,
        2.3937466955,
        2.4057643465,
        2.5941566295,
        2.5017608845,
        2.7810623144999997,
        2.4989670045,
        2.7739211304999998,
        2.4013837505
      ]
    },
    {
      "command": "pnpr@HEAD",
      "mean": 1.6173187580000001,
      "stddev": 0.17781551908374485,
      "median": 1.6154905065,
      "user": 1.25090028,
      "system": 1.3341404999999997,
      "min": 1.3806070995,
      "max": 1.8175668645,
      "times": [
        1.8151251275,
        1.5557886834999999,
        1.3960962715,
        1.7941869335,
        1.3806070995,
        1.8175668645,
        1.5853914615,
        1.6455895515,
        1.4151535655,
        1.7676820215
      ]
    },
    {
      "command": "pnpr@main",
      "mean": 1.5260904274000002,
      "stddev": 0.1416212315618846,
      "median": 1.497962256,
      "user": 1.2143393799999997,
      "system": 1.3140443999999998,
      "min": 1.3750111505,
      "max": 1.7814699704999999,
      "times": [
        1.5179202715,
        1.4502312335,
        1.7814699704999999,
        1.7451239345,
        1.4780042405,
        1.4055222415,
        1.5493832895000001,
        1.5709456895,
        1.3872922525,
        1.3750111505
      ]
    }
  ]
}

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

Command Mean [ms] Min [ms] Max [ms] Relative
pacquet@HEAD 318.9 ± 29.3 289.2 375.1 1.14 ± 0.12
pacquet@main 279.8 ± 12.7 264.5 300.8 1.00
pnpr@HEAD 297.4 ± 12.5 281.3 321.6 1.06 ± 0.07
pnpr@main 315.0 ± 26.4 276.7 367.1 1.13 ± 0.11
BENCHMARK_REPORT.json
{
  "results": [
    {
      "command": "pacquet@HEAD",
      "mean": 0.3188593638800001,
      "stddev": 0.02931798542031895,
      "median": 0.30956920048000003,
      "user": 0.27456610000000004,
      "system": 0.6071104,
      "min": 0.28917209648000003,
      "max": 0.37506645848000003,
      "times": [
        0.37506645848000003,
        0.34904421448000006,
        0.32434321948000006,
        0.31615235648,
        0.30298604448000005,
        0.29202925548,
        0.28917209648000003,
        0.29282583848000004,
        0.34644800548000004,
        0.30052614948
      ]
    },
    {
      "command": "pacquet@main",
      "mean": 0.27975280018000004,
      "stddev": 0.012703376286417326,
      "median": 0.27444179048000006,
      "user": 0.2317868,
      "system": 0.5572121,
      "min": 0.26450238948000004,
      "max": 0.30084668148000004,
      "times": [
        0.28579052448000003,
        0.26838079348000005,
        0.30084668148000004,
        0.27303312948,
        0.27448059348000003,
        0.27440298748,
        0.26450238948000004,
        0.26924586548,
        0.29684229248000005,
        0.29000274448
      ]
    },
    {
      "command": "pnpr@HEAD",
      "mean": 0.29742348758000003,
      "stddev": 0.012485160972571303,
      "median": 0.29713919798,
      "user": 0.24889260000000002,
      "system": 0.5602288,
      "min": 0.28130052348,
      "max": 0.32158890348,
      "times": [
        0.30714646648000005,
        0.28615789348000004,
        0.29237292948000004,
        0.28130052348,
        0.28279404448,
        0.30495588848000005,
        0.29602663148,
        0.29825176448,
        0.30363983048000004,
        0.32158890348
      ]
    },
    {
      "command": "pnpr@main",
      "mean": 0.31498857238,
      "stddev": 0.02641536386798515,
      "median": 0.31300854098,
      "user": 0.2721787,
      "system": 0.5974778,
      "min": 0.27666910748,
      "max": 0.36713561448000004,
      "times": [
        0.30552782148,
        0.31297050948000005,
        0.31705334648000005,
        0.31304657248,
        0.29191221548,
        0.29237839948000005,
        0.33915816348000005,
        0.36713561448000004,
        0.33403397348,
        0.27666910748
      ]
    }
  ]
}

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

Command Mean [s] Min [s] Max [s] Relative
pacquet@HEAD 2.706 ± 0.010 2.691 2.724 1.74 ± 0.09
pacquet@main 2.807 ± 0.040 2.752 2.894 1.81 ± 0.10
pnpr@HEAD 1.602 ± 0.109 1.473 1.838 1.03 ± 0.09
pnpr@main 1.555 ± 0.079 1.441 1.660 1.00
BENCHMARK_REPORT.json
{
  "results": [
    {
      "command": "pacquet@HEAD",
      "mean": 2.7063385664400004,
      "stddev": 0.009714354021915388,
      "median": 2.70757871684,
      "user": 1.7392925599999998,
      "system": 1.38616978,
      "min": 2.6910397893400004,
      "max": 2.72379121334,
      "times": [
        2.6959309423400004,
        2.70566808334,
        2.70245210234,
        2.70948935034,
        2.72379121334,
        2.6910397893400004,
        2.6992191993400003,
        2.70963796934,
        2.7165745993400003,
        2.7095824153400003
      ]
    },
    {
      "command": "pacquet@main",
      "mean": 2.8071581334400006,
      "stddev": 0.039687195338023486,
      "median": 2.8029365168400004,
      "user": 1.8359317599999998,
      "system": 1.34521048,
      "min": 2.75209752634,
      "max": 2.8939667203400004,
      "times": [
        2.8062470273400004,
        2.7771262513400004,
        2.75209752634,
        2.7996260063400005,
        2.81401512034,
        2.78098742534,
        2.8453757693400004,
        2.8939667203400004,
        2.81489244534,
        2.78724704234
      ]
    },
    {
      "command": "pnpr@HEAD",
      "mean": 1.60162576874,
      "stddev": 0.10934165083412299,
      "median": 1.58123233934,
      "user": 1.15228956,
      "system": 1.24741238,
      "min": 1.4733673483399998,
      "max": 1.83799399134,
      "times": [
        1.57718732834,
        1.63622383834,
        1.4733673483399998,
        1.83799399134,
        1.53078625534,
        1.56813849034,
        1.58527735034,
        1.48791555134,
        1.59882505534,
        1.7205424783399998
      ]
    },
    {
      "command": "pnpr@main",
      "mean": 1.5546691969400002,
      "stddev": 0.07931858661202044,
      "median": 1.5570471213400001,
      "user": 1.1906818599999998,
      "system": 1.26205708,
      "min": 1.44122643634,
      "max": 1.65980305634,
      "times": [
        1.55803069534,
        1.51957724434,
        1.44122643634,
        1.6422507603399998,
        1.65980305634,
        1.62589723334,
        1.45710708634,
        1.47651699634,
        1.61021891334,
        1.55606354734
      ]
    }
  ]
}

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

Command Mean [ms] Min [ms] Max [ms] Relative
pacquet@HEAD 562.2 ± 20.4 523.5 585.7 1.73 ± 0.12
pacquet@main 650.9 ± 14.7 633.3 678.0 2.00 ± 0.13
pnpr@HEAD 347.6 ± 25.8 299.8 379.9 1.07 ± 0.10
pnpr@main 325.6 ± 19.7 304.3 364.0 1.00
BENCHMARK_REPORT.json
{
  "results": [
    {
      "command": "pacquet@HEAD",
      "mean": 0.56222773104,
      "stddev": 0.020421005998196774,
      "median": 0.5685308989400001,
      "user": 0.7290276,
      "system": 0.71712968,
      "min": 0.5234867189400001,
      "max": 0.58574712494,
      "times": [
        0.57153168594,
        0.5829433569400001,
        0.58146176794,
        0.58574712494,
        0.5479583199400001,
        0.5234867189400001,
        0.5700486749400001,
        0.5470240079400001,
        0.5670131229400001,
        0.54506252994
      ]
    },
    {
      "command": "pacquet@main",
      "mean": 0.65089690264,
      "stddev": 0.01469827414409172,
      "median": 0.6458189899400001,
      "user": 0.8035876,
      "system": 0.70642138,
      "min": 0.63334790894,
      "max": 0.6780230669400001,
      "times": [
        0.6444117459400001,
        0.6703848229400001,
        0.6359688439400001,
        0.63334790894,
        0.6613266859400001,
        0.6524645069400001,
        0.6470315589400001,
        0.6446064209400001,
        0.6780230669400001,
        0.6414034649400001
      ]
    },
    {
      "command": "pnpr@HEAD",
      "mean": 0.34764361974,
      "stddev": 0.025784462739360577,
      "median": 0.35114024894,
      "user": 0.2337075,
      "system": 0.5973638799999998,
      "min": 0.29984588294000003,
      "max": 0.37987574094000004,
      "times": [
        0.31925684394000003,
        0.34409286794,
        0.35095244194,
        0.29984588294000003,
        0.32537801294,
        0.37987574094000004,
        0.37069031594,
        0.36820697794,
        0.35132805594,
        0.36680905694
      ]
    },
    {
      "command": "pnpr@main",
      "mean": 0.32563001733999997,
      "stddev": 0.0197372583706814,
      "median": 0.32015222294,
      "user": 0.21599580000000002,
      "system": 0.55897318,
      "min": 0.30433186494000003,
      "max": 0.36396040594,
      "times": [
        0.36396040594,
        0.35685877794000004,
        0.32057576694,
        0.30433186494000003,
        0.32573893994,
        0.31972867894,
        0.30993538294,
        0.32799612194,
        0.31191337394,
        0.31526085994
      ]
    }
  ]
}

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

Command Mean [s] Min [s] Max [s] Relative
pacquet@HEAD 1.880 ± 0.039 1.832 1.963 5.72 ± 0.28
pacquet@main 1.981 ± 0.015 1.960 2.007 6.03 ± 0.27
pnpr@HEAD 0.333 ± 0.013 0.310 0.352 1.01 ± 0.06
pnpr@main 0.329 ± 0.014 0.308 0.347 1.00
BENCHMARK_REPORT.json
{
  "results": [
    {
      "command": "pacquet@HEAD",
      "mean": 1.8803399920399997,
      "stddev": 0.03921164828872728,
      "median": 1.87524439474,
      "user": 1.0073402599999999,
      "system": 0.76971874,
      "min": 1.83210955574,
      "max": 1.96284321674,
      "times": [
        1.84760406274,
        1.8788730097400002,
        1.87886276074,
        1.8580403647400001,
        1.83210955574,
        1.90328635174,
        1.87162602874,
        1.96284321674,
        1.9203222987400002,
        1.8498322707400001
      ]
    },
    {
      "command": "pacquet@main",
      "mean": 1.9814574578400002,
      "stddev": 0.01498932158302224,
      "median": 1.9781747632400002,
      "user": 1.1334515599999997,
      "system": 0.77162494,
      "min": 1.96013116074,
      "max": 2.00727862574,
      "times": [
        2.00727862574,
        2.0044219297400003,
        1.98660200074,
        1.97598821774,
        1.98036130874,
        1.9686383547400002,
        1.97351025974,
        1.98491403574,
        1.97272868474,
        1.96013116074
      ]
    },
    {
      "command": "pnpr@HEAD",
      "mean": 0.33266298924000004,
      "stddev": 0.013180462568632445,
      "median": 0.33615683074,
      "user": 0.22136256000000004,
      "system": 0.5590070399999999,
      "min": 0.30962102374000006,
      "max": 0.35173050074000006,
      "times": [
        0.35173050074000006,
        0.33989834274,
        0.33897501174000005,
        0.34556263474000004,
        0.33839253874,
        0.33392112274,
        0.30962102374000006,
        0.31524302774,
        0.32683826074000005,
        0.32644742874000005
      ]
    },
    {
      "command": "pnpr@main",
      "mean": 0.3287763845400001,
      "stddev": 0.014410528188978942,
      "median": 0.32749107074000006,
      "user": 0.22935626,
      "system": 0.56052934,
      "min": 0.30841350874,
      "max": 0.34741253374000003,
      "times": [
        0.32542916874000005,
        0.34741253374000003,
        0.31380220474000003,
        0.31699440074,
        0.30841350874,
        0.31895691074000004,
        0.34456618574000003,
        0.32955297274000006,
        0.33532440474,
        0.34731155474000003
      ]
    }
  ]
}

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

Command Mean [ms] Min [ms] Max [ms] Relative
pacquet@HEAD 363.8 ± 20.9 337.5 404.0 3.60 ± 0.50
pacquet@main 510.9 ± 54.4 445.3 596.9 5.05 ± 0.83
pnpr@HEAD 101.1 ± 12.7 90.7 141.3 1.00
pnpr@main 104.1 ± 19.2 88.8 159.7 1.03 ± 0.23
BENCHMARK_REPORT.json
{
  "results": [
    {
      "command": "pacquet@HEAD",
      "mean": 0.36376410554000005,
      "stddev": 0.020873125182456573,
      "median": 0.36199744854000004,
      "user": 0.35433966,
      "system": 0.07793537999999998,
      "min": 0.33749501904,
      "max": 0.40401749104,
      "times": [
        0.33749501904,
        0.34888012204,
        0.37385172504,
        0.37448502304000003,
        0.34425670004000003,
        0.38421874004,
        0.36779847304,
        0.40401749104,
        0.34644133804000005,
        0.35619642404
      ]
    },
    {
      "command": "pacquet@main",
      "mean": 0.51087304444,
      "stddev": 0.054391988580523354,
      "median": 0.5048129935400001,
      "user": 0.5022711599999999,
      "system": 0.07709337999999999,
      "min": 0.44534259404000004,
      "max": 0.5968631160400001,
      "times": [
        0.48139920704000005,
        0.44695232304000004,
        0.46921637904,
        0.58149118604,
        0.47737660204000004,
        0.5968631160400001,
        0.5282267800400001,
        0.44534259404000004,
        0.5448654270400001,
        0.5369968300400001
      ]
    },
    {
      "command": "pnpr@HEAD",
      "mean": 0.10107652693285714,
      "stddev": 0.0126946738009862,
      "median": 0.09593073854,
      "user": 0.02866771000000001,
      "system": 0.013605279999999999,
      "min": 0.09067342404,
      "max": 0.14127303204,
      "times": [
        0.09852452804,
        0.13745417904,
        0.11030975104,
        0.09760118704000001,
        0.09545036204,
        0.09804615104,
        0.09467855404,
        0.09292331304,
        0.10422413704,
        0.09291849304000001,
        0.09489212504,
        0.09086099504,
        0.09309974304,
        0.09334298004000001,
        0.14127303204,
        0.11075361404,
        0.10000437304,
        0.09265403704,
        0.09067342404,
        0.09251031904,
        0.10970273304,
        0.10503971604000001,
        0.09602127304000001,
        0.09452557804,
        0.09254167704,
        0.09883697404,
        0.09584020404,
        0.11543930104000001
      ]
    },
    {
      "command": "pnpr@main",
      "mean": 0.10406136665538462,
      "stddev": 0.019233717039577006,
      "median": 0.09683677304,
      "user": 0.031347536923076916,
      "system": 0.013546356923076923,
      "min": 0.08883034704000001,
      "max": 0.15966950304,
      "times": [
        0.10629489104,
        0.08883034704000001,
        0.09400850904000001,
        0.09522208404,
        0.09734605804,
        0.10649098804,
        0.14955901204,
        0.09602287604000001,
        0.10022210104,
        0.09581664004,
        0.09216131404,
        0.09452478704,
        0.09868388604,
        0.09914971004,
        0.09881828804000001,
        0.09670004704,
        0.09294302004,
        0.09661787204,
        0.10050807804,
        0.12379739604000001,
        0.14919325504,
        0.09195980604000001,
        0.09149328004,
        0.09258828504000001,
        0.09697349904000001,
        0.15966950304
      ]
    }
  ]
}

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

Command Mean [s] Min [s] Max [s] Relative
pacquet@HEAD 4.701 ± 0.154 4.505 4.932 1.31 ± 0.05
pacquet@main 4.566 ± 0.116 4.468 4.820 1.27 ± 0.03
pnpr@HEAD 3.702 ± 0.124 3.497 3.898 1.03 ± 0.04
pnpr@main 3.590 ± 0.038 3.523 3.640 1.00
BENCHMARK_REPORT.json
{
  "results": [
    {
      "command": "pacquet@HEAD",
      "mean": 4.700944708120001,
      "stddev": 0.154054401086469,
      "median": 4.69708385702,
      "user": 2.5619976,
      "system": 1.7813388600000004,
      "min": 4.50538950002,
      "max": 4.9318777450199995,
      "times": [
        4.70823665202,
        4.9059934390199995,
        4.571727303019999,
        4.9318777450199995,
        4.71558264802,
        4.68593106202,
        4.61960368902,
        4.84912839302,
        4.51597665002,
        4.50538950002
      ]
    },
    {
      "command": "pacquet@main",
      "mean": 4.5661516107199995,
      "stddev": 0.11597365812124254,
      "median": 4.52844129752,
      "user": 2.0540413,
      "system": 1.5165134599999999,
      "min": 4.46803383102,
      "max": 4.819625450019999,
      "times": [
        4.53246724102,
        4.475508245019999,
        4.57025078502,
        4.58314636102,
        4.49184426002,
        4.47934788102,
        4.46803383102,
        4.524415354019999,
        4.716876699019999,
        4.819625450019999
      ]
    },
    {
      "command": "pnpr@HEAD",
      "mean": 3.70167975912,
      "stddev": 0.12449259457617189,
      "median": 3.69128114952,
      "user": 1.6449376,
      "system": 1.5827577600000002,
      "min": 3.49692158202,
      "max": 3.8978502770200003,
      "times": [
        3.77926597102,
        3.49692158202,
        3.78428503602,
        3.5991433170200002,
        3.8978502770200003,
        3.60901517602,
        3.68108001702,
        3.8448622450200003,
        3.62289168802,
        3.70148228202
      ]
    },
    {
      "command": "pnpr@main",
      "mean": 3.589638435220001,
      "stddev": 0.037732075576824814,
      "median": 3.59177993252,
      "user": 1.6879863999999998,
      "system": 1.57865216,
      "min": 3.52313357502,
      "max": 3.64029219702,
      "times": [
        3.60189239402,
        3.63182182302,
        3.57786543602,
        3.55415685402,
        3.58663304602,
        3.62665762702,
        3.52313357502,
        3.59692681902,
        3.55700458102,
        3.64029219702
      ]
    }
  ]
}

@github-actions

github-actions Bot commented Jul 29, 2026 •

Copy link
Copy Markdown
Contributor

🐰 Bencher Report

Projectpnpm's project
Branchpr/13491
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,691.04 ms
(-4.60%)Baseline: 2,820.92 ms
3,385.10 ms
(79.50%)
isolated-linker.fresh-install.cold-cache.hot-store📈 view plot
🚷 view threshold
1,832.11 ms
(-6.72%)Baseline: 1,964.12 ms
2,356.94 ms
(77.73%)
isolated-linker.fresh-install.hot-cache.hot-store📈 view plot
🚷 view threshold
523.49 ms
(-18.39%)Baseline: 641.43 ms
769.72 ms
(68.01%)
isolated-linker.fresh-resolve.hot-cache.offline📈 view plot
🚷 view threshold
337.50 ms
(-15.24%)Baseline: 398.17 ms
477.80 ms
(70.64%)
isolated-linker.fresh-restore.cold-cache.cold-store📈 view plot
🚷 view threshold
2,414.22 ms
(-0.97%)Baseline: 2,437.76 ms
2,925.31 ms
(82.53%)
isolated-linker.fresh-restore.cold-cache.cold-store.cold-pnpr📈 view plot
🚷 view threshold
4,505.39 ms
(-0.36%)Baseline: 4,521.55 ms
5,425.86 ms
(83.04%)
isolated-linker.fresh-restore.hot-cache.hot-store📈 view plot
🚷 view threshold
289.17 ms
(+1.91%)Baseline: 283.75 ms
340.50 ms
(84.92%)
🐰 View full continuous benchmarking report in Bencher

@github-actions

github-actions Bot commented Jul 29, 2026 •

Copy link
Copy Markdown
Contributor

🐰 Bencher Report

Projectpnpm's project
Branchpr/13491
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,473.37 ms
isolated-linker.fresh-install.cold-cache.hot-store📈 view plot
⚠️ NO THRESHOLD
309.62 ms
isolated-linker.fresh-install.hot-cache.hot-store📈 view plot
⚠️ NO THRESHOLD
299.85 ms
isolated-linker.fresh-resolve.hot-cache.offline📈 view plot
⚠️ NO THRESHOLD
90.67 ms
isolated-linker.fresh-restore.cold-cache.cold-store📈 view plot
⚠️ NO THRESHOLD
1,380.61 ms
isolated-linker.fresh-restore.cold-cache.cold-store.cold-pnpr📈 view plot
⚠️ NO THRESHOLD
3,496.92 ms
isolated-linker.fresh-restore.hot-cache.hot-store📈 view plot
⚠️ NO THRESHOLD
281.30 ms
🐰 View full continuous benchmarking report in Bencher

zkochan and others added 3 commits July 29, 2026 15:58
miette wraps the report at a point that depends on the temp path
length, so a phrase assertion like "contains a symlink" fails whenever
the wrap lands inside the phrase — the continuation gutter glyph also
lands between the words, so plain whitespace-collapsing is not enough.
Strip the box-drawing tokens and collapse the report onto one line
before matching, in all four deploy-target assertions.

Co-Authored-By: Claude Fable 5 <[email protected]>
The auto-install-peers hoist loop cloned the workspace tree and ran a
full peer pass — DependenciesGraph construction included — once per
importer per round, making a from-scratch resolve of a large component
workspace quadratic in both time and memory.

Replace the per-round snapshot + full pass with a PeerHoistDiscovery
engine shared by every hoist round of one workspace resolve:

- discovery walks share one persistent tree view, incrementally synced
  from the workspace context (rebuilt from scratch when a
  children-owner change rewrites recorded children or a peer split);
- the walker's purePkgs / peersCache / parent-context maps persist
  across rounds and importers, so a subtree settled by one importer's
  pass short-circuits every compatible revisit — the same sharing the
  final resolve_peers_workspace pass already applies within one call;
- discovery skips graph construction entirely: the hoist loop only
  consumes missing peers and resolved providers, and each peers-cache
  item now carries its subtree's per-package missing breakdown so the
  owner-scope report stays exact under cross-round cache hits.

Also drop the remaining per-importer O(workspace) costs in the initial
barrier: record_first_walk_missing no longer deep-clones the
children-owner map, the preferred-versions fold reads an append-only
resolved-versions log through a per-importer cursor, and the
owner-scope maps are snapshotted once per barrier instead of once per
importer.

cargo bench -p pacquet-resolving-deps-resolver --bench workspace_full_resolution
(331 importers, 5,000 shared packages, peer hoisting, no lockfile):

- before: 65.1s resolver time, 3.76 GiB peak RSS
- after: 1.55s resolver time, 1.14 GiB peak RSS

Co-Authored-By: Claude Fable 5 <[email protected]>
@zkochan
zkochan marked this pull request as ready for review July 29, 2026 14:13
Copilot AI review requested due to automatic review settings July 29, 2026 14:13

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.

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

@qodo-code-review

Copy link
Copy Markdown

PR Summary by Qodo

perf(resolver): make multi-importer peer-hoist discovery linear

✨ Enhancement 🐞 Bug fix 🧪 Tests 🕐 40+ Minutes

Grey Divider

AI Description

• Add a deterministic benchmark modeling Bit-scale multi-importer full resolution.
• Share peer-hoist discovery state across importers/rounds to remove quadratic snapshots.
• Stabilize CLI deploy stderr assertions by flattening miette-wrapped reports.
Diagram

graph TD
  F{{"workspace_full_resolution bench"}} --> A["resolve_workspace"] --> B["ImporterHoistState hoist loop"] --> C[["PeerHoistDiscovery"]] --> D["Walker (discovery)"]
  C --> E[("WorkspaceTreeCtx")]
  E --> C
  subgraph Legend
    direction LR
    _mod["Module"] ~~~ _eng[["Engine (cached)"]] ~~~ _data[("Shared context")] ~~~ _test{{"Benchmark/Test"}}
  end
Loading
High-Level Assessment

The following are alternative approaches to this PR:

1. Run resolve_peers_workspace per hoist round (workspace-wide pass)
  • ➕ Leverages existing workspace sharing logic with minimal new state machinery
  • ➕ Keeps a single codepath for peer resolution behavior
  • ➖ Still likely expensive to repeat full graph/depPath work each hoist round
  • ➖ Harder to limit the hoist loop to just the data it consumes (missing peers + providers)
2. Keep per-importer snapshots but pool them with copy-on-write diffs
  • ➕ Avoids introducing discovery mode and Walker branching
  • ➕ May reduce memory versus deep cloning full trees per importer
  • ➖ Complex correctness story for invalidation on children-owner changes/peer splits
  • ➖ Still risks high CPU due to repeated full walks over mostly-identical subtrees

Recommendation: The chosen approach (shared PeerHoistDiscovery with incremental tree sync + persistent caches, and graph-free discovery output) is the best fit for the regression: it targets the exact hot path (per-importer/per-round repetition) while preserving the final full resolve_peers_workspace behavior for install correctness. The added revision/invalidation hooks (sync_discovery_tree returning unmergeable) are a pragmatic way to keep caching safe when the workspace context mutates incompatibly.

Files changed (12) +1027 / -240

Enhancement (4) +708 / -202
resolve_dependency_tree.rsAdd revisioned workspace ctx syncing, reachable snapshots, and version log +212/-13

Add revisioned workspace ctx syncing, reachable snapshots, and version log

• Extends WorkspaceTreeCtx with a revision counter and an append-only resolved-versions log to eliminate repeated full rescans. Adds an importer-scoped reachable snapshot API, incremental sync support for the discovery engine, and utilities to map provider NodeIds to existing package IDs without holding full snapshots.

pnpm/crates/resolving-deps-resolver/src/resolve_dependency_tree.rs

resolve_importer.rsSwitch hoist required rounds to shared peer-hoist discovery +75/-44

Switch hoist required rounds to shared peer-hoist discovery

• Reworks the required hoist round to consume PeerDiscoveryResult (missing peers + providers) instead of full ResolvePeersResult built from per-importer full snapshots. Also removes per-round preferred-version rescans via a per-importer cursor into the workspace resolved-versions log, and reduces owner-scope cloning by sharing barrier snapshots.

pnpm/crates/resolving-deps-resolver/src/resolve_importer.rs

resolve_peers.rsIntroduce PeerHoistDiscovery engine and discovery-mode walker +395/-139

Introduce PeerHoistDiscovery engine and discovery-mode walker

• Adds a shared PeerHoistDiscovery with incremental workspace sync and persistent walker caches. Implements a discovery-only walk path that skips DependenciesGraph/node-record construction while preserving peer matching and issue reporting, including subtree missing-peer breakdown replayed on cache hits.

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

resolve_workspace.rsShare PeerHoistDiscovery across workspace hoist rounds and snapshot owner scope once +26/-6

Share PeerHoistDiscovery across workspace hoist rounds and snapshot owner scope once

• Creates a single PeerHoistDiscovery instance for the entire workspace hoist phase, threading it through importer required rounds. Snapshots owner-scope maps once per barrier and drops the discovery engine before the final merged-tree snapshot to reduce peak memory.

pnpm/crates/resolving-deps-resolver/src/resolve_workspace.rs

Refactor (1) +1 / -1
resolved_tree.rsMake ChildEdge comparable for sync conflict detection +1/-1

Make ChildEdge comparable for sync conflict detection

• Derives PartialEq/Eq for ChildEdge to support safe incremental sync checks when children lists are re-recorded under different owners.

pnpm/crates/resolving-deps-resolver/src/resolved_tree.rs

Tests (4) +300 / -31
deploy.rsHarden deploy CLI stderr assertions against miette wrapping +20/-8

Harden deploy CLI stderr assertions against miette wrapping

• Updates deploy tests to match against a flattened miette report instead of raw wrapped stderr. Introduces a helper that strips gutter glyphs and collapses whitespace so assertions are path-length independent.

pnpm/crates/cli/tests/deploy.rs

workspace_full_resolution.rsAdd deterministic multi-importer full-resolution regression benchmark +222/-0

Add deterministic multi-importer full-resolution regression benchmark

• Introduces a synthetic resolver and workspace generator modeling a 331-importer, 5,000-package layered graph with peer hoisting enabled and no lockfile reuse. Prints single-run timing and key counts to catch large regressions without statistical harness overhead.

pnpm/crates/resolving-deps-resolver/benches/workspace_full_resolution.rs

tests.rsTest importer-scoped reachable snapshot behavior +50/-1

Test importer-scoped reachable snapshot behavior

• Adds a unit test ensuring snapshot_reachable_from includes only the occurrence-node closure of an importer's direct deps, excluding unrelated importer nodes.

pnpm/crates/resolving-deps-resolver/src/resolve_dependency_tree/tests.rs

tests.rsRefactor peer-walker tests to use Walker::new constructor +8/-22

Refactor peer-walker tests to use Walker::new constructor

• Updates tests to construct Walker via the new constructor and cache container, aligning test setup with the new discovery-capable walker structure.

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

Documentation (2) +14 / -6
workspace-hoist-discovery-linear.mdAdd changeset documenting linearized workspace peer-hoist discovery +5/-0

Add changeset documenting linearized workspace peer-hoist discovery

• Adds a patch changeset describing the regression fix and the measured performance/memory improvements on a Bit-scale workspace workload.

.changeset/workspace-hoist-discovery-linear.md

lib.rsDocument graph-free peer discovery in the hoist loop +9/-6

Document graph-free peer discovery in the hoist loop

• Updates crate-level resolver pipeline docs to reflect that the hoist loop now uses a shared, graph-free discovery variant of the peer pass and runs the full pass once per install.

pnpm/crates/resolving-deps-resolver/src/lib.rs

Other (1) +4 / -0
Cargo.tomlRegister workspace_full_resolution benchmark target +4/-0

Register workspace_full_resolution benchmark target

• Adds a non-harness Criterion-style bench entry for the new deterministic performance regression benchmark.

pnpm/crates/resolving-deps-resolver/Cargo.toml

@greptile-apps

greptile-apps Bot commented Jul 29, 2026 •

Copy link
Copy Markdown
Contributor

Confidence Score: 5/5

The PR appears safe to merge.

No blocking failure remains.

Reviews (2): Last reviewed commit: "style(resolver): apply cargo fmt" | Re-trigger Greptile

@qodo-code-review

qodo-code-review Bot commented Jul 29, 2026 •

Copy link
Copy Markdown

Code Review by Qodo

🐞 Bugs (1) 📘 Rule violations (2) 📜 Skill insights (0)

Context used
✅ Compliance rules (platform): 24 rules

Grey Divider


Remediation recommended

1. Rewrite invalidation footgun 🐞 Bug ☼ Reliability ⭐ New
Description
WorkspaceTreeCtx::record_children_rewrite() advances children_rewrites but does not also advance
revision, while PeerHoistDiscovery::discover() only checks children_rewrites when it observes
a revision change. Any future call path that records a rewrite without also bumping the revision
can leave the discovery engine with stale tree/caches for the remainder of the workspace resolve.
Code

pnpm/crates/resolving-deps-resolver/src/resolve_dependency_tree.rs[R1091-1093]

+    pub(crate) fn record_children_rewrite(&self) {
+        self.children_rewrites.fetch_add(1, std::sync::atomic::Ordering::Relaxed);
+    }
Relevance

●●● Strong

Team often accepts subtle resolver reliability/cache-safety fixes; implicit revision+rewrite
contract is a future footgun.

PR-#13391
PR-#13431
PR-#13459

ⓘ Recommendations generated based on similar findings in past PRs

Evidence
The workspace context exposes separate mutation markers (revision, children_rewrites) but the
discovery engine only considers children_rewrites inside the revision-changed branch; tests
already document that rewrites must be paired with a revision bump, indicating the contract is
implicit and easy to violate later.

pnpm/crates/resolving-deps-resolver/src/resolve_dependency_tree.rs[1077-1093]
pnpm/crates/resolving-deps-resolver/src/resolve_peers.rs[377-390]
pnpm/crates/resolving-deps-resolver/src/resolve_peers/tests.rs[2064-2070]

Agent prompt
The issue below was found during a code review. Follow the provided context and guidance below and implement a solution

### Issue description
`PeerHoistDiscovery` only evaluates `children_rewrites` when `revision` changes. However, `record_children_rewrite()` increments only `children_rewrites`, creating an easy-to-miss invariant: callers must remember to also call `bump_revision()` whenever they record a rewrite.

If a future change introduces a rewrite outside `extend_tree()` (or otherwise forgets to pair the calls), the discovery engine may not rebuild, reusing stale subtree verdicts and producing incorrect peer-hoist discovery outcomes.

### Issue Context
This PR introduces the `children_rewrites` counter and the discovery-engine invalidation logic keyed by `revision`.

### Fix Focus Areas
- pnpm/crates/resolving-deps-resolver/src/resolve_dependency_tree.rs[1086-1094]
- pnpm/crates/resolving-deps-resolver/src/resolve_peers.rs[377-390]

### Suggested fix
Prefer making the invariant unskippable by design. Options:
1. Make `record_children_rewrite()` also call `bump_revision()` (or do an atomic add on `revision` too).
2. Replace the two methods with a single API, e.g. `record_children_rewrite_and_bump_revision()` and keep `record_children_rewrite()` private.
3. Alternatively, change `PeerHoistDiscovery::discover()` to always check `children_rewrites` (even when `revision` is unchanged), though this is less explicit and still leaves two counters to reason about.

ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools


2. Historical phrasing in benchmark 📘 Rule violation ⚙ Maintainability
Description
New documentation in the benchmark module and PeerHoistDiscovery uses historical/regression
framing (e.g., “Regression benchmark,” “regressed run,” and “Replaces …” with prior quadratic
behavior) instead of describing current behavior and constraints. This violates the requirement to
avoid past-implementation commentary and increases the risk the docs become stale or misleading.
Code

pnpm/crates/resolving-deps-resolver/benches/workspace_full_resolution.rs[R1-13]

+//! Regression benchmark for the large multi-importer full-resolution path.
+//!
+//! This models the Bit workspace that exposed the regression:
+//!
+//! - 331 component importers;
+//! - a shared 5,000-package layered dependency graph;
+//! - 20 direct roots per importer;
+//! - peer hoisting enabled, which runs the importer peer-discovery barrier;
+//! - no wanted lockfile, so the whole graph is resolved.
+//!
+//! Run once (the benchmark intentionally has no statistical harness because a
+//! regressed run can take minutes and several GiB):
+//!
Relevance

●●● Strong

Repo has accepted rewriting docs to avoid historical/regression phrasing and focus on current
contract.

PR-#13343
PR-#13172
PR-#13407

ⓘ Recommendations generated based on similar findings in past PRs

Evidence
PR Compliance ID 772199 forbids comments/docstrings that reference past behavior or implementations
using historical or temporal phrasing, requiring documentation to focus on present-day
behavior/contracts. The cited benchmark documentation explicitly characterizes itself as a
“regression benchmark” and refers to “regressed” runs, and the PeerHoistDiscovery doc comment
states it “Replaces” an older approach while describing prior performance (quadratic), which are all
examples of historical framing rather than statements of current invariants, behavior, or rationale
in present terms.

Rule 772199: Comments must describe current behavior, not historical implementations
pnpm/crates/resolving-deps-resolver/benches/workspace_full_resolution.rs[1-13]
pnpm/crates/resolving-deps-resolver/src/resolve_peers.rs[340-343]

Agent prompt
The issue below was found during a code review. Follow the provided context and guidance below and implement a solution

## Issue description
Comments/docstrings must describe current behavior, invariants, and constraints in present terms, and should not use historical/regression framing or language that refers to prior implementations (e.g., “Regression benchmark,” “regressed run,” or “Replaces …” with old performance characteristics).

## Issue Context
PR Compliance ID 772199 disallows historical/temporal phrasing in comments. The newly added benchmark documentation uses regression-focused wording (e.g., “Regression benchmark”, “exposed the regression”, “regressed run”) and the `PeerHoistDiscovery` doc comment uses historical language (“Replaces …”) and describes the old approach’s quadratic behavior; both should be rewritten to describe what the code/benchmark does now and, if necessary, why it exists, without referencing past implementations or regressions.

## Fix Focus Areas
- pnpm/crates/resolving-deps-resolver/benches/workspace_full_resolution.rs[1-13]
- pnpm/crates/resolving-deps-resolver/src/resolve_peers.rs[340-343]

ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools



Informational

3. Changeset missing pnpm entry 📘 Rule violation § Compliance
Description
The new changeset file lists only pacquet and omits a required pnpm package entry. This can
break or misrepresent release automation expectations for pnpm versioning/bump classification.
Code

.changeset/workspace-hoist-discovery-linear.md[R1-3]

+---
+"pacquet": patch
+---
Relevance

● Weak

Recent PRs rejected adding pnpm entry when changeset intentionally bumps only pacquet.

PR-#13459
PR-#13417
PR-#13343

ⓘ Recommendations generated based on similar findings in past PRs

Evidence
PR Compliance ID 713436 requires changesets to explicitly include a pnpm entry with a valid bump
type. The added changeset front-matter contains only "pacquet": patch and no pnpm entry.

Rule 713436: Explicitly declare pnpm package and correct bump type in changesets
.changeset/workspace-hoist-discovery-linear.md[1-3]

Agent prompt
The issue below was found during a code review. Follow the provided context and guidance below and implement a solution

## Issue description
The changeset `.changeset/workspace-hoist-discovery-linear.md` does not include a `pnpm` entry in its front-matter, but the compliance rule requires an explicit `pnpm` bump type.

## Issue Context
Changesets are used for release/version automation; omitting `pnpm` can cause missing or incorrect version bumps.

## Fix Focus Areas
- .changeset/workspace-hoist-discovery-linear.md[1-3]

ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools


Grey Divider

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

Previous review results

Review updated until commit a4f62a0 ⚖️ Balanced

Results up to commit da4ea12 ⚖️ Balanced


🐞 Bugs (0) 📘 Rule violations (2) 📎 Requirement gaps (0) 🎨 UX issues (0) 🔗 Cross-repo conflicts (0) 📜 Skill insights (0)


Remediation recommended
1. Historical phrasing in benchmark 📘 Rule violation ⚙ Maintainability
Description
New documentation in the benchmark module and PeerHoistDiscovery uses historical/regression
framing (e.g., “Regression benchmark,” “regressed run,” and “Replaces …” with prior quadratic
behavior) instead of describing current behavior and constraints. This violates the requirement to
avoid past-implementation commentary and increases the risk the docs become stale or misleading.
Code

pnpm/crates/resolving-deps-resolver/benches/workspace_full_resolution.rs[R1-13]

+//! Regression benchmark for the large multi-importer full-resolution path.
+//!
+//! This models the Bit workspace that exposed the regression:
+//!
+//! - 331 component importers;
+//! - a shared 5,000-package layered dependency graph;
+//! - 20 direct roots per importer;
+//! - peer hoisting enabled, which runs the importer peer-discovery barrier;
+//! - no wanted lockfile, so the whole graph is resolved.
+//!
+//! Run once (the benchmark intentionally has no statistical harness because a
+//! regressed run can take minutes and several GiB):
+//!
Relevance

●●● Strong

Repo has accepted rewriting docs to avoid historical/regression phrasing and focus on current
contract.

PR-#13343
PR-#13172
PR-#13407

ⓘ Recommendations generated based on similar findings in past PRs

Evidence
PR Compliance ID 772199 forbids comments/docstrings that reference past behavior or implementations
using historical or temporal phrasing, requiring documentation to focus on present-day
behavior/contracts. The cited benchmark documentation explicitly characterizes itself as a
“regression benchmark” and refers to “regressed” runs, and the PeerHoistDiscovery doc comment
states it “Replaces” an older approach while describing prior performance (quadratic), which are all
examples of historical framing rather than statements of current invariants, behavior, or rationale
in present terms.

Rule 772199: Comments must describe current behavior, not historical implementations
pnpm/crates/resolving-deps-resolver/benches/workspace_full_resolution.rs[1-13]
pnpm/crates/resolving-deps-resolver/src/resolve_peers.rs[340-343]

Agent prompt
The issue below was found during a code review. Follow the provided context and guidance below and implement a solution

## Issue description
Comments/docstrings must describe current behavior, invariants, and constraints in present terms, and should not use historical/regression framing or language that refers to prior implementations (e.g., “Regression benchmark,” “regressed run,” or “Replaces …” with old performance characteristics).

## Issue Context
PR Compliance ID 772199 disallows historical/temporal phrasing in comments. The newly added benchmark documentation uses regression-focused wording (e.g., “Regression benchmark”, “exposed the regression”, “regressed run”) and the `PeerHoistDiscovery` doc comment uses historical language (“Replaces …”) and describes the old approach’s quadratic behavior; both should be rewritten to describe what the code/benchmark does now and, if necessary, why it exists, without referencing past implementations or regressions.

## Fix Focus Areas
- pnpm/crates/resolving-deps-resolver/benches/workspace_full_resolution.rs[1-13]
- pnpm/crates/resolving-deps-resolver/src/resolve_peers.rs[340-343]

ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools



Informational
2. Changeset missing pnpm entry 📘 Rule violation § Compliance
Description
The new changeset file lists only pacquet and omits a required pnpm package entry. This can
break or misrepresent release automation expectations for pnpm versioning/bump classification.
Code

.changeset/workspace-hoist-discovery-linear.md[R1-3]

+---
+"pacquet": patch
+---
Relevance

● Weak

Recent PRs rejected adding pnpm entry when changeset intentionally bumps only pacquet.

PR-#13459
PR-#13417
PR-#13343

ⓘ Recommendations generated based on similar findings in past PRs

Evidence
PR Compliance ID 713436 requires changesets to explicitly include a pnpm entry with a valid bump
type. The added changeset front-matter contains only "pacquet": patch and no pnpm entry.

Rule 713436: Explicitly declare pnpm package and correct bump type in changesets
.changeset/workspace-hoist-discovery-linear.md[1-3]

Agent prompt
The issue below was found during a code review. Follow the provided context and guidance below and implement a solution

## Issue description
The changeset `.changeset/workspace-hoist-discovery-linear.md` does not include a `pnpm` entry in its front-matter, but the compliance rule requires an explicit `pnpm` bump type.

## Issue Context
Changesets are used for release/version automation; omitting `pnpm` can cause missing or incorrect version bumps.

## Fix Focus Areas
- .changeset/workspace-hoist-discovery-linear.md[1-3]

ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools


Qodo Logo

@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.

Actionable comments posted: 2

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

913-970: 🩺 Stability & Availability | 🔵 Trivial | 💤 Low value

Lock acquisition order is the reverse of snapshot() for packages/dependencies_tree.

snapshot (Line 888) acquires packages before dependencies_tree; snapshot_reachable_from holds the dependencies_tree guard (it is shadowed at Line 932, not dropped) and then takes packages at Line 955. Today both are only called from the sequential orchestrator, so this cannot deadlock, but the file documents lock order elsewhere (record_first_walk_missing). Consider either dropping the dependencies_tree guard explicitly after Line 937 (mirroring the drop(all_children) you already do) or recording the single-caller invariant.

♻️ Drop the guard once the filtered map is built
-        let dependencies_tree: HashMap<_, _> = reachable_node_ids
-            .iter()
-            .filter_map(|node_id| {
-                dependencies_tree.get(node_id).cloned().map(|node| (node_id.clone(), node))
-            })
-            .collect();
+        let reachable_dependencies_tree: HashMap<_, _> = reachable_node_ids
+            .iter()
+            .filter_map(|node_id| {
+                dependencies_tree.get(node_id).cloned().map(|node| (node_id.clone(), node))
+            })
+            .collect();
+        drop(dependencies_tree);
+        let dependencies_tree = reachable_dependencies_tree;
🤖 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.rs` around
lines 913 - 970, Update snapshot_reachable_from so the dependencies_tree lock
guard is explicitly dropped immediately after the filtered dependencies_tree map
is constructed and before acquiring the packages lock. Preserve the existing
reachable-tree collection logic and mirror the explicit drop(all_children)
pattern already used in the function.
pnpm/crates/resolving-deps-resolver/src/resolve_peers.rs (1)

1575-1582: 📐 Maintainability & Code Quality | 🔵 Trivial | 💤 Low value

Arc::unwrap_or_clone expresses this take-or-clone more directly.

♻️ Suggested simplification
-            let mut merged = match subtree_missing_by_pkg.take() {
-                Some(arc) => Arc::try_unwrap(arc).unwrap_or_else(|shared| (*shared).clone()),
-                None => HashMap::new(),
-            };
+            let mut merged = subtree_missing_by_pkg.take().map(Arc::unwrap_or_clone).unwrap_or_default();
🤖 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.rs` around lines 1575 -
1582, In the subtree_missing_by_pkg merge logic, replace the manual
Arc::try_unwrap(...).unwrap_or_else(...) pattern with Arc::unwrap_or_clone while
preserving the existing HashMap fallback and subsequent entry extension
behavior.
pnpm/crates/resolving-deps-resolver/src/resolve_dependency_tree/tests.rs (1)

50-91: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

Consider covering the lazy-edge package closure too.

The fixture has empty packages/children_by_id, so the second half of snapshot_reachable_from (walking children_by_id to include packages only reachable through lazy edges, and excluding a foreign importer's package) is untested — the part most likely to regress.

🤖 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/tests.rs`
around lines 50 - 91, Extend
importer_snapshot_excludes_other_importers_occurrence_nodes to populate packages
and children_by_id with a lazy-edge package reachable from root, plus a package
belonging only to the unrelated importer. Assert the snapshot includes the
lazily reachable package and excludes the foreign importer's package, covering
the second traversal in snapshot_reachable_from while preserving the existing
dependency-tree assertions.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In @.changeset/workspace-hoist-discovery-linear.md:
- Line 5: Rewrite the changeset entry to describe the user-visible improvement:
large multi-project workspaces now resolve from scratch faster and with lower
resource usage. Remove references to resolver internals, implementation details,
and run-specific benchmark figures.

In `@pnpm/crates/resolving-deps-resolver/src/resolve_dependency_tree.rs`:
- Around line 1121-1135: Update sync_discovery_tree’s occupied dependencies_tree
merge to account for children changes, not only the minimum depth. When an
existing node’s children shape differs from the shared node, either return false
to reject the merge or replace the discovery node’s children with the newer
value, ensuring Realized-to-Lazy transitions from make_non_owner_nodes_lazy are
reflected.

---

Nitpick comments:
In `@pnpm/crates/resolving-deps-resolver/src/resolve_dependency_tree.rs`:
- Around line 913-970: Update snapshot_reachable_from so the dependencies_tree
lock guard is explicitly dropped immediately after the filtered
dependencies_tree map is constructed and before acquiring the packages lock.
Preserve the existing reachable-tree collection logic and mirror the explicit
drop(all_children) pattern already used in the function.

In `@pnpm/crates/resolving-deps-resolver/src/resolve_dependency_tree/tests.rs`:
- Around line 50-91: Extend
importer_snapshot_excludes_other_importers_occurrence_nodes to populate packages
and children_by_id with a lazy-edge package reachable from root, plus a package
belonging only to the unrelated importer. Assert the snapshot includes the
lazily reachable package and excludes the foreign importer's package, covering
the second traversal in snapshot_reachable_from while preserving the existing
dependency-tree assertions.

In `@pnpm/crates/resolving-deps-resolver/src/resolve_peers.rs`:
- Around line 1575-1582: In the subtree_missing_by_pkg merge logic, replace the
manual Arc::try_unwrap(...).unwrap_or_else(...) pattern with
Arc::unwrap_or_clone while preserving the existing HashMap fallback and
subsequent entry extension behavior.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro Plus

Run ID: 50a4490a-9dc4-45e7-bec9-ea1f5591286e

📥 Commits

Reviewing files that changed from the base of the PR and between 6eed03f and da4ea12.

📒 Files selected for processing (12)
  • .changeset/workspace-hoist-discovery-linear.md
  • pnpm/crates/cli/tests/deploy.rs
  • pnpm/crates/resolving-deps-resolver/Cargo.toml
  • pnpm/crates/resolving-deps-resolver/benches/workspace_full_resolution.rs
  • pnpm/crates/resolving-deps-resolver/src/lib.rs
  • pnpm/crates/resolving-deps-resolver/src/resolve_dependency_tree.rs
  • pnpm/crates/resolving-deps-resolver/src/resolve_dependency_tree/tests.rs
  • pnpm/crates/resolving-deps-resolver/src/resolve_importer.rs
  • pnpm/crates/resolving-deps-resolver/src/resolve_peers.rs
  • pnpm/crates/resolving-deps-resolver/src/resolve_peers/tests.rs
  • pnpm/crates/resolving-deps-resolver/src/resolve_workspace.rs
  • pnpm/crates/resolving-deps-resolver/src/resolved_tree.rs

@qodo-code-review

qodo-code-review Bot commented Jul 29, 2026 •

Copy link
Copy Markdown

PR Code Suggestions ✨

Warning

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

CategorySuggestion                                                                                                                                    Impact
Possible issue
Prevent inverted-lock-order deadlocks

Modify provider_pkg_ids to fetch the required data from dependencies_tree before
locking packages. This avoids a lock order inversion that could cause deadlocks
with snapshot.

pnpm/crates/resolving-deps-resolver/src/resolve_dependency_tree.rs [1172-1179]

-let dependencies_tree = lock_recoverable(&self.dependencies_tree);
+let candidates: Vec<_> = {
+    let dependencies_tree = lock_recoverable(&self.dependencies_tree);
+    node_ids
+        .filter_map(|node_id| {
+            dependencies_tree
+                .get(node_id)
+                .map(|node| (node_id.clone(), node.resolved_package_id.clone()))
+        })
+        .collect()
+};
 let packages = lock_recoverable(&self.packages);
-node_ids
-    .filter_map(|node_id| {
-        let pkg_id = &dependencies_tree.get(node_id)?.resolved_package_id;
-        packages.contains_key(pkg_id).then(|| (node_id.clone(), pkg_id.clone()))
-    })
+candidates
+    .into_iter()
+    .filter(|(_, pkg_id)| packages.contains_key(pkg_id))
     .collect()

[To ensure code accuracy, apply this suggestion manually]

Suggestion importance[1-10]: 10

__

Why: This suggestion correctly identifies a critical lock inversion that can lead to deadlocks, and provides an effective solution to fix it.

High
Publish revisions after mutations

Move the ctx.workspace.bump_revision() call to the end of extend_tree or after
all mutations are committed. This ensures concurrent readers don't miss updates
due to an incorrectly synchronized revision check.

pnpm/crates/resolving-deps-resolver/src/resolve_dependency_tree.rs [1636]

+// Perform all shared workspace mutations first.
+...
 ctx.workspace.bump_revision();

[To ensure code accuracy, apply this suggestion manually]

Suggestion importance[1-10]: 10

__

Why: This suggestion identifies a critical race condition where early revision publishing can cause concurrent sync operations to miss subsequent updates, leading to a corrupted workspace state.

High
  • Update

zkochan and others added 2 commits July 29, 2026 16:50
…rewrite

A children-ownership handover rewrites existing occurrence nodes'
children in the shared context (make_non_owner_nodes_lazy), which the
discovery engine's incremental sync could not see: an owner re-recording
an equal child list re-points the children_by_id Arc without content
drift, leaving the engine walking realized children and cache verdicts
derived before the rewrite. Track such rewrites with a counter on the
workspace context and discard the engine's whole view when it advanced
since the last sync.

Also apply review nitpicks: release the dependencies_tree guard in
snapshot_reachable_from before taking packages so the function never
holds two context locks at once, use Arc::unwrap_or_clone for the
subtree-missing merge, cover the lazy-edge package closure of
snapshot_reachable_from with a test, and reword the changeset to stay
user-facing.

Co-Authored-By: Claude Fable 5 <[email protected]>
Copilot AI review requested due to automatic review settings July 29, 2026 14:54

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.

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

@zkochan

zkochan commented Jul 29, 2026

Copy link
Copy Markdown
Member Author

The review nitpicks are addressed in 14eb7da as well: snapshot_reachable_from now drops the dependencies_tree guard before taking packages (keeping a single lock-acquisition order file-wide), the subtree-missing merge uses Arc::unwrap_or_clone, and the lazy-edge package closure of snapshot_reachable_from is covered by a dedicated test.


Written by an agent (Claude Code, claude-fable-5).

@zkochan zkochan changed the title perf(resolver): reduce multi-importer full-resolution overhead perf(resolver): make multi-importer peer-hoist discovery linear Jul 29, 2026
@zkochan
zkochan enabled auto-merge July 29, 2026 14:55
@github-actions github-actions Bot added the reviewed: coderabbit CodeRabbit submitted an approving review label Jul 29, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants