Repository navigation
Conversation
…links pnpm#17502 stopped the hardlink mode check from stat'ing a store file once per link, but it still stats each file once before its first link. The store verifier has read the same inode's mode a moment earlier in the same install, so an offline install of a large workspace still makes about 100k `statx` calls, against 54k in 12.7.0 (pnpm#17500). `pnpm_fs::file_mode` now keeps a process-wide map from store path to the mode last read for it. The verifier records the mode of each file it passes, and `source_has_desired_mode` reads the map before falling back to one read of its own, which it then records too. This replaces the set of linkable paths from pnpm#17502. A warm store with verify-store-integrity on goes back to one stat per blob, the 12.7.0 count; with it off, each blob is still stat'ed only once however many packages link it. The mode comparison itself is unchanged. The map is process-global because the verifier and the importer run in different install-scoped contexts, the same reason the CAS write locks live in `pnpm_fs`. Threading the mode down to `import_indexed_dir` instead would change the `FilesMap` shape at a dozen call sites across five crates. Unlike the set it replaces, a mismatched mode is remembered too: such an entry keeps being copied, now without a re-stat. A blob rewritten by another process under a different umask after this process first read it is noticed only by the next process. Assisted-by: Claude:claude-opus-5-5
jclaveau
force-pushed
the
fix/hardlink-mode-check-per-source
branch
from
October 30, 2026 14:53
aba197a to
2221b90
Compare
Owner
Author
|
Superseded by #3, which carries this commit together with the round-2 review fixes. Assisted-by: Claude:claude-opus-5-5 |
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 join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Summary
Follow-up to pnpm#17502 for pnpm#17500: closes the remaining
statxgap.pnpm#17502 caches a linkable answer per store path, so a store file shared by several packages is no longer stat'ed once per link. It still stats every store file once before its first link, though the store verifier (
check_pkg_files_integrity) read that same inode's mode a moment earlier in the same install. On the vitest fixture that leaves 100kstatxcalls, against 54k in 12.7.0 (run below).This PR replaces the
DashSet<PathBuf>of linkable paths intarget_mode.rswith a process-wide map from store path to inode mode, kept inpnpm_fs::file_mode:source_has_desired_modereads the map first. On a miss it reads the mode once (fs::metadataon unix,copy_permissionson wasi) and records it.store_inode_mode_is_linkableis unchanged, so the umask issue pnpm/pnpm#3807 semantics are unchanged.dashmap.The result:
Why process-global. The verifier and the importer run in different install-scoped contexts. The CAS write locks live in
pnpm_fsfor the same reason. Threading the mode down toimport_indexed_dirinstead would change theFilesMapshape at about a dozen call sites across deps-restorer, package-manager, cli, env-installer and python-installer.Trade-offs:
@pnpm/napiembedder the map holds onePathBuf+u32per distinct store file read.v11 is not affected.
Tests
hardlink_uses_the_mode_the_verifier_recorded(deps-restorer, new): it records the desired mode, sets the file's real mode off it, then links. The link must share the inode, because the recorded mode was used without a stat.careful_path_records_the_mode_of_a_verified_file(store-dir, new): a verified pass records the blob's mode.hardlink_reuses_a_store_entry_mode_check(from perf(deps-restorer): stat a store file once for the hardlink mode check pnpm/pnpm#17502): kept as is, and still passes.target_mode.rs,check_pkg_files_integrity.rs, the deps-restorerCargo.tomlandCargo.lockrestored from main 896dc10 make both new tests fail, while the perf(deps-restorer): stat a store file once for the hardlink mode check pnpm/pnpm#17502 test passes.cargo test:-p pnpm-deps-restorer: 672 passed.-p pnpm-store-dir: 245 + 2 passed.-p pnpm-fs: 212 passed. 2secure_temp_lockXDG tests fail the same way on the base commit, because of the local sandbox environment.cargo clippy --all-targets -- -D warningsis clean on the three crates.Measurement
Offline frozen
pnpm installof the vitest fixture (da7ce171, 66,952 linked files) on a warm store. All arms run on the same Ubuntu image, interleaved, with medians over n=10 rounds per runner and cgroup CPU.patchedis this change on its pre-pnpm/pnpm#17502 base (f4a1e8c).pr17502is b96f423 andbaseis 4cb926c. The source arms are glibccargo build --release -p pnpm-clibuilds made the same way, and 12.7.0 is the registry binary. Each cell isarm vs 12.7.0.Run 40981503781:
pnpm#17502 recovers 21k of the 67k extra
statxcalls. Its user time rose about as much as its sys time fell, so its user+sys is no better than base. This change bringsstatxback to the 12.7.0 count and sys to 0.99-1.04x. Its user time is also up 0.01-0.05 s against base, from the map lookups.This branch vs post-pnpm/pnpm#17502 main vs 12.7.0
Run 41075659469:
followup= this branch (2221b90),main= 896dc10 (contains 63be32b), both built from source with the same flags. Offline warm-store install of vitest@da7ce17 (66,954 files), medians over 10 interleaved rounds, 3 runners.On main, pnpm#17502 still issues about 46k extra
statxper install, one per store file on its first link. This branch removes them, because the store verifier has already read those modes. User time is 0.01-0.02 s above main, from the map lookups.linkatis identical across the source-built arms (66,946).Assisted-by: Claude:claude-opus-5-5