Repository navigation
Description
Summary
Let pnpm install packages from zstd-compressed tarballs (.tar.zst) when a registry offers them, starting with pnpr. A prototype shows tarballs 37% smaller and cold-store installs 33% faster on a 25 Mbit/s link. On fast links the install is bound by writing files to disk and gains nothing.
pnpm/pnpm#16585 already made pnpm accept zstd-compressed metadata responses and made pnpr serve them. That does not help tarballs. A .tgz is already gzip output, so Content-Encoding: zstd on top saves nothing, and pnpr excludes tarballs from response compression. The gain needs a zstd-compressed tar, which is a different artifact with a different hash.
Measurements
Measured 2026-10-15 on an M1 Max (macOS). The fixture has 30 popular direct dependencies, and a macOS install fetches 1,183 tarballs.
Size of all tarballs:
| format | total | vs gzip |
|---|---|---|
| gzip (as published) | 228.9 MB | |
| zstd level 3 | 198.8 MB | -13% |
| zstd level 19 | 143.5 MB | -37% |
Install time used a prototype client (see below). Each run was a frozen-lockfile install --ignore-scripts with a cold store and a warm metadata cache. Tarballs came from one local file server, behind a TCP proxy that emulates latency and a shared downstream bandwidth cap. The values are medians of 5 interleaved runs, comparing gzip with zstd level 19:
| link | wall time | user CPU |
|---|---|---|
| loopback | 48.5 -> 49.8 s (no difference, runs spread 42-58 s) | 3.29 -> 2.70 s |
| 100 Mbit/s, 40 ms RTT | 46.3 -> 49.4 s (inconclusive, ranges overlap) | 3.49 -> 2.78 s |
| 25 Mbit/s, 60 ms RTT | 84.8 -> 56.3 s (-33%, ranges disjoint) | 4.59 -> 3.26 s |
- Disk floor: a cold-store install on macOS spends about 45 s in file creation (
systime), while user CPU is about 3.5 s. The download only shows in wall time once it takes longer than that floor. On this machine that happens below roughly 40 Mbit/s for this tree. - Other machines (unmeasured): a machine that creates files faster, such as a Linux CI runner, has a lower floor, so the crossover should come at a higher bandwidth.
- CPU: decoding uses 18-30% less CPU at every link, but it is too small a share of the install to move wall time.
- Correctness: the zstd and gzip runs produced byte-identical content-addressed stores.
- Possible prototype issue: the 100 Mbit/s rows lean slightly slower with zstd. This may be noise, or the prototype routing small archives through the eager decoder differently. It was not investigated.
Not covered: Linux, Windows, other dependency trees, real registries (the server was a Python file server, verified to deliver all 229 MB in 5 s), and warm-store installs. A restored store downloads few tarballs, so the gain reaches only cold installs: fresh CI, Docker builds, new machines.
Prototype
The prototype was a local branch on top of b260a317ec and was not pushed. It touched three things in pnpm/crates/tarball:
- Sniff the zstd frame magic (
28 B5 2F FD) at each decode site:decompress_gzip,extract_gzipped_tarball, and both streaming entry points inextract/streaming.rs. It decodes with thezstdcrate, which reqwest'szstdfeature already compiles in. - Accept the zstd magic in
starts_with_gzip_magic(download/body.rs). The download path rejects any body that does not start with the gzip magic before it decodes anything. - Skip the integrity comparison. The lockfile pins the sha512 of the
.tgz, so a.tar.zstcannot match it. The prototype still computed the hash, so its cost is included.
Item 3 is the design problem.
Design questions
Integrity. dist.integrity and every lockfile pin the exact .tgz bytes. A client that receives .tar.zst cannot check that hash without the .tgz. A .tar.zst needs its own hash, and that hash has to reach the lockfile:
- Metadata: the packument carries an alternate next to
dist, for exampledist.zstd = { tarball, integrity }. - Lockfile: the lockfile records the alternate's integrity next to the
.tgzone. Otherwise a frozen install has nothing to verify the.tar.zstagainst. This is a lockfile format change and has to stay compatible with clients that only know.tgz. - Trust: at resolution time this is no weaker than today, because
dist.integrityalready comes from the registry. After resolution the lockfile pins whatever hash it recorded.
Provenance and attestations. Sigstore provenance names the .tgz digest as its subject. A .tar.zst produced by the registry is not covered by the publisher's attestation, so its link to the signed artifact is only the registry's claim. Options:
- Fall back to the
.tgzwhenever provenance or attestation checks are enabled. - Have the registry attest the transcoding.
- Only use alternates that the publisher produced and that provenance covers.
Who produces the .tar.zst:
- pnpr transcodes on publish or on first fetch. This is cheap to ship, but registry-produced hashes carry the trust trade-off above.
pnpm publishuploads both. This keeps the artifact author-produced, but needs registry support for a second artifact.
Negotiation. A client that does not understand zstd must never receive it. Gating on a metadata field the client opts into (it reads dist.zstd only if it knows it) is simpler than content negotiation on the tarball URL.
Level. The registry compresses each tarball once, so level 19 is affordable. Level 3 is the option for on-the-fly transcoding, and it gives only -13%.
Suggested next steps
- Measure on a Linux runner to find where the crossover sits on a machine with a lower disk floor. This decides how many users would see a gain.
- Settle the integrity and lockfile design before writing production code. It is the part that touches the lockfile format and supply-chain checks.
- Ship it in pnpr and pnpm v12 behind the opt-in metadata field. Other registries can adopt it later.
Written by an agent (Claude Code, claude-opus-5-5).
Activity
zkochan commentedon Oct 15, 2026
The design is proposed in pnpm/rfcs#39 (zstd-compressed registry tarballs). A registry entry in
registriesdeclarestarballCompression: zstd, and lockfile integrities for that registry then pin the.tar.zst. pnpr servestgz,zstd, or both per registry.Written by an agent (Claude Code, claude-opus-5-5).
zkochan commentedon Oct 16, 2026
Linux results: zstd tarballs, cold-store frozen install
Same method, scripts, fixture, and prototype patch as the macOS run (patch on
b260a317ec, release build with thin LTO).Summary: On Linux the crossover is between 2 and 4 Gbit/s, compared with 25-100 Mbit/s on macOS. The cold-store install's filesystem work is small here: about 1.3 s wall and about 6 s
sysfor the whole install. Below 2 Gbit/s the install is bandwidth-bound, and wall time follows bytes transferred. zst19 is 28-36% faster from 1 Gbit/s down to 25 Mbit/s, and 24% faster at 2 Gbit/s.1. Machine
nproc32), governorperformance/var/tmp/zstd-bench, btrfs on LUKS (dm-crypt) on a Samsung SSD 9100 PRO 4TB (NVMe)./tmpis tmpfs, so it was not used.2. Tarballs and correctness
A Linux install fetches 1177 of the 1361 lockfile packages. The rest are optional dependencies for other platforms.
No download or re-compression printed
FAIL. The correctness check printedIDENTICAL: the tgz and zst19 stores have the same 48,407 content-addressed files. Everyserve-*.logstayed empty, so no metadata requests and no non-200 responses. The bytes counted by the proxy match the totals above on every run.3. Results
Five runs per cell, variants interleaved within each round, wall time in seconds. "vs tgz" compares medians.
userandsysare medians. No row failed. The matrix rows come first. The 2 Gbit/s, 4 Gbit/s, and 20 ms uncapped rows are an extra sweep I added afterwards with the same scripts, because the matrix had no point between 1 Gbit/s and loopback.4. Crossover
5. Observations and limits
user, and 5.6-5.8 ssyson loopback, compared with about 45 s, almost allsys, on the M1 Max.systime barely changes with the variant or the link (5.5-6.9 s).userdrops by about 0.3-0.7 s with zst3 or zst19, while hashing the tgz-pinned integrity still runs. This doesn't show up in wall time on any link.curl -P 16took about 0.25 s directly fromserve.pyand about 0.3 s through an uncappedlink.py(about 6 Gbit/s). The 1.3 s loopback floor is pnpm, not the Python server or proxy.nodeprocesses) fell during the 50 Mbit/s block, whose ranges stayed within 0.3%. Loopback tgz spread 7.5% (1.32-1.42 s), within the 10% threshold. I'd treat the 2 Gbit/s result as directional, and wouldn't trust the Python token bucket's precision at multiple Gbit/s.Written by an agent (Claude Code, claude-opus-5-5).
zkochan commentedon Oct 16, 2026
Follow-up: zstd is also faster above the crossover
In my previous comment, zstd looked neutral or slightly slower at loopback, 20 ms uncapped, and 4 Gbit/s (+1% and +3% in two cells). With 5 runs, that was noise. I reran those three links with 15 rounds each, variants interleaved, same scripts and machine. No run failed.
zst3 was faster than tgz in 10 to 12 of 15 rounds on each link.
userCPU drops from 2.9 s to 2.6 s because zstd decodes faster than gzip, whilesysstays at about 5.7 s.Written by an agent (Claude Code, claude-opus-5-5).
zkochan commentedon Oct 16, 2026
zstd tarballs on Windows (not Linux)
These are Windows measurements. The task asked for Linux, but this machine runs Windows 10, so I ported the harness and ran the same method here. I didn't measure Linux.
Bottom line: with a Defender exclusion on the work directory,
zst19is clearly faster below 50–100 Mbit/s (crossover between 50 and 100). That's higher than on the M1 Max (25–100), because the install's filesystem floor is ~21 s here vs ~45 s there. With Defender's default real-time scanning, a cold install takes ~325 s and zstd makes no difference even at 20 Mbit/s.1. Machine
b260a317ec+ patch, reports 12.14.0), zstd crate 0.13.3 / libzstd 1.5.7, Node 26.12.0 (bundled zstd 1.5.7) for the harness2. Tarballs and correctness
The Windows install fetches 1176 tarballs. The lockfile has 1361 packages, and the rest are optional binaries for other platforms. So the set differs from the macOS one.
.zstdecompresses to exactly the tar inside its.tgz(2352/2352 checked).tgzandzst19installs each produced the same 48,404 content-addressed store files.serve-*.logstayed empty: no metadata requests and no 404s.3. Results, Defender exclusion on the work directory (5 runs each)
Each table gives the wall-time median, the min–max range, the change against
tgz, the medianuserandsysCPU of the pnpm process, and the bytes transferred.Loopback
20 ms one-way, 1000 Mbit/s
20 ms, 500 Mbit/s
20 ms, 200 Mbit/s
20 ms, 100 Mbit/s
20 ms, 50 Mbit/s
30 ms, 25 Mbit/s
All 105 runs succeeded with 1177 entries in
node_modules/.pnpm, and the byte counts match the tarball totals exactly.3b. Default Defender, no exclusion (3 runs each)
The short pass was meant to run at loopback, 100 and 25 Mbit/s. A PowerShell argument-passing bug ran all 9 installs at 0 ms, 20 Mbit/s instead. That link is slower than any in the main matrix, so it's the case most favourable to zstd.
On loopback without the exclusion (one run each, from the correctness check): tgz 324.1 s and zst19 326.8 s. During an install,
MsMpEng.exeused ~2.3 cores while pnpm used ~0.15, and the disk was only 12–26% busy. Defender's on-write scanning is the bottleneck, and the 20 Mbit/s download (95 s for tgz) hides completely behind it.4. Crossover
zst3saves only 12% of bytes and gives −9 to −12% on the slow links, sozst19is the useful level.5. Caveats and surprises
link.pyandserve.py. Python isn't installed here, and Windows has no SIGUSR1/2, so stats are reset and dumped over a control port.timeBeginPeriod(1)throughnode:ffi.GetProcessTimeson the pnpm process, not/usr/bin/time.syncbefore each run.gzip -dc | zstdfrom stdin, the frames carry no content size.sync, plus Windows background I/O. The slow links, where transfer dominates, spread under 3–14%. So the crossover conclusion holds, but differences under ~10% on fast links are noise.sysis ~49 s in every variant, spread over 8 threads, so ~21 s wall. zstd lowersuserslightly (10.4 vs 11.8 s on loopback), but CPU isn't what bounds the install.Written by an agent (Claude Code, Claude Opus 5.5).
zkochan commentedon Nov 8, 2026
Shipped through pnpm/rfcs#39, pnpm/pnpm#17054 and pnpm/pnpm#17437. The final design uses the tar integrity plus zstd content coding instead of a
dist.zstdalternate.Written by an agent (Claude Code, claude-opus-5-5).