Skip to content

Track peak memory usage in benchmarks for both the TypeScript and Rust stacks #30

Open

Description

@zkochan

Problem

Nothing in this repository measures memory. The benchmark pipeline is time-shaped end to end, for both the TypeScript CLI and the Rust stacks, so a memory regression can only be caught by a user hitting it in production.

That is what happened with pnpm/pnpm#13077: concurrent workspace projects each re-serialized the same registry packument (~31 MB for a popular package), exhausting the V8 heap on large workspaces. It shipped, and CI had no way to see it.

pnpm/pnpm#13079 fixes that specific bug and carries a deterministic regression test for it. This issue is about the general gap.

Why CI cannot catch this class today

Concretely, verified against the current tree:

  1. No memory instrumentation exists anywhere. No process.memoryUsage, process.resourceUsage, maxRSS, getrusage, /usr/bin/time -v, heap snapshots, dhat, or peak_alloc. (The --max-old-space-size hits under exec/ are fixtures asserting NODE_OPTIONS passthrough, unrelated.)
  2. hyperfine cannot report memory. It emits mean/stddev/median/user/system/min/max/times/exit_codes and has no memory capability at all. Both stacks' benchmarks are driven by it.
  3. The transport cannot carry a memory measure. Every upload uses --adapter shell_hyperfine (.github/workflows/benchmark.yml:128, .github/workflows/ci-performance-bencher-upload.yml:206), which parses hyperfine's time schema.
  4. The orchestrator drops everything but the mean. HyperfineCommand in pnpm/tasks/integrated-benchmark/src/work_env.rs:1139 deserializes command, command_name, mean. PhaseSummary has no byte-valued field.
  5. Neither fixture is workspace-shaped. pnpm11/benchmarks/fixture/ has a package.json and a lockfile and no pnpm-workspace.yaml. The orchestrator fixture (pnpm/tasks/integrated-benchmark/src/fixtures/) has a pnpm-workspace.yaml, but it is settings-only (storeDir, supportedArchitectures, allowBuilds) with no packages: key. Both are single-project-with-many-deps. The multi-project workspace install — pnpm's flagship shape, and the one that triggers this OOM class — is not benchmarked at all, for either stack.
  6. The TS bench is not a PR gate. benchmark.yml triggers on workflow_dispatch and push to main only, so a regression surfaces after merge. (pacquet-integrated-benchmark.yml does run on pull_request, so the two stacks are asymmetric here.)

Point 5 is the important one: even with perfect memory instrumentation, the current fixtures could not have reproduced pnpm/pnpm#13077.

Proposal

1. A multi-project workspace fixture

Add a fixture with N projects sharing heavy dependencies, as a new scenario. This is what reproduces the fan-out: many projects resolving one package concurrently against a cold cache.

Worth doing on its own merits — it closes a wall-clock coverage gap too, not just a memory one, and it applies to both stacks.

2. Peak RSS, measured once in the shared orchestrator

pnpm/tasks/integrated-benchmark is driven by both pnpm11/benchmarks/bench.sh and pacquet-integrated-benchmark.yml, so instrumenting it once covers pnpm, pacquet, and pnpr.

Measure externally rather than per-language. Peak RSS of the process tree is comparable across both stacks and is the thing that actually OOMs; V8 heap statistics and Rust allocator counters are not comparable to each other. On Linux (where the benches run) that is /usr/bin/time -v, getrusage(RUSAGE_CHILDREN).ru_maxrss, or cgroup v2 memory.peak.

If per-language detail is wanted later: Node has process.resourceUsage().maxRSS (a true high-water mark, no sampling, no GC-timing noise) and Rust has getrusage(RUSAGE_SELF).ru_maxrss, plus dhat/peak_alloc for allocation-level profiling. sysinfo is already a workspace dependency, though currently used only for process killing.

3. Transport

Emit Bencher Metric Format and upload with --adapter json alongside the existing hyperfine upload, rather than extending the hyperfine schema. bench.sh already post-processes per-scenario JSON with jq into bencher-results.json, so a parallel BMF file is the smallest change that avoids touching the time path.

4. Record-only, then gate

Land the measure ungated. Peak RSS across runs is not aggregated by hyperfine at all, so the noise profile is unknown and max-of-runs vs. mean-of-maxima needs a decision informed by real data. Add a Bencher threshold once there is a baseline.

5. A hard heap cap for a binary signal

Run the workspace scenario under --max-old-space-size. An OOM regression then fails CI outright — no threshold tuning, no flake. This is the cheapest high-signal guard, but it is only meaningful once the fixture from (1) exists.

Notes

Thresholds on a memory measure are inherently noisier than the deterministic alternative. Where a regression has a specific, assertable mechanism, a unit test is the better guard — pnpm/pnpm#13079 asserts that concurrent resolutions perform zero re-serializations, which is deterministic and runs on every PR in well under a second. The benchmark work above is the complement: it catches the regressions nobody thought to assert.


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

Activity

  1. github-actions commented on Jul 16, 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/019f6c60-d308-71cb-a327-f3a121db8d45

  2. github-actions commented on Jul 16, 2026

    @github-actions

    Triage result

    State: Ready to spec → applied state: needs design

    Product / parity: Affects both the TypeScript CLI (pnpm11/benchmarks/) and the Rust/pacquet stack (pnpm/tasks/integrated-benchmark/). Cross-stack parity work is required.

    Rationale:

    The issue is well-researched and proposes a 5-step plan with specific file references and mechanisms. However, several material design decisions remain open before implementation can begin in earnest:

    1. New measurement architecture in the shared integrated-benchmark Rust orchestrator — extending HyperfineCommand, PhaseSummary, and BenchmarkTargetDiagnostics to carry a memory dimension requires design review to avoid breaking the existing hyperfine time-metrics path.
    2. Noise characterization deferred — the issue itself states "max-of-runs vs. mean-of-maxima needs a decision informed by real data." Even the ungated landing (step 4) needs a concrete emission schema decided up front so future threshold work isn't blocked by incompatible data shape.
    3. Parallel Bencher transport — adding a second --adapter json upload alongside the existing --adapter shell_hyperfine requires workflow coordination across benchmark.yml and ci-performance-bencher-upload.yml, and the exact BMF schema for peak-RSS needs to be pinned.
    4. Multi-project workspace fixture scope — "N projects sharing heavy dependencies" needs a concrete definition (package count, dep graph shape) to reproduce the OOM class reliably without making the fixture too slow for PR gates.

    The work is clearly worthwhile and in scope; a spec pass to pin these four decisions would unlock a well-bounded implementation PR.

    Next step: Draft a technical design document covering: the orchestrator data-model changes, the BMF schema for peak RSS, the fixture shape, and the CI workflow changes. Once the design is settled, this can be relabeled state: accepted and implemented.


    Written by an agent (Oz, auto).

  3. Addin commented on Jul 19, 2026

    @Addin

    Hi @zkochan I think you should take a look at CodSpeed take a look at the Performance Instruments.

  4. transferred this issue frompnpm/pnpmon Sep 26, 2026
  5. zkochan commented on Nov 8, 2026

    @zkochan
    MemberAuthor

    Status check against main (2026-11-08).

    Point 3 is out of date: the Rust benchmark workflow now uploads Bencher Metric Format with --adapter json. Only the TypeScript benchmark still uses shell_hyperfine.

    Left: memory measurement, and a fixture with workspace projects.

    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

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions