Skip to content

12.17.0: hardlink import still stats each store file once before linking it (statx 1.86x vs 12.7.0 after #17502) #17543

Closed

Description

@jclaveau

Last pnpm version that worked

12.7.0

pnpm version

12.17.0

Code to reproduce the issue

Same setup as #17500: Linux x64, store and project on the same filesystem (hardlink import), default umask 0022, cold node_modules, offline install from a pre-filled store, vitest at da7ce17 with its packageManager pin removed.

git clone https://github.com/vitest-dev/vitest && cd vitest
git checkout da7ce1712fd4d0e4e807ec01ce755581e6892d5b
node -e 'const fs=require("fs");const m=JSON.parse(fs.readFileSync("package.json"));delete m.packageManager;fs.writeFileSync("package.json",JSON.stringify(m,null,2))'
printf '\nnodeLinker: hoisted\nstrictDepBuilds: false\n' >> pnpm-workspace.yaml

PNPM=./pnpm-12.17.0   # repeat with 12.7.0
$PNPM install --no-frozen-lockfile --store-dir="$PWD/../store"   # online: fill the store
find . -name node_modules -type d -prune -exec rm -rf {} +
strace -f -c -o counts.txt $PNPM install --frozen-lockfile --offline --store-dir="$PWD/../store"
grep statx counts.txt

Expected behavior

About the 12.7.0 count of statx calls. With verify-store-integrity on, the store verifier has already read the mode of every store file earlier in the same install, so linking should not need another stat.

Actual behavior

#17502 removed the repeated stats of a store file shared by several packages. It still stats every store file once before its first link, so a 12.17.0 install makes about 46k more statx calls than 12.7.0, and system CPU is 10-14% higher.

Released binaries from npm, an offline install of the same lockfile into a hot store, glibc runner, 10 rounds per arm, 3 replicates on separate runners. Calls are the median of 3 strace rounds; "12.17.0 (source)" is the v12.17.0 tag built from source, as a control for the npm binary:

arm statx calls (EPYC 7763 / 7763 / 9V74) vs 12.7.0 system CPU (7763 / 7763 / 9V74)
12.7.0 (npm) 53,891 / 53,892 / 53,890 1.00x 2.07 / 2.06 / 1.60 s
12.17.0 (npm) 100,074 / 100,049 / 100,046 1.86x 2.28 vs 2.07 s (1.10x) / 2.31 vs 2.06 s (1.12x) / 1.82 vs 1.60 s (1.13x)
12.17.0 (source) 100,045 / 100,058 / 100,051 1.86x 2.29 vs 2.07 s (1.11x) / 2.30 vs 2.06 s (1.12x) / 1.83 vs 1.60 s (1.14x)

linkat is 66,946 on every 12.17.0 arm, so the extra calls (about 0.69 per link) come from reading store file metadata, not from linking more files. Before #17502 the same setup read about 121k calls (2.25x).

Run: https://github.com/jclaveau/ci-prebuilds/actions/runs/41304468122

Additional information

The remaining call is source_has_desired_mode in pnpm/crates/deps-restorer/src/link_file/target_mode.rs: on its first sight of a store path it runs fs::metadata to decide whether the blob can be hardlinked as is. check_pkg_files_integrity already read that inode's mode a moment earlier in the same install, on all three of its paths (fast, re-stat, rehash).

A candidate fix is in my fork as a draft: jclaveau#3. It records the mode the verifier reads in a process-wide map keyed by store path, and drops the entry when a store file fails verification, since its re-fetch may land a new inode with another mode. source_has_desired_mode reads that map and stats only on a miss. On the run above it brings statx back to 54,248 / 54,263 / 54,263 calls (1.01x vs 12.7.0), and system CPU to 2.05 vs 2.07 s (0.99x) / 2.08 vs 2.06 s (1.01x) / 1.61 vs 1.60 s (1.00x).

The same draft PR also adds a syscall-count check to the integrated benchmark, because wall time did not catch the 12.8.0 regression: each extra warm-cache statx costs about a microsecond, so the extra calls stayed inside the comparison's 5% noise allowance. In the fork's CI, reverting #17502 on top of that check fails it with 12 statx rows at +2.7% to +7.3%, while the timing table reads "Within tolerance" (https://github.com/jclaveau/pnpm/actions/runs/41084341826).

I can open either part as a PR here if you want it.

Assisted-by: Claude:claude-opus-5-5

Node.js version

v24.22.2 (not involved: the native binary runs the install)

Operating System

Linux

Contributing a fix

  • I am working on a fix

Activity

  1. added a commit that references this issue on Nov 2, 2026
    9d24536
  2. added a commit that references this issue on Nov 10, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions