Repository navigation
[pull] main from pnpm:main - #467
Merged
Merged
Conversation
…tial phases (#13564) 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.
…omLockfile remap (#13563) `remap_link_node_id` compared `lockfile_dir` against the link's `directory` verbatim, but a workspace link records that directory relative to the importer that declares it, so the lexical containment check never matched and every internal link was remapped to `link:<modules_dir>/<alias>` — feeding peer resolution a node id that should only stand in for links living outside the workspace. The lockfile then recorded the peer as `link:node_modules/<alias>`, a path relative to the lockfile root rather than to the importer that holds the symlink. Resolve the target against `project_dir` before the containment check, and thread each importer's root into `ResolvePeersOptions::project_dir` in the multi-importer walk (it already threads `modules_dir`). The same check also caught injected (`file:`) workspace dependencies, whose directory is relative to the lockfile dir. Upstream only remaps linked dependencies (`isLocal`, i.e. a non-`file:` directory resolution), so gate the remap on a `link:` id. The TypeScript CLI is unaffected — its directory resolutions for links are absolute — so it only gains the mirror test. Closes #13556
… focused modules (#13562) resolve_dependency_tree.rs carried the public options/error types, the shared workspace context, the per-importer tree context, the recursive walk, node reuse and children-ownership bookkeeping, lockfile-snapshot reuse checks, catalog specifier resolution, and manifest extraction in one 4,037-line file. Keep resolve_dependency_tree.rs as the facade holding the options, error, and notification types plus the two entry points, and move the implementation into resolve_dependency_tree/: workspace_ctx.rs (WorkspaceTreeCtx, the shared per-pkgIdWithPatchHash dedup maps, and the children-ownership claim/handover), tree_ctx.rs (TreeCtx and the per-edge ResolveOptions derivations), walk.rs (the fresh-resolve walk — seed, children walk, per-wanted resolve cache, level folds), reuse.rs (ReuseSource, the update scope, direct-dep change bookkeeping, subtree-reuse predicates, and the snapshot-driven walk), manifest.rs (what the walk reads off a resolved package: pkg id, child specs, peers, leaf classification, deprecation), and catalogs.rs (catalog: specifier resolution). TreeCtx and WorkspaceTreeCtx stay one struct each; their inherent impls are divided across the modules with pub(super) visibility, so every cross-module item stays private to resolve_dependency_tree and the crate's public API is unchanged. The pub(super) surface was derived mechanically: every marker was stripped and the compiler re-added only the ones the crate cannot compile without. The unit tests that drive one module's internals move next to it, with the shared result builder lifted into a test_support module; the end-to-end tree-walk tests stay at the facade. Pure code movement: no behavior, allocation, cloning, dispatch, or traversal change. After normalizing away imports, module declarations, visibility markers, and reference-style doc links, the multiset of source lines before and after differs only by the eleven signatures rustfmt re-wrapped because pub(super) pushed them past the width. Closes #13554.
…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.
Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
…t key (#13568) The peer-resolution passes sort `NodeId`s so their output does not depend on hash iteration order. The comparison key was a freshly formatted `String` per element — `"0:{value:020}"` for a counter, `"1:{id}"` for a leaf — and `sort_by_key` re-invokes the key function on every comparison, so each sort allocated `O(n log n)` strings. `build_final_dep_paths` and the Tarjan pass under it run those sorts over every node that resolved a peer, plus one sorted successor list per node. Derive `Ord` on `NodeId` instead and sort the values directly. The derived order is the same total order the rendered keys encoded: the variant order puts counters before leaves, a fixed-width zero-padded u64 compares like the number it renders, and leaf ids compare as their `str` either way. The resolved graph is unchanged. On the 114-project Bit workspace from https://github.com/pnpm/pnpm/issues/13505, resolution drops from ~16.0s to ~13.4s, with the final depPath pass falling from 2.50s to 0.76s. The peer-heavy `workspace_full_resolution` benchmark goes from ~1.01s to ~0.85s.
…om the settled tree (#13570) The peer-hoist pickers biased toward preferred_versions_from_run, an arrival-ordered workspace-wide fold written by every walk. Concurrent importer waves can transiently win a children-ownership claim, walk a subtree, and lose the context to a deterministically better-placed occurrence; whether that transient walk (and its version folds) happens depends on thread interleaving, so the fold's membership — and the hoisted peer picks, and every peer suffix downstream — varied run to run, rewriting pnpm-lock.yaml on every install of identical inputs. Derive the pickers' candidates from the settled reachable tree instead: WorkspaceTreeCtx::run_preferred_versions walks children_by_id (which only ever holds the deterministic children owner's records) from the recorded importer-level direct deps and folds each reachable package's identity. The closure is cached, grown incrementally per revision, and rebuilt when a children-ownership rewrite restructures existing subtrees. workspace:-surfaced project versions keep their fold via a per-package identity record, also reachability-gated. This matches the TS resolver, where allPreferredVersions ends up equal to the set reachable through its arrival-ordered dedup because it is single-threaded. The concurrent init waves stay concurrent. Closes #13567
…he adversarial interleaving (#13572) The optional- and required-peer hoists read the same run-resolved candidate set but pick differently, so the transient-walk regression scenario from #13567 is now asserted through both pickers: the required-peer variant pins that an unreachable transiently-walked version must not win the dedupe-onto-highest-satisfying pick. Verified to fail against the pre-pnpm/pnpm#13570 resolver with the exact symptom (host suffixed with the unreachable pin). The shared fixture is extracted into a resolve_with_transient_shared_walk driver. Related to #13567.
…og (#13571) The peer-hoist discovery engine keeps one view of the workspace context across every hoist round, refreshing it before each pass. That refresh walked all three shared maps end to end — `children_by_id`, `packages`, `dependencies_tree` — so every round cost one scan of the whole workspace even when the round had added a handful of nodes. A resolve of the 114-project Bit workspace from https://github.com/pnpm/pnpm/issues/13505 runs 172 of those syncs in the initial rounds alone, and each `extend_tree` bumps the revision that triggers them. Have the context record which keys of those maps each write touched, and sync by visiting the keys written since the view's cursor. Only keys are recorded, never values: the sync reads each key's current value, so a key written several times, or written by concurrently-walking importers in either order, converges on the same view. A view discarded after an unmergeable change (a children-owner handover that re-split a package's children and peers) refills itself by scanning the shared maps once, rather than replaying the log, which would copy every key twice. Neither existing scenario of the `workspace_full_resolution` benchmark runs the auto-install-peers loop — the peer-heavy one provides every importer's peers up front, so it converges in one round with a single sync and measures identically here — so add a hoist-heavy scenario where the peers are missing and the importers' direct sets differ. That scenario runs 7.68/7.32/7.31s on main against 7.33/6.78/6.67s here. On that workspace the initial rounds' sync time drops from 683ms to 215ms — the remainder is the three rebuilds, which replay the log — and the hoist loop's from 30ms to 0.3ms, taking the two phases from 3.78s + 1.28s to 2.79s + 1.03s. Related to https://github.com/pnpm/pnpm/issues/13505.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
See Commits and Changes for more details.
Created by
pull[bot] (v2.0.0-alpha.4)
Can you help keep this open source service alive? 💖 Please sponsor : )