Repository navigation
Description
Summary
On a large bit.cloud workspace (114 importers, ~25k graph nodes, ~21k lockfile snapshots — ~/src/sandbox/opus-5), a resolving install spends ~54 of ~63 engine seconds inside the peer-resolution machinery, single-threaded, with no progress output — users see the install "hang" for a minute. Tree resolution, fetching, and linking are all fine.
Phase budget (resolution-only replay via @pnpm/napi with lockfileOnly: true, phase timers around resolve_workspace):
| phase | time |
|---|---|
| importer tree inits | 3.5 s |
| prepare initial hoist rounds | 5.1 s |
| complete initial hoist rounds | 14–19 s |
| optional/required hoist loop | 4–15 s |
| merged-tree snapshot | 0.6–3 s |
| final peer pass | 13.5 s |
Measured structure
- 802
PeerHoistDiscovery::discoverwalks per install: 114 importers × ~7 hoist-loop rounds, plus per-importer fixpoint iterations. Every walk re-covers the importer's whole direct forest. - 2.6M
resolve_nodevisits for a ~25k-node graph (977k pure-pkg fast-path hits, 1.3M peers-cache hits, 316k fresh walks) — ~100× amplification, ~29 µs/visit. - ~250 children-ownership rewrites fire mid-hoist: importer-level hoisted peers claim package children at depth 0 and outrank deeper owners (
ChildrenOwnerranks by(depth, importer_order, parent_path)), each transfer runsmake_non_owner_nodes_lazy+record_children_rewrite, which invalidates the discovery engine's tree view and caches — forcing everyone back to full walks. - Leaf-level sampling (
eu-stackon a debuginfo build): SipHash over ~50-charString/NodeId::Leaf(Arc<str>)keys and malloc/free churn dominate; the walker's maps are all default-hasherstd::collections.
Optimizations prototyped (bisected with env kill-switches; work stashed on branch perf-opus5)
Combined effect: 77 s → 43.6 s. Each one individually changes some peer-variant bindings in the emitted lockfile (e.g. a [email protected] suffix flipping to 5.9.3, ±42 snapshots) — all still-valid resolutions, but the exhaustive re-walks turn out to be load-bearing for byte-determinism today:
- Convergence gate — skip
run_required_roundfor an importer whose previous round ended with no missing required peers (inputs unchanged since). Drift source: owner-scope suppression maps and the preferred-versions fold evolve between rounds. - Incremental discovery — walk only the direct deps added since the importer's last walk (full direct set retained as the importer-parent provider context), accumulating scope-filtered missing reports.
- Ownership-rewrite gating — skip the lazy-flip/cache-invalidation when the displaced owner's
peer_shadowedset equals the claimant's. Unsound as formulated: child NodeId occurrence identity feeds peer-variant computation, so equal shadow context does not imply identical children at the NodeId level.
Paths forward
- Fast hasher (
rustc-hash/ahash) for the resolver-internal maps — byte-identical by construction, targets the dominant leaf cost across every peer phase. - Harden the three structural gates above, accepting a one-time bound-but-valid binding shift (or designing exact replay of the order-sensitive folds).
- Parallelize per-importer discovery and the final peer pass (single-threaded today; the walker owns a shared mutable tree + caches).
- Emit a progress/stage event during the peer phase so the reporter shows activity (the "hang" perception), pending TS emission-parity check.
Repro
rm -rf node_modules pnpm-lock.yaml && bd install in the bit.cloud workspace, or resolution-only: dump bit's installOptions via a probe in @teambit/pnpm's lynx.js and call napi.install({...opts, lockfileOnly: true}) directly (~80 s, no linking).
Written by an agent (Claude Code, claude-fable-5).
Activity
github-actions commentedon Jul 30, 2026
Automated Oz triage is running now. It will classify this issue against the implementation-readiness states — Ready to implement, Ready to spec, Needs info, or Wait to implement — and apply the matching pnpm
state:label.Follow along in Oz: https://oz.warp.dev/runs/019fb3db-063e-7946-851b-875b7b722c7b
Written by an agent (Oz, auto).
github-actions commentedon Jul 30, 2026
Triage result
Ready to specstate: needs designpnpm/crates/resolving-deps-resolver/src/resolve_peers.rs,resolve_importer.rs,resolve_dependency_tree.rs);PeerHoistDiscovery::discover,ChildrenOwner,make_non_owner_nodes_lazy, andrecord_children_rewriteall exist there. This is internal resolution machinery, not shared with the TypeScript CLI's own peer resolver, so no directinstall/add/update/removeparity change is mandated — with one caveat: the proposed peer-phase progress/stage event is explicitly "pending TS emission-parity check," and any accepted optimization that shifts emitted peer-variant bindings would change lockfile bytes.Needs infoorWait to implement. But it is not a bounded one-pass fix either: the issue is a profiling writeup with several competing "paths forward" whose trade-offs are unresolved. The three structural gates each perturb byte-determinism (one is called out as "unsound as formulated"), the fast-hasher swap is safe but only part of the win, and parallelizing the walker requires restructuring today's shared mutable tree + caches. Confirmed against the checkout: no fast hasher (rustc-hash/ahash/FxHashMap) is used anywhere in the Rust stack yet, so that avenue is genuinely open. Choosing which paths to pursue and how to preserve exact lockfile output is a design decision.Written by an agent (Oz, auto).
zkochan commentedon Jul 30, 2026
First installment: pnpm/pnpm#13506 lands the convergence gate, incremental discovery, ownership-handover rewrite gating, and an FxHash swap for the resolver-internal maps — resolution on the reference workspace drops from ~77 s to ~36 s (cold-install engine time 2 min → 1 min), with all 7,495 workspace tests passing. Peer bindings can shift once to a different still-range-valid provider; output is deterministic across runs.
Remaining toward the sub-5 s target, in expected-leverage order:
Written by an agent (Claude Code, claude-fable-5).
perf(resolver): cut large-workspace peer resolution roughly in half (#…
zkochan commentedon Aug 1, 2026
Third installment: pnpm/pnpm#13568 removes the allocating
NodeIdsort key. Re-profiling the reference workspace first (resolution-only replay, 114 importers, warm cache, offline) showed the phase budget has moved a lot since this issue was filed — the whole resolution now runs ~16s, of which the peer machinery is ~10.5s:extend_treefor the hoisted peers)build_final_dep_paths, 1.5–2.3s walk, 0.3s graph rebuild)The surprise was
build_final_dep_paths: 2.5s of the final pass went into sorting, not peer matching. The passes sortNodeIds for determinism, and the key was a formattedStringper element, re-rendered on every comparison bysort_by_key. DerivingOrdand sorting the values drops it to 0.76s (SCC pass 1.10s → 0.12s), taking the whole resolution to ~13.4s and the peer-heavyworkspace_full_resolutionbenchmark from ~1.01s to ~0.85s.Remaining toward the sub-5s target, unchanged in order:
Separately, while trying to use lockfile byte-identity as the regression gate for that PR, I found that
mainis not run-to-run deterministic on this workspace: two consecutive replays of the same binary, same input lockfile,offline: true, emit different peer bindings. Filed as pnpm/pnpm#13567 — it also means byte-comparison can't currently gate resolver changes on a workspace of this shape.Written by an agent (Claude Code, claude-opus-5).
perf(resolving-deps-resolver): order node ids without rendering a sor…
chore(resolving-deps-resolver): drop a stray patch backup file
perf(resolving-deps-resolver): rebuild the discovery view by scanning
refactor(resolving-deps-resolver): set the rebuilt view's cursor in p…
perf(resolving-deps-resolver): sync the discovery view from a write log
test(resolving-deps-resolver): pin the synced view's contents
chore(resolving-deps-resolver): drop a stray patch backup file
perf(resolving-deps-resolver): rebuild the discovery view by scanning
2 remaining items
test(resolving-deps-resolver): add a hoist-heavy resolution benchmark
zkochan commentedon Aug 1, 2026
Correction to my measurement of pnpm/pnpm#13568, and a benchmark gap worth knowing about.
The end-to-end figure I quoted for the
NodeIdsort-key change — "~16.0s → ~13.4s" on the reference workspace — was not measured cleanly: the 16.0s baseline runs restored the inputpnpm-lock.yamland ranoffline: true, while several of the 13.4s runs did not. Comparing across protocols like that is worth nothing, and I should not have quoted it. What does hold up for that PR:workspace_full_resolutionpeer-heavy scenario, a clean A/B at the time: 1.00/1.02/1.01s → 0.852/0.856/0.840s (~16%). Today'smain, which contains it, measures ~850ms on that scenario, which is consistent;build_final_dep_paths2.50s → 0.76s, of which the Tarjan pass is 1.10s → 0.12s.The CI integrated benchmark did not demonstrate that change either, and I described its output more favourably than it deserved.
The gap: neither existing scenario of
workspace_full_resolutionruns the auto-install-peers loop at all. The peer-heavy one hands every importer all the framework packages up front, so no peer is ever missing, the loop converges in one round, and the workspace context is synced exactly once. Anything that changes the cost of a hoist round is invisible to it — I confirmed this by A/B-ing pnpm/pnpm#13571 on it: ~850ms on main and on the branch alike, over 6 interleaved runs. The CI integrated benchmark's peer-heavy scenario is the same fixture shape, plus end-to-end install noise of ±0.4s on a ~1.7s mean.pnpm/pnpm#13571 therefore adds a third scenario — peers not provided by the importers, and each importer declaring a different subset of roots, so the hoist loop really runs. It costs ~8x the peer-heavy one (6.9s vs 0.9s) because that loop dominates it, and it separates the two builds cleanly: main 7.68/7.32/7.31s vs branch 7.33/6.78/6.67s, every pair favouring the branch.
Anyone measuring the remaining items on this issue (parallelizing the peer phase, the children-rewrite re-walks) should use that scenario rather than the peer-heavy one or the integrated benchmark.
Written by an agent (Claude Code, claude-opus-5).
perf(resolving-deps-resolver): sync the discovery view from a write l…
test(micro-benchmark): gate multi-importer workspace resolution in CI
test(micro-benchmark): gate multi-importer workspace resolution in CI (…
perf(resolving-deps-resolver): amortize the per-importer workspace sc…
zkochan commentedon Aug 2, 2026
Fourth installment: pnpm/pnpm#13579 (the amortizations) and pnpm/pnpm#13581 (a benchmark that can see them).
Re-profiling first, because the budget in the issue body predates pnpm/pnpm#13571 and pnpm/pnpm#13575 and no longer holds. On the hoist-heavy resolution fixture (331 importers, 5,030 packages),
mainat 5644b55356 spent:The final peer pass — one of the two parallelization targets listed above — is 6% of the resolve today. The two items above it were both per-importer rescans of the whole workspace, and both came out byte-identically, with no threads added and peak memory down:
first_importer_by_pkg/first_walk_missing_by_pkgnow carries theArcsnapshot last projected from it, handed out until a write invalidates it; the writers that usually change nothing test first.Arc-shared subtree summaries instead of flattening them into an ownedpkg id → namesmap for one consumer to read and drop — 1.6M entries built and freed per wave.6.7s → 1.50s (4.4x). Neutral on the 114-importer bit.cloud workspace (10.48 → 10.19s): its importers mostly have their peers provided, so its per-round maps are small. The win needs many importers and many packages.
The measurement problem, and the fix. Nothing in CI could see any of this. The integrated benchmark's scenarios all converge in one hoist round, and a 40-importer hoist-heavy scenario I built for it measured 820.6ms vs 819.0ms across this very change — a gate that cannot fail. pnpm/pnpm#13581 therefore moved the fixture into the micro-benchmark task, which already builds both sides of a PR and posts their comparison. CI now reports, on its own hardware:
±0.62ms on 244ms — 0.4% variance, against 17–27% for the end-to-end scenario. Anything that reintroduces this cost shows up in that table.
Remaining, in expected-leverage order:
Anyone measuring either should use
workspace_resolution/hoist_heavy(or--full-workspace-resolutionlocally); note that lockfile byte-identity still cannot gate resolver changes on a large workspace, per pnpm/pnpm#13567, which I reopened with fresh numbers.Written by an agent (Claude Code, claude-opus-5).
perf(resolving-deps-resolver): answer the hoist scope's ancestor quer…
perf(resolving-deps-resolver): derive each package's name once for th…
perf(resolving-deps-resolver): derive each package's name once for th…
zkochan commentedon Aug 2, 2026
Note for anyone picking up the remaining items here: lockfile byte-identity now works as a regression gate. pnpm/pnpm#13594 made resolution deterministic (8 consecutive replays of the 114-importer workspace byte-identical, where before almost every pair differed), so a resolver change can be verified by comparing emitted lockfiles rather than by arguing equivalence from the code. Several earlier comments on this issue say the opposite; they are obsolete.
It also removed ~1s from that workspace's resolve (10.2-10.4s to 9.2-9.5s), because the importer races it eliminated were costing redundant subtree walks.
Remaining, with the fixture caveat that cost me a day here. The synthetic
workspace_resolutionfixtures and a real workspace disagree completely on resolver internals — 0 tree materializations vs 419,043, 0 multi-item cache buckets vs 90% of lookups, walks at 31% of the resolve vs ~63%. I scoped the walk parallelization as feasible from fixture numbers and had to retract every part of it after measuring the real workspace. Measure there first.Two avenues measured and closed since the last installment: scoping the children-rewrite invalidation (only 41 of 139 forced-full walks touch nothing rewritten, and preserving caches across a rewrite measured slower), and importer inits (96% of it is the tree walk, already concurrent within an importer).
Written by an agent (Claude Code, claude-opus-5).
zkochan commentedon Aug 3, 2026
Measured the parallelization item properly, and I would close it as not worth doing in its current form.
Where the time is (114-importer workspace, ~9.6s resolution replay on
641ccd3df4):Why each candidate fails:
build_final_graph(0.3s) — 82% of it is a single order-dependent build loop (173ms of 211ms on the real workspace, and the same ratio on the fixture). Parallelizing the two folds around it saves ~38ms, 0.4%.build_final_dep_paths(0.6s) — a memoized DFS through dependency chains; sequential by construction.extend_treeresolves siblings in parallel at every level. Only the cross-importer fan-out was removed, deliberately, by 13594.Total safe parallel gain: under 1%.
What would actually unlock the walks is making cached verdicts canonical rather than first-writer-wins, so that concurrent cache writes cannot change the result. That is a redesign of the peers cache, not a parallelization pass, and it should be justified on its own terms rather than as a perf item.
The remaining item on this issue is the progress/stage events during the peer phase, pending the TypeScript emission-parity check.
Written by an agent (Claude Code, claude-opus-5).
zkochan commentedon Nov 8, 2026
Status check against main (2026-11-08).
The 77 s budget in the body is obsolete: peer resolution fell to about 9.6 s through pnpm/pnpm#13506, pnpm/pnpm#13568, pnpm/pnpm#13579 and pnpm/pnpm#13594, and the comments here rule out parallelizing it.
Left: progress or stage events during the peer phase. The reporter has none yet.
Written by an agent (Claude Code, claude-opus-5-5).