Repository navigation
Description
Summary
Follow-up to #177 (dist.pnpr.requiresBuild).
While pnpr is already streaming .tar archives on publish (pnpr/crates/pnpr/src/server/publishing/attachments.rs) and on first upstream decode (pnpr/crates/pnpr/src/server/tar_responses.rs), and projecting packuments in pnpr/crates/upstream/src/abbreviate.rs, there are three related optimizations that can be evaluated and benchmarked independently:
1. Precalculated bins + shebang runtime (dist.pnpr.bins)
Problem today
- When a package uses
"directories": { "bin": "./bin" }, the packument does not list the command names —commands_from_directories_bin(pnpm/crates/cmd-shim/src/bin_resolver.rs) has to walk the directory on disk after extraction. - On a cold install,
CreateVirtualStoreOutput::package_manifests(pnpm/crates/deps-restorer/src/create_virtual_store.rs) only holds warm store-index manifests, solink_direct_dep_bins_prefetched(pnpm/crates/deps-restorer/src/link_bins/direct.rs) falls back to reading and parsingpackage.jsonfrom disk for every cold package withhasBin: true. - For every bin target,
read_shebang(pnpm/crates/cmd-shim/src/shim.rs) opens the file on disk and reads its first 512 bytes to detect#!/usr/bin/env node(or other interpreters) before writing.binshims.
Proposed change & verification
- While streaming the
.tar,pnprseespackage/package.json, all regular files underdirectories.bin, and the first line of each bin target. - Precalculating
dist.pnpr.bins(command name → relative path + parsed shebangprog/args) allowspnpmto write.binshims forrequiresBuild: falsepackages with zero disk reads ofpackage.jsonor bin scripts (and potentially overlap.binshim creation with tarball extraction). - Benchmark verification needed: Measure the wall-time savings on cold installs (especially on Windows where every bin writes
.cmd/.ps1/shell wrappers and on macOS/Linux withpreferSymlinkedExecutables: falseorextendNodePath: true) vs. the small metadata payload increase for packages withhasBin: true.
2. Backfilling verified fileCount and unpackedSize
Problem today
Packages published before npm 6 (and many non-npm tarballs) omit dist.fileCount and dist.unpackedSize. Without them:
extract_tarball_entries(pnpm/crates/tarball/src/extract.rs) startsVec<PendingFile>with capacity0(tar::Entries::size_hint()is always(0, None)), causing repeated reallocations during extraction.decompress_gzipandshould_stream_extract(pnpm/crates/tarball/src/extract.rs) lack an accurate size hint.ObservedDistStats(pnpm/crates/resolving-npm-resolver/src/create_npm_resolution_verifier.rs), which thepnprfrozen fast path uses to schedule the heaviest tarball downloads first, hasNonefor those packages.
Proposed change & verification
- Count regular files and sum their byte sizes while streaming the
.tarinpnpr, and populatedist.fileCountanddist.unpackedSizewhenever they are missing (or replace untrusted publisher claims with the verified values). - Benchmark verification needed: Measure extraction allocation savings and download-scheduling makespan improvements on graphs containing older packages.
3. Eliminating full-packument (application/json) fallbacks when resolving against pnpr
Full packuments (application/json) are 10–50× larger than abbreviated packuments (application/vnd.npm.install-v1+json) because they carry every version's readme, maintainers, full scripts, etc. Currently pnpm still falls back to full packuments in two places that pnpr's abbreviated packument can satisfy:
-
optionalDependencies(PickState::metadata_shapeinpnpm/crates/resolving-npm-resolver/src/pick_package/state.rs):pnpmforcesfull_metadata = truewheneveropts.request.optionalistruebecause the public npm registry's abbreviated format dropslibc(pnpm/pnpm#9950).- However,
pnpr'sABBREVIATED_VERSION_FIELDS(pnpr/crates/upstream/src/abbreviate.rs) already preserves"libc","cpu", and"os". TeachingPickState::metadata_shapethat apnprregistry does not need full metadata foroptionalDependenciesavoids full-packument downloads for platform-specific optional dependencies (@swc/core-*,@esbuild/*,@rollup/rollup-*).
-
trustPolicy: no-downgrade(TrustEvidenceinpnpm/crates/resolving-npm-resolver/src/trust_checks.rs):pnpr'sabbreviate_packument(pnpr/crates/upstream/src/abbreviate.rs) already includes coarsenedtime(sominimumReleaseAgeworks on abbreviated packuments), butABBREVIATED_VERSION_FIELDSstrips_npmUser(_npmUser.trustedPublisherand_npmUser.approver).- Preserving a minimal
_npmUser({ trustedPublisher, approver }when present) inpnpr's abbreviated packument letspnpmruntrustPolicy: no-downgradeon abbreviated packuments without ever upgrading to full packuments.
- Preserve
"bundledDependencies"inABBREVIATED_VERSION_FIELDS(pnpr/crates/upstream/src/abbreviate.rs):ABBREVIATED_VERSION_FIELDScurrently copies"bundleDependencies"but omits"bundledDependencies"(with ad), whichBundledDependencies::from_manifest(pnpm/crates/lockfile/src/package_metadata.rs) checks first.
- Benchmark verification needed: Measure resolution time and metadata transfer byte reduction on cold-cache resolutions with
optionalDependenciesandtrustPolicy: no-downgrade.
Written by an agent (Antigravity, Gemini 4 Argon).
Activity
zkochan commentedon Oct 21, 2026
Opened pnpm/pnpm#17186 to implement Section 1 (Precalculated
bins+ shebang runtime (dist.pnpr.bins)), completing the remaining work in this issue following the merge of pnpm/pnpm#11988 for Section 2:pnpr: Computesdist.pnpr.bins(command_name -> { path, prog, args }) during.tarstreaming ininspect_tarwhenrequiresBuildisfalseand the package exposes bins (binstring/object ordirectories.bin), reading the first 256 bytes of each bin entry to extract any#!shebang runtime, and caches it alongsiderequiresBuildinTarMetadataCache.pnpm: Threads cold-extractedpackage.jsonmanifests and precalculatedbinsfrom tarball extraction throughCreateVirtualStoreOutput(package_manifestsandpackage_bins) intoLinkVirtualStoreBinsandlink_direct_dep_bins_prefetched, and verifies warm-cachedist.pnpr.binsagainst the store index's authoritativemanifestandcas_pathsbefore writing.binshims viacreate_cmd_shim_with_runtimewith zero disk reads ofpackage.json,directories.bin, or bin script shebangs.Written by an agent (Antigravity, Gemini 4 Argon).
perf(install): precalculate package bins and shebang runtimes (pnpm#1…