Skip to content

perf(pacquet): avoid nested tarball extraction parallelism without regressions #15

Open

Description

@zkochan

Problem

On a cold frozen install of the pinned Next.js workspace from pnpm/pnpm#13305, the TypeScript CLI completed in 11.30s while the Rust CLI completed in 13.84s on the same machine and dependency graph.

Investigation indicates that many tarballs are downloaded concurrently while each tarball with at least 32 files also uses inner parallel extraction. This nested parallelism increases scheduling and filesystem contention. As an experiment, effectively disabling per-tarball parallel extraction improved Rust fetch performance, but applying that globally could regress workloads with one or a few very large tarballs.

The concurrent integrity/extraction benchmark added by pnpm/pnpm#13433 provides a deterministic regression workload for the many-tarball case.

Proposed investigation

Test an adaptive, globally bounded extraction strategy rather than simply increasing or removing PARALLEL_EXTRACT_THRESHOLD:

  • preserve inner parallel extraction when only a few large tarballs are active;
  • prefer sequential extraction within each tarball when many tarballs are already in flight;
  • prevent outer package concurrency from multiplying unboundedly with per-tarball file concurrency.

Before choosing an implementation, parameterize the integrity benchmark across:

  • 1, 8, 32, 128, and 256 concurrent tarballs;
  • 8, 32, 64, 256, and 2,048 files per tarball;
  • small and large files;
  • compressible and incompressible content.

End-to-end validation

Validate baseline Rust against candidate Rust on:

  1. The pinned Next.js cold frozen-install reproduction.
  2. All 48 installation scenarios from fix: restore pnpm v12 benchmarks vltpkg/benchmarks#132:
    • fixtures: Next.js, Astro, Svelte, Vue, Large, and Babylon.js;
    • states: clean, cache, cache plus lockfile, cache plus node_modules, cache plus lockfile plus node_modules, lockfile, lockfile plus node_modules, and node_modules.
  3. The vlt build, build-cache, and run scenarios as correctness checks.
  4. Single-large-tarball microbenchmarks that exercise the workload most likely to benefit from inner parallel extraction.

Run at least five measured iterations after warmup. Repeat apparent regressions with baseline/candidate order reversed so machine drift is not mistaken for an implementation effect.

Acceptance criteria

  • The Next.js cold frozen install improves by at least 10%.
  • The concurrent-tarball microbenchmark improves materially.
  • No repeatable vlt installation scenario regresses by more than 3%.
  • Single-large-tarball scenarios do not regress by more than 3%.
  • Aggregate vlt performance does not regress.
  • Package counts, exit codes, lockfiles, and installed dependency graphs remain equivalent.

The optimization should not be merged if it only exchanges the Next.js regression for a regression in low-concurrency or large-tarball workloads.


Written by an agent (Codex, GPT-5).

Activity

  1. github-actions commented on Jul 27, 2026

    @github-actions

    Oz triage is running now and will classify this issue and apply one pnpm state: label.

    Follow along in Oz: https://app.warp.dev/run/019fa406-ffb9-7204-b79f-9fb13fb7780a

  2. github-actions commented on Jul 27, 2026

    @github-actions

    Triage result

    • Issue: pnpm/tasks#15 — perf(pacquet): avoid nested tarball extraction parallelism without regressions
    • State: Ready to spec
    • Applied label: state: needs design
    • Product / parity: Rust pacquet only (pnpm/crates/tarball). No TypeScript parity needed — the TypeScript CLI is the faster baseline here, not the target of changes.
    • Rationale: The issue explicitly defers the implementation choice to benchmark results: "Before choosing an implementation, parameterize the integrity benchmark across…" Multiple valid approaches exist (raise/lower PARALLEL_EXTRACT_THRESHOLD, globally-bounded fan-out semaphore, adaptive per-tarball vs. pool routing), and the correct choice depends on empirical data from the 5×5 tarball/file-count matrix. The concurrent benchmark infrastructure landed in PR test(benchmark): cover concurrent integrity extraction pnpm#13433 (merged), so the prerequisite tooling is in place. The acceptance criteria are clear, but the design is not.
    • Key implementation area: pnpm/crates/tarball/src/lib.rs — specifically the PARALLEL_EXTRACT_THRESHOLD constant (line 898), cas_write_pool() (line 82), and post_download_semaphore() (line 59). The problem is that post_download_semaphore allows num_cpus * 2 concurrent tarballs in flight, and each tarball with ≥32 files fans out across the dedicated cas_write_pool (also sized to num_cpus), creating up to num_cpus² * 2 concurrent CAS writes.
    • Next step: Run the benchmark matrix (1, 8, 32, 128, 256 concurrent tarballs × 8, 32, 64, 256, 2 048 files per tarball) and analyse where the contention inflection point lies. Results drive the design choice between a simple threshold change, a globally-bounded file-write semaphore, or the full adaptive strategy described in the issue.

    Written by an agent (Oz, auto).

  3. transferred this issue frompnpm/pnpmon Sep 26, 2026
  4. hood commented on Nov 9, 2026

    @hood

    Some macOS data for this one. The nested fan-out shows up there too, mostly as system time rather than wall time.

    Setup: pnpm 12.18.0 built from pnpm/pnpm@3600b05d00, M1 Pro (10 cores), APFS. Fixture is the integrated-benchmark one (1356 snapshots, ~33k files). Cold store, install --frozen-lockfile --ignore-scripts against registry.npmjs.org. The machine runs an EDR (Carbon Black plus a JumpCloud ES extension), so absolute syscall costs are inflated. That's pretty common on corporate dev Macs tbh.

    Cold install

    run wall user sys
    1 11.6 s 2.2 s 31.6 s
    2 11.0 s 2.2 s 28.1 s
    3 9.4 s 2.1 s 29.1 s

    pnpm fetch (store only) alone is 24.6 s sys, so almost all of it is the store write, not linking.

    The global rayon pool isn't the cause

    RAYON_NUM_THREADS wall (2 runs) sys
    16 (default here) 12.9 / 10.6 s 25.1 / 27.9 s
    8 9.3 / 8.5 s 27.4 / 26.7 s
    4 9.0 / 9.0 s 27.2 / 27.4 s
    2 9.4 / 8.6 s 27.0 / 27.9 s

    Sys stays at ~27 s whatever the rayon size. The wall numbers are network-noisy, so I wouldn't read much into them.

    Who's in the kernel

    Thread census mid-install: 40 tokio-rt-worker (10 async plus ~30 blocking from post_download_semaphore and streaming_extract_semaphore), 10 cas-write, 16 global rayon, 4 pnpm-link.

    sample over 7 s of a cold install, thread-ms on the leaf syscall (symbolized build):

    pool syscall thread-ms caller
    cas-write open 5861 StoreDir::write_cas_file
    blocking (BufferedExtraction::run) open 2297 StoreDir::write_cas_file
    cas-write + blocking write 2636 StoreDir::write_cas_file
    cas-write + blocking close 2635 StoreDir::write_cas_file
    pnpm-link clonefileat 3315 link_file::clone_tier, dir_clone_cache
    cas-write + blocking stat (parent dir) 487 unix_creation_mode
    cas-write + blocking fstat 343 grant_mode_bits

    A create-open costs ~250 µs here vs ~100 µs for a per-file clonefileat. So ~40 threads are queueing on the metadata path that dir_clone_cache.rs already describes as serialized volume-wide, and the queueing is what burns the sys time.

    Takeaways for the design

    • On macOS the useful cap is on concurrent CAS creators: the blocking extractors that write inline under PARALLEL_EXTRACT_THRESHOLD plus the cas-write pool, not the rayon pool.
    • A wall-time win is unproven. A cap should cut sys time a lot (laptop CPU, fans), but wall is bounded by the APFS ceiling either way. The cold-pnpr scenario is probably the right way to measure it, since the npm registry is too noisy for this.
    • Side note: the per-file parent stat in unix_creation_mode is ~3% of CAS syscall time. The shard dirs' mode could be cached once per dir.

    Repro

    cp pnpm/tasks/integrated-benchmark/src/fixtures/* /tmp/proj && cd /tmp/proj
    rm -rf node_modules store-dir && /usr/bin/time -l pnpm install --frozen-lockfile --ignore-scripts
    # per-pool breakdown: build with CARGO_PROFILE_RELEASE_STRIP=false, then
    pnpm install --frozen-lockfile --ignore-scripts & sample $! 7 1 -file cold.sample

    (Looks sloppy as I’m on the move and did a speech-to-text -> polish with 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

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions