Skip to content

perf(deps-restorer): reuse the store verifier's mode reading for hardlinks - #1

Closed
jclaveau wants to merge 1 commit into
mainfrom
fix/hardlink-mode-check-per-source
Closed

jclaveau wants to merge 1 commit into
mainfrom
fix/hardlink-mode-check-per-source

Conversation

@jclaveau

@jclaveau jclaveau commented Oct 30, 2026 •

Copy link
Copy Markdown
Owner

Summary

Follow-up to pnpm#17502 for pnpm#17500: closes the remaining statx gap.

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 100k statx calls, against 54k in 12.7.0 (run below).

This PR replaces the DashSet<PathBuf> of linkable paths in target_mode.rs with a process-wide map from store path to inode mode, kept in pnpm_fs::file_mode:

  • The verifier records the mode of every file it passes: the fast path, the re-stat path and the rehash path.
  • source_has_desired_mode reads the map first. On a miss it reads the mode once (fs::metadata on unix, copy_permissions on wasi) and records it.
  • store_inode_mode_is_linkable is unchanged, so the umask issue pnpm/pnpm#3807 semantics are unchanged.
  • deps-restorer no longer depends on dashmap.

The result:

Why process-global. The verifier and the importer run in different install-scoped contexts. The CAS write locks live in pnpm_fs for the same reason. Threading the mode down to import_indexed_dir instead would change the FilesMap shape at about a dozen call sites across deps-restorer, package-manager, cli, env-installer and python-installer.

Trade-offs:

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.
  • Red: target_mode.rs, check_pkg_files_integrity.rs, the deps-restorer Cargo.toml and Cargo.lock restored 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.
  • Green: with the fix, all three pass.
  • cargo test:
    • -p pnpm-deps-restorer: 672 passed.
    • -p pnpm-store-dir: 245 + 2 passed.
    • -p pnpm-fs: 212 passed. 2 secure_temp_lock XDG tests fail the same way on the base commit, because of the local sandbox environment.
  • cargo clippy --all-targets -- -D warnings is clean on the three crates.

Measurement

Offline frozen pnpm install of 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. patched is this change on its pre-pnpm/pnpm#17502 base (f4a1e8c). pr17502 is b96f423 and base is 4cb926c. The source arms are glibc cargo build --release -p pnpm-cli builds made the same way, and 12.7.0 is the registry binary. Each cell is arm vs 12.7.0.

Run 40981503781:

runner arm statx sys user user+sys
EPYC 7763 patched 54,276 vs 53,886 (1.01x) 2.07 vs 2.09 s (0.99x) 0.86 vs 0.81 s (1.06x) 2.93 vs 2.90 s (1.01x)
EPYC 7763 pr17502 100,057 vs 53,886 (1.86x) 2.34 vs 2.09 s (1.12x) 0.91 vs 0.81 s (1.12x) 3.25 vs 2.90 s (1.12x)
EPYC 7763 base 121,177 vs 53,886 (2.25x) 2.41 vs 2.09 s (1.15x) 0.81 vs 0.81 s (1.00x) 3.22 vs 2.90 s (1.11x)
Xeon 8573C patched 54,276 vs 53,888 (1.01x) 1.26 vs 1.21 s (1.04x) 0.79 vs 0.78 s (1.01x) 2.05 vs 1.99 s (1.03x)
Xeon 8573C pr17502 100,016 vs 53,888 (1.86x) 1.38 vs 1.21 s (1.14x) 0.81 vs 0.78 s (1.04x) 2.19 vs 1.99 s (1.10x)
Xeon 8573C base 121,181 vs 53,888 (2.25x) 1.43 vs 1.21 s (1.18x) 0.73 vs 0.78 s (0.94x) 2.16 vs 1.99 s (1.09x)
EPYC 7763 patched 54,276 vs 53,885 (1.01x) 2.05 vs 2.02 s (1.02x) 0.82 vs 0.78 s (1.05x) 2.87 vs 2.80 s (1.03x)
EPYC 7763 pr17502 100,057 vs 53,885 (1.86x) 2.26 vs 2.02 s (1.12x) 0.88 vs 0.78 s (1.13x) 3.14 vs 2.80 s (1.12x)
EPYC 7763 base 121,176 vs 53,885 (2.25x) 2.34 vs 2.02 s (1.16x) 0.77 vs 0.78 s (0.99x) 3.11 vs 2.80 s (1.11x)

pnpm#17502 recovers 21k of the 67k extra statx calls. Its user time rose about as much as its sys time fell, so its user+sys is no better than base. This change brings statx back 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.

CPU arm statx sys user user+sys
EPYC 9V45 followup vs 12.7.0 54,251 vs 53,885 calls (1.01x) 1.42 vs 1.42 s (1.00x) 0.55 vs 0.48 s (1.14x) 1.97 vs 1.90 s (1.04x)
EPYC 9V45 main vs 12.7.0 100,215 vs 53,885 calls (1.86x) 1.58 vs 1.42 s (1.12x) 0.54 vs 0.48 s (1.12x) 2.12 vs 1.90 s (1.12x)
EPYC 9V45 followup vs main 54,251 vs 100,215 calls (0.54x) 1.42 vs 1.58 s (0.90x) 0.55 vs 0.54 s (1.02x) 1.97 vs 2.12 s (0.93x)
EPYC 9V45 (2nd) followup vs 12.7.0 54,256 vs 53,885 calls (1.01x) 1.51 vs 1.50 s (1.01x) 0.62 vs 0.58 s (1.07x) 2.13 vs 2.08 s (1.02x)
EPYC 9V45 (2nd) main vs 12.7.0 100,153 vs 53,885 calls (1.86x) 1.68 vs 1.50 s (1.12x) 0.61 vs 0.58 s (1.05x) 2.29 vs 2.08 s (1.10x)
EPYC 9V45 (2nd) followup vs main 54,256 vs 100,153 calls (0.54x) 1.51 vs 1.68 s (0.90x) 0.62 vs 0.61 s (1.02x) 2.13 vs 2.29 s (0.93x)
Xeon 8573C followup vs 12.7.0 54,247 vs 53,893 calls (1.01x) 1.28 vs 1.23 s (1.04x) 0.87 vs 0.84 s (1.05x) 2.15 vs 2.07 s (1.04x)
Xeon 8573C main vs 12.7.0 100,015 vs 53,893 calls (1.86x) 1.39 vs 1.23 s (1.13x) 0.85 vs 0.84 s (1.02x) 2.24 vs 2.07 s (1.08x)
Xeon 8573C followup vs main 54,247 vs 100,015 calls (0.54x) 1.28 vs 1.39 s (0.92x) 0.87 vs 0.85 s (1.02x) 2.15 vs 2.24 s (0.96x)

On main, pnpm#17502 still issues about 46k extra statx per 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. linkat is identical across the source-built arms (66,946).


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

…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
jclaveau force-pushed the fix/hardlink-mode-check-per-source branch from aba197a to 2221b90 Compare October 30, 2026 14:53
@jclaveau jclaveau changed the title perf(deps-restorer): read a store file's mode once per process perf(deps-restorer): reuse the store verifier's mode reading for hardlinks Oct 30, 2026
@jclaveau

jclaveau commented Nov 1, 2026

Copy link
Copy Markdown
Owner Author

Superseded by #3, which carries this commit together with the round-2 review fixes.

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

@jclaveau jclaveau closed this Nov 1, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant