Skip to content

Install from zstd-compressed tarballs (.tar.zst) offered by the registry #135

Closed

Description

@zkochan

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 (sys time), 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:

  1. Sniff the zstd frame magic (28 B5 2F FD) at each decode site: decompress_gzip, extract_gzipped_tarball, and both streaming entry points in extract/streaming.rs. It decodes with the zstd crate, which reqwest's zstd feature already compiles in.
  2. 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.
  3. Skip the integrity comparison. The lockfile pins the sha512 of the .tgz, so a .tar.zst cannot 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 example dist.zstd = { tarball, integrity }.
  • Lockfile: the lockfile records the alternate's integrity next to the .tgz one. Otherwise a frozen install has nothing to verify the .tar.zst against. 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.integrity already 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 .tgz whenever 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 publish uploads 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

  1. 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.
  2. Settle the integrity and lockfile design before writing production code. It is the part that touches the lockfile format and supply-chain checks.
  3. 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

  1. added
    area: supply chain security
    on Oct 15, 2026
  2. zkochan commented on Oct 15, 2026

    @zkochan
    MemberAuthor

    The design is proposed in pnpm/rfcs#39 (zstd-compressed registry tarballs). A registry entry in registries declares tarballCompression: zstd, and lockfile integrities for that registry then pin the .tar.zst. pnpr serves tgz, zstd, or both per registry.


    Written by an agent (Claude Code, claude-opus-5-5).

  3. zkochan commented on Oct 16, 2026

    @zkochan
    MemberAuthor

    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 sys for 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

    CPU AMD Ryzen 9 9950X3D2, 16 cores / 32 threads (nproc 32), governor performance
    RAM 60 GiB
    Kernel / distro 7.2.5-200.fc44.x86_64, Aurora 44.20261006.1 (Fedora Kinoite based)
    Work dir /var/tmp/zstd-bench, btrfs on LUKS (dm-crypt) on a Samsung SSD 9100 PRO 4TB (NVMe). /tmp is tmpfs, so it was not used.
    Tools Python 3.14.7, Node.js 26.12.0

    2. Tarballs and correctness

    A Linux install fetches 1177 of the 1361 lockfile packages. The rest are optional dependencies for other platforms.

    variant files total
    tgz 1177 235.3 MB
    zst3 1177 206.5 MB (-12%)
    zst19 1177 150.1 MB (-36%)

    No download or re-compression printed FAIL. The correctness check printed IDENTICAL: the tgz and zst19 stores have the same 48,407 content-addressed files. Every serve-*.log stayed 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. user and sys are 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.

    link variant median range vs tgz user sys MB down
    loopback tgz 1.34 1.32-1.42 2.88 5.78 235.6
    zst3 1.30 1.25-1.33 -3% 2.60 5.60 206.7
    zst19 1.28 1.23-1.34 -4% 2.53 5.58 150.3
    20 ms, uncapped (extra) tgz 1.39 1.37-1.46 2.84 5.69 235.6
    zst3 1.41 1.29-1.43 +1% 2.56 5.68 206.7
    zst19 1.37 1.31-1.45 -1% 2.57 5.67 150.3
    20 ms, 4000 Mbit/s (extra) tgz 1.40 1.38-1.93 2.89 5.76 235.6
    zst3 1.37 1.32-1.76 -2% 2.60 5.78 206.7
    zst19 1.44 1.28-1.72 +3% 2.56 5.74 150.3
    20 ms, 2000 Mbit/s (extra) tgz 1.76 1.59-1.89 2.87 5.81 235.6
    zst3 1.42 1.29-1.71 -20% 2.66 5.62 206.7
    zst19 1.33 1.27-1.52 -24% 2.64 5.53 150.3
    20 ms, 1000 Mbit/s tgz 2.27 2.23-2.34 2.95 6.27 235.6
    zst3 2.01 1.97-2.09 -12% 2.63 6.09 206.7
    zst19 1.62 1.56-1.71 -28% 2.66 6.18 150.3
    20 ms, 500 Mbit/s tgz 4.21 4.15-4.25 3.13 6.09 235.6
    zst3 3.64 3.58-3.67 -14% 2.71 6.45 206.7
    zst19 2.81 2.75-2.86 -33% 2.70 6.15 150.3
    20 ms, 200 Mbit/s tgz 9.79 9.79-9.79 3.40 6.17 235.6
    zst3 8.57 8.56-8.59 -12% 2.92 6.37 206.7
    zst19 6.35 6.32-6.38 -35% 2.85 6.42 150.3
    20 ms, 100 Mbit/s tgz 19.29 19.25-19.33 3.65 6.45 235.6
    zst3 16.82 16.80-16.88 -13% 3.18 6.51 206.7
    zst19 12.42 12.38-12.50 -36% 3.04 6.50 150.3
    20 ms, 50 Mbit/s tgz 38.09 38.06-38.15 3.67 6.40 235.6
    zst3 33.40 33.38-33.46 -12% 3.17 6.67 206.7
    zst19 24.41 24.40-24.44 -36% 3.18 6.57 150.3
    30 ms, 25 Mbit/s tgz 75.73 75.72-76.05 3.86 6.87 235.6
    zst3 66.47 66.42-66.48 -12% 3.27 6.56 206.7
    zst19 48.41 48.41-48.52 -36% 3.14 6.62 150.3

    4. Crossover

    • zst19 is clearly faster, with non-overlapping ranges, at 2000 Mbit/s and every slower link tested. The gain is -24% at 2 Gbit/s, -28% at 1 Gbit/s, and -33% to -36% from 500 Mbit/s down to 25 Mbit/s. That last figure equals the 36% size reduction, because those links are fully bandwidth-bound.
    • At 4000 Mbit/s, 20 ms uncapped, and loopback, the variants are indistinguishable. Medians differ by 4% or less, the ranges overlap, and every variant sits at a floor of about 1.3-1.4 s.
    • So the crossover is between 2 and 4 Gbit/s on this machine, compared with 25-100 Mbit/s on macOS. Above it, zstd neither helps nor hurts. Below it, the gain is the size reduction.
    • zst3 gives -12% to -14% across all bandwidth-bound links, which matches its 12% size reduction. At 2 Gbit/s its range overlaps tgz.
    • Below 1 Gbit/s, wall time is the transfer time plus about 0.4 s. For example, tgz at 100 Mbit/s needs 18.85 s to transfer 235.6 MB and took 19.29 s. Extraction and linking overlap with the download almost entirely.
    • At 25 Mbit/s with 60 ms RTT: tgz 75.7 s, zst19 48.4 s (-36%). macOS measured 84.8 s and 56.3 s (-33%).

    5. Observations and limits

    • The filesystem cost is very different from macOS. The whole cold-store install takes about 1.3 s wall, 2.5-2.9 s user, and 5.6-5.8 s sys on loopback, compared with about 45 s, almost all sys, on the M1 Max. sys time barely changes with the variant or the link (5.5-6.9 s).
    • zstd saves a little CPU. Median user drops 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.
    • I checked that the harness is not the ceiling. Fetching all 1177 tgz files with curl -P 16 took about 0.25 s directly from serve.py and about 0.3 s through an uncapped link.py (about 6 Gbit/s). The 1.3 s loopback floor is pnpm, not the Python server or proxy.
    • Noise at 2 and 4 Gbit/s: some runs were 0.3-0.5 s slower than the rest, scattered across variants and rounds (for example, tgz at 4 Gbit/s ranged 1.38-1.93 s). Other agent sessions on the machine pushed the load average to about 7, and I could not stop them. I didn't record load during the extra sweep. In the main matrix, the logged load spikes (up to about 16, from other node processes) 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.
    • The lockfile run needed a retry. The first frozen install through pnpr failed because npmjs upstream requests timed out (504) and pnpr's circuit breaker then returned 503. A rerun through the same pnpr succeeded. The first run had already requested all 1177 tarballs, so the list is complete, and the correctness check confirms every install got 1178 package directories.
    • Not measured: a real WAN (packet loss, TCP slow start on fresh connections, HTTP/2), other filesystems (only btrfs on dm-crypt; ext4 and XFS may differ), warm-store installs, and the registry's cost of compressing at level 19.

    Written by an agent (Claude Code, claude-opus-5-5).

  4. zkochan commented on Oct 16, 2026

    @zkochan
    MemberAuthor

    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.

    link tgz zst3 zst19 zst19 faster than tgz in the same round
    loopback 1.38 s (1.29-1.46) 1.31 s (-5%) 1.30 s (-6%, 1.24-1.36) 14 of 15, median 0.08 s
    20 ms, uncapped 1.43 s (1.32-2.14) 1.38 s (-3%) 1.34 s (-7%, 1.29-1.41) 11 of 15, median 0.11 s
    20 ms, 4000 Mbit/s 1.53 s (1.38-1.89) 1.43 s (-7%) 1.37 s (-11%, 1.30-1.67) 11 of 15, median 0.17 s

    zst3 was faster than tgz in 10 to 12 of 15 rounds on each link.

    • zstd is faster on every link tested, including links where bandwidth is not the limit. Median user CPU drops from 2.9 s to 2.6 s because zstd decodes faster than gzip, while sys stays at about 5.7 s.
    • Above about 2 Gbit/s, the gain is 5-10%, and the ranges still overlap. Below it, the gain follows the size reduction, reaching -36% for zst19.
    • So I would restate the crossover from my earlier comment as follows. Between 2 and 4 Gbit/s is where the large, bandwidth-driven gain fades on this machine. zstd is not neutral above it.

    Written by an agent (Claude Code, claude-opus-5-5).

  5. zkochan commented on Oct 16, 2026

    @zkochan
    MemberAuthor

    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, zst19 is 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

    CPU Intel Core i7-3770 @ 3.40 GHz (Ivy Bridge, 2012), 4 cores / 8 threads
    RAM 32 GB (4 × 8 GB DDR3-1867)
    OS Windows 10 Pro 22H2, build 19045
    Disk Samsung SSD 850 EVO 500 GB, SATA SSD (not NVMe), NTFS, 8.3 names enabled, last-access updates disabled
    Antivirus Microsoft Defender, real-time protection on, no exclusions by default
    Toolchain pnpm prototype (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 harness

    2. 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.

    variant files total vs tgz
    tgz 1176 236.3 MB
    zst3 1176 207.8 MB −12%
    zst19 1176 150.2 MB −36%
    • Every .zst decompresses to exactly the tar inside its .tgz (2352/2352 checked).
    • Correctness check: IDENTICAL. The tgz and zst19 installs each produced the same 48,404 content-addressed store files.
    • Every serve-*.log stayed 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 median user and sys CPU of the pnpm process, and the bytes transferred.

    Loopback

    variant median range Δ user sys bytes
    tgz 21.9 s 19.1–23.5 11.8 49.9 236.5 MB
    zst3 20.9 s 18.7–26.1 −5% 10.8 49.0 208.0 MB
    zst19 21.6 s 20.4–27.9 −1% 10.4 49.5 150.4 MB

    20 ms one-way, 1000 Mbit/s

    variant median range Δ user sys bytes
    tgz 22.4 s 20.0–25.3 11.4 48.6 236.5 MB
    zst3 20.9 s 20.2–21.8 −7% 11.4 49.2 208.0 MB
    zst19 22.3 s 20.4–23.2 −0% 10.8 48.9 150.4 MB

    20 ms, 500 Mbit/s

    variant median range Δ user sys bytes
    tgz 21.7 s 19.7–28.4 11.7 50.1 236.5 MB
    zst3 21.9 s 19.7–24.5 +1% 11.2 49.4 208.0 MB
    zst19 21.8 s 19.2–25.9 +0% 10.5 48.6 150.4 MB

    20 ms, 200 Mbit/s

    variant median range Δ user sys bytes
    tgz 22.7 s 19.7–22.9 11.8 49.6 236.5 MB
    zst3 22.8 s 19.9–24.7 +1% 11.1 49.3 208.0 MB
    zst19 21.3 s 19.0–26.7 −6% 11.1 49.7 150.4 MB

    20 ms, 100 Mbit/s

    variant median range Δ user sys bytes
    tgz 24.1 s 22.6–27.6 11.1 48.6 236.5 MB
    zst3 23.6 s 21.8–29.5 −2% 11.2 49.2 208.0 MB
    zst19 21.8 s 19.3–25.4 −10% 10.9 50.4 150.4 MB

    20 ms, 50 Mbit/s

    variant median range Δ user sys bytes
    tgz 42.1 s 41.7–43.1 9.7 48.5 236.5 MB
    zst3 38.1 s 37.5–39.9 −9% 9.6 48.4 208.0 MB
    zst19 28.6 s 27.6–31.5 −32% 9.9 48.4 150.4 MB

    30 ms, 25 Mbit/s

    variant median range Δ user sys bytes
    tgz 80.0 s 79.6–81.2 8.8 48.4 236.5 MB
    zst3 70.8 s 69.7–73.0 −12% 9.1 47.7 208.0 MB
    zst19 51.6 s 50.8–52.5 −36% 9.4 48.2 150.4 MB

    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.

    variant median range Δ user sys bytes
    tgz 323.6 s 321.8–348.5 10.7 48.1 236.5 MB
    zst3 332.6 s 325.0–347.8 +3% 9.7 48.7 208.0 MB
    zst19 329.8 s 324.7–349.8 +2% 9.7 49.0 150.4 MB

    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.exe used ~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

    • With the exclusion, the crossover is between 50 and 100 Mbit/s. At 50 Mbit/s the ranges don't overlap (tgz 41.7–43.1 s, zst19 27.6–31.5 s, −32%). At 100 Mbit/s they overlap (22.6–27.6 vs 19.3–25.4). The zst19 median is 10% lower there, but within the noise.
    • The install floor is ~21 s here. tgz takes 18.9 s to transfer at 100 Mbit/s and 37.8 s at 50 Mbit/s, so the crossover sits where tgz transfer time passes the floor, around 80–100 Mbit/s.
    • macOS comparison: on the M1 Max the crossover was between 25 and 100 Mbit/s with a ~45 s floor. Here the floor is about half that, so the crossover moves up, as the RFC predicts for faster filesystems.
    • Below the crossover, the gain is about the size ratio: −32% at 50 Mbit/s and −36% at 25 Mbit/s (macOS: −33% at 25 Mbit/s). Above it, nothing measurable.
    • zst3 saves only 12% of bytes and gives −9 to −12% on the slow links, so zst19 is the useful level.
    • With default Defender there is no crossover in the measured range. Even at 20 Mbit/s, zstd made no measurable difference.

    5. Caveats and surprises

    • Not Linux. This is a Windows data point. The Linux question is still open.
    • Ported harness:
      • The link emulator and the static server are Node ports of link.py and serve.py. Python isn't installed here, and Windows has no SIGUSR1/2, so stats are reset and dumped over a control port.
      • Windows' 15.6 ms timer tick would have stretched the 20 ms delays, so the link process calls timeBeginPeriod(1) through node:ffi.
      • Measured: a single small request takes ~47 ms through the 20 ms link (nominal 40 ms), and the 25 Mbit/s cap delivered 24.7 Mbit/s.
      • CPU time comes from GetProcessTimes on the pnpm process, not /usr/bin/time.
      • There's no sync before each run.
    • Recompression: zstd frames were made with Node's bundled libzstd 1.5.7, fed in 128 KiB chunks, with the checksum flag on. Like gzip -dc | zstd from stdin, the frames carry no content size.
    • Noise: with the exclusion, runs of one variant on fast links spread by up to ~40% (e.g. zst19 loopback 20.4–27.9 s), above the 10% target. I didn't pin down the cause. Likely suspects are the previous run's 48k-file store being deleted just before each run without 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.
    • CPU: sys is ~49 s in every variant, spread over 8 threads, so ~21 s wall. zstd lowers user slightly (10.4 vs 11.8 s on loopback), but CPU isn't what bounds the install.
    • Not measured: Linux; WSL2; a Windows 11 Dev Drive (ReFS + Defender performance mode), which would likely sit between the two Windows cases; an NVMe disk; and the default-Defender pass at the planned links (only 0 ms / 20 Mbit/s plus one loopback run per variant).

    Written by an agent (Claude Code, Claude Opus 5.5).

  6. zkochan commented on Nov 8, 2026

    @zkochan
    MemberAuthor

    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.zstd alternate.

    Written by an agent (Claude Code, claude-opus-5-5).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    area: performancearea: supply chain securityproduct: pacquetproduct: pnprtype: feature

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions