Skip to content

Hoisted linker blows up on dense peer-variant graphs since peer variants keep distinct hoister references #323

Done

Description

@zkochan

Problem

nodeLinker: hoisted never finishes on https://github.com/jamenh/synthesized-giant-monorepo, a public repro that mirrors a large Atlassian monorepo (warm store, empty node_modules). The process grows past 25 GB RSS and is killed. Nothing is written to disk. The time goes into the hoisting algorithm in pnpm/crates/real-hoist.

The isolated linker on the same lockfile finishes in about 57s, so this is specific to hoisting.

Measurements

Running real-hoist directly on the lockfile filtered to the 2,310 benchmarked importers (M1 Max, instrumented build):

  • 34M+ decouple_child copies before I stopped it, with tree depth around 30.
  • About 33M of the absorb decisions are Conflict between two peer variants of the same name@version, for example two snapshots of one @atlaskit/* version that differ only in which react / @types/react line satisfies their peers.
  • The repo has 1,518 such peer-variant snapshots (8,395 snapshots for 6,877 distinct name@version).

Cause

pnpm/pnpm#17397 (fix(hoist): preserve peer variants in workspaces) makes a peer-bearing node keep its own snapshot key as its hoister reference. The TypeScript v11 getHoisterPkgId collapses every registry variant to name@version. With distinct references, two variants can never share a hoisted position, so each conflict decouples a subtree copy. On a dense peer graph the copies multiply at every level.

What a fix needs

A rule for when two peer variants are interchangeable at a given position: both resolve every peer to the same physical package from that position. The hoister would then treat them as one reference there and keep them distinct only where their peers really differ. That keeps the correctness fix of pnpm/pnpm#17397 without the blow-up.

Repro

  1. Clone the repo above and run ./bench.sh once to populate the caches.
  2. Set nodeLinker: hoisted and run pnpm install --frozen-lockfile --offline with an empty node_modules.
  3. Watch RSS grow without the install reaching the link phase.

Related: the isolated-linker part of the same report is answered by enableGlobalVirtualStore (warm install 11-13s vs Yarn ~50s on this machine).


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

Activity

  1. self-assigned this
    on Nov 21, 2026
  2. zkochan commented on Nov 21, 2026

    @zkochan
    MemberAuthor

    For the isolated-linker side of the same report: pnpm/pnpm#18294 keys the macOS dir-clone cache by package content, so peer variants share one cached copy. The reporter measured -14% to -19% on this repro. It does not change the hoisted problem described here.


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

  3. zkochan commented on Nov 21, 2026

    @zkochan
    MemberAuthor

    Draft fix: pnpm/pnpm#18303. Root cause: the Rust hoister never ported upstream's peer ordering (getSortedRegularDependencies, Hoistable.DEPENDS), and its own peer check refused dedups and re-walked refused copies per path. The PR ports upstream's algorithm and adds a post-hoist repair for pnpm peer shapes outside Yarn's model (alias-bound and transitive peers). The synthesized monorepo now hoists in 2.9 s at 524 MB, against 25+ GB and no result before.


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

  4. kairosci commented on Nov 26, 2026

    @kairosci

    Resolved by pnpm/pnpm#18303, merged as 691d13b136.

    The hoister now shares one identity across compatible peer variants without cross-linking them, ports upstream peer ordering, and repairs remaining peer bindings after hoisting. The synthesized monorepo now hoists in seconds at hundreds of megabytes, and the PR is green on main. The remaining notes in its description are follow-ups, not blockers for this issue.


    Written by an agent (Big Pickle, big-pickle).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions