Skip to content

Latest commit

 

History

History
447 lines (373 loc) · 26.5 KB

README.md

File metadata and controls

447 lines (373 loc) · 26.5 KB

Install benchmark

Times cold, warm and repeat installs of one entry package with every supported package manager, and records time, peak memory and CPU for each run.

Before benchmarking a fix for repeated work, node bench/premise.ts <lockfile>... counts how often it repeats in real lockfiles. See perf.md.

./bench.sh                         # every runner and fixture, then the charts
./bench.sh -r upm,pnpm12 -f nuxt   # a subset
./bench.sh --cold 5 --warm 5       # more samples
./bench.sh --registry vlt          # every manager against vlt's registry
./bench.sh --registry replay       # against a local recording of npm's, see below
./bench.sh -f tiny --cold 1 --warm 0 --repeat 0  # quick, refreshes charts/size.svg
node report.ts results/<stamp>.jsonl  # markdown tables (bench.sh does not print them)
node chart.ts                      # re-render the charts for the newest run

Needs: Linux, Node 24 (the .ts tools run with type stripping, no build), Perl for measure.pl, and jup and vlt in node_modules (node ../upm install --frozen-lockfile). zstd is optional: without it the size chart has no CI restore estimate.

option default meaning
-r, --runners all comma separated runner names
-f, --fixtures nitro,nuxt,next comma separated fixture names
--cold/--warm/--repeat <n> 3 / 3 / 3 samples per phase for each runner and fixture
--keep off keep each project and cache after its fixture
--min-free <mb> 3072 stop before the disk gets this full
-o, --out <file> results/<stamp>.jsonl results file
--registry <name> npm registry for all managers, see below
--no-chart off skip the SVG charts
--dry-run off print the plan and exit

BENCH_WORK moves the work directory (default ~/.cache/upm-bench, or under XDG_CACHE_HOME). Each runner's output goes to <work>/logs/<runner>-<fixture>.log.

What a run does

  1. Rebuilds ../dist so upm is always this working tree.
  2. Downloads every manager with jup (vlt comes from node_modules) and runs its --version once, so no download lands in a timed run.
  3. For each fixture, runs the three phases below in order, in rounds: each round runs every runner once, starting one runner later than the round before. A slow minute of network then lands on every manager, not on whichever ran its samples back to back. Then it deletes the fixture's projects and caches (unless --keep).
  4. Writes results/<stamp>.jsonl and, beside it, charts for each phase and measure: <stamp>.<phase>.svg, .memory.svg, .cpu.svg, plus <stamp>.size.svg. A full suite (all runners, default fixtures) also refreshes the committed charts/ that the main README links to. Size does not depend on the fixtures, so any run of all runners on the default registry refreshes charts/size.svg and the sizes quoted in the main README, between <!-- size:<runner> --> (or size:<runner>:packed) and <!-- /size -->.

Core dumps are off (ulimit -c 0): a crash counts as a failed run, not a heap-sized file in the repo. Any core.<pid> newer than the run is deleted on exit.

Registry

--registry separates the two things a benchmark mixes: the manager and the registry behind it. Run the same managers on two registries and each manager's rows show what the registry changed.

value registry
npm each manager's default: registry.npmjs.org, or its proxy for yarn 1
vlt https://registry.vlt.io/$BENCH_VLT_ACCOUNT/npm/
replay a recording of npm's by record.sh, served by registry.ts
<url> any npm-compatible registry

vlt serves npm packages only under an account, and only with its token, so vlt needs BENCH_VLT_ACCOUNT (a vlt.io account or organization) and BENCH_REGISTRY_TOKEN. A token for a url is optional.

BENCH_VLT_ACCOUNT=<account> BENCH_REGISTRY_TOKEN=<token> ./bench.sh --registry vlt
node report.ts results/<npm run>.jsonl results/<vlt run>.jsonl

Before each install, outside the timed command, runners.sh writes the registry and token to the project's .npmrc, which upm, npm, pnpm, yarn 1, bun, deno, aube and nub read. yarn 4 gets YARN_NPM_REGISTRY_SERVER and YARN_NPM_AUTH_TOKEN, vlt gets --registries npm=<url> with VLT_REGISTRY and VLT_TOKEN. Both yarns send a token only for scoped packages unless told to always send it, so they are.

Each row records registry. The reports and charts show a row from another registry as its own manager row, with the registry after the version. A full suite on another registry does not replace the committed charts/.

Record and replay

The live registry changes under a benchmark: the CDN caches some urls and not others, the network has slow minutes, and new releases change the graph. registry.ts takes that out. It is a small Node server with two modes:

  • record proxies every request to the upstream registry (https://registry.npmjs.org) and keeps the request, the response and its timing: time to first byte and to the last, from when the request leaves on a connected socket. A wait for one of the proxy's sockets or a new connection's handshake is not counted, or a manager's burst of requests would record its queue as the registry's latency.
  • replay answers from the recording alone. It waits the recorded time to first byte, then sends the body in 64 KiB chunks spread over the recorded transfer time. Each request gets its manager's first recorded body, and the median time of every recorded sample of that url, by any manager, so all wait the same for the same document or tarball: per abbreviated or full document, but one for a tarball, whatever Accept it was asked with. The wait counts from the request's arrival, reading the body from disk included. Bodies are read per response, not held: a full recording is over a gigabyte.
  • Responses keep the CDN's age and cache-control, so a manager that honors HTTP caching revalidates when it would have live.
./bench.sh --registry replay       # records what is missing, then times against the recording
./record.sh -r upm,pnpm12 -f tiny  # records by hand, adding to the recording
rm -rf recording                   # start over: the next replay records everything again

A replay first records, untimed, each runner and fixture the recording lacks at that runner's version, so the first full replay runs every manager through record mode once and later ones touch no network. upm counts at any build. recording/recorded lists what is there; a pair with a failed run is left out and recorded again next time.

The recording keeps one version of each manager. Each uses the server under its own path, /~<runner>/<version>/, so every response is kept as that manager's. When a manager is recorded at a new version, registry.ts settle drops what its older version recorded, on every fixture, and any body nothing else uses; the next replay records the other fixtures again for the new version.

record.sh runs bench.sh through the server in record mode: three cold rounds, one warm, one repeat. The first request for a url meets the CDN's miss and the proxy's new connections. More rounds give the median a typical sample, so that cost does not land on whichever manager asked first. Other options go to bench.sh; --port (default 4880), --upstream and -o <dir> go to the server.

The recording lives in BENCH_RECORDING (default bench/recording, gitignored: a full one is gigabytes, mostly tarballs): meta.json, index.jsonl (one line per response), bodies/<sha256> and recorded. JSON bodies are stored with the upstream origin replaced by the server's, so tarballs come through it too, and a recording replays on the port and scheme it was recorded on. Delete the directory to record from scratch.

  • TLS, as on the live registry. A new recording is served over https with a certificate from its own CA (tls/ca.pem, made with openssl), so each manager pays its handshakes and encryption. HTTP/2 is offered by ALPN beside HTTP/1.1, as npm's CDN does: deno, aube and nub take it, the rest stay on HTTP/1.1, and the server logs which each speaks. Each manager is told to trust the CA in its own way, only for the install: NODE_EXTRA_CA_CERTS (upm, npm, pnpm, yarn 1, bun, vlt), DENO_CERT, SSL_CERT_FILE (aube, nub) and yarn 4's YARN_HTTPS_CA_FILE_PATH. record.sh --plain records over http instead.

  • The release-age gate counts back from the recording's start, not from now (BENCH_AGE_FROM), in record and replay alike. Otherwise a week-old recording would let managers pick versions released since, which it does not hold. npm and upm get the exact date as before.

  • A request matches on method, url, Accept and Accept-Encoding. A manager asking a little differently gets the closest recorded answer the live registry could have given, never an abbreviated document for a full one, and a body it cannot decode is sent plain. The server logs each near match and miss to <work>/logs/registry.log, and its last line counts them. A miss is a 404, so a stale recording shows up as failed runs. A manager can also ask for a slightly different set of urls each run: upm fetches a varying share of the foreign-platform version documents of an optional binding, so an odd miss of one is expected and harmless.

  • Not the live registry: a handshake costs the CPU but not the round trips it would to a CDN, recorded times come from the proxy's own pooled connections, and the server shares the machine's CPU with the manager. Concurrent responses are not throttled to a shared bandwidth. Compare managers on one recording; check a claim about network behavior against the live registry too.

  • BENCH_REPLAY_LATENCY=<factor> scales every recorded time; 0 serves at loopback speed.

Fixtures

Each fixture is a package.json with pinned versions, so every manager starts from the same graph. A fixture folder is copied whole, so one can hold workspaces.

fixture entry package
nitro nitro@3.0.260903-beta
nuxt nuxt@4.5.2
next next@16.3.4, plus react and react-dom@19.2.0, which it needs
tiny ms@2.1.3, no dependencies. Not in the default suite; use -f tiny
monorepo 46 workspaces, about 790 packages. Not in the default suite; -f monorepo

tiny is for A/B tests of startup or thread changes, where a ~150 ms install shows costs the big fixtures hide. nuxt reaches @isaacs/cliui, which uses alias specs (string-width-cjs@npm:string-width@^4.2.0), so its tree has both an ESM and a CJS copy of string-width, strip-ansi and wrap-ansi.

monorepo is for what grows with workspaces: the no-op install, and linking and resolving many tops. Its workspaces sit under apps/*, packages/** and tools/*, apps on Next.js, Vite, VitePress, Storybook and Fastify over shared libraries, and depend on each other by *, which npm and yarn 1 read too (not workspace:*). pnpm-workspace.yaml names the same patterns for pnpm, aube and nub. It holds package.json files only: a real monorepo's glob also walks its source folders, which this one has none of.

Phases

Run in this order, so one download fills the cache for the rest.

phase state before the install what it costs
cold no cache, no lockfile, no node_modules resolve + download + link
warm cache and lockfile kept, every node_modules deleted read lockfile + link
repeat nothing deleted finding there is nothing to do

warm matters most for CI with a restored cache. repeat is what an editor or a predev hook pays when install had nothing to do.

Runners

upm runs ../dist/upm.mjs, the same file as the published bin. Its version is dist-<sha>, with -dirty when src/ has uncommitted or untracked changes. Set UPM_CLI=../upm to measure the source entry instead (src-<sha>, slower to start, not what users run).

Other managers come from jup (a dev dependency, so versions do not depend on the machine). They are not run through jup: runners.sh finds each manager's own entry in the jup store and starts it directly, a native binary as is and a JavaScript entry on the same node as upm. A jup shim would add a Node process of about 40 ms and 56 MB. jup has no vlt yet, so vlt is a dev dependency itself and runs from node_modules the same way.

runner command (lifecycle scripts off in all)
upm node ../dist/upm.mjs install --store <cache>
npm node <npm> install
pnpm11 node <pnpm@11> install --store-dir <cache>
pnpm12 <pnpm@12> install --store-dir <cache>
yarn1 node <yarn@1> install --cache-folder <cache>
yarn4 node <yarn@4> install (node-modules linker)
bun <bun> install
deno <deno> install --node-modules-dir=auto
aube <aube> install
nub <nub> install
vlt node <vlt> install --cache <cache>

node is not a runner: Node 24 has no install command and this build ships no npm.

Fairness

  • Projects outside any other project. aube and nub install into the nearest directory above the project with workspaces in its package.json or a pnpm-workspace.yaml, without checking the project is a member. Under bench/.work, that was this repo: they installed upm's own dev dependencies there and reported the time as the fixture's. So the work directory defaults to outside the repo, and bench.sh refuses one with a package.json or workspace file anywhere above it.
  • Private caches. Each manager's cache lives under <work>/<runner>-<fixture>/cache, so "cold" is a directory delete and no real cache is touched. pnpm needs both --store-dir and XDG_CACHE_HOME: with the store alone, a "cold" pnpm read the real metadata cache and finished nuxt in 696 ms instead of 2.98 s. The others use npm_config_cache, YARN_GLOBAL_FOLDER, BUN_INSTALL_CACHE_DIR, DENO_DIR, AUBE_STORE_DIR, vlt's --cache and the XDG directories. Each cold row records the cache size; a successful cold run with a cache under 1 MB gets a warning, as the manager may have used a shared cache, and so does any successful run that leaves no packages in the project.
  • Lifecycle scripts are off everywhere, because upm cannot run them.
  • A 1-day release-age gate for all, set by the harness and not left to the machine's npmrc, yarnrc or environment, so every machine resolves the same versions (BENCH_MIN_AGE_DAYS changes it). Each manager gets its own key: npm's min-release-age (upm, npm), pnpm's minimum-release-age (pnpm, aube, nub), yarn 4's npmMinimalAgeGate, bun's --minimum-release-age, deno's --min-dep-age and vlt's --before <date>. runners.sh has the details.
  • CI is unset, since pnpm turns on --frozen-lockfile under CI and a cold run fails. Colors, update notices, audit, fund and telemetry are off for all.
  • Packages are counted by inode, following symlinks. Isolated layouts hold both a real directory and links to it, and aube and nub link to a global store, so a plain file count would not compare.

Real differences, left in on purpose:

  • yarn 1 has no release-age gate, so it can install a version the others hold back. Neither has vlt: its install ignores --before (1.2.0 and 1.3.0), so the flag has no effect yet. bun applies the gate with a stability rule of its own and can pick an older version than the rest.
  • yarn 4 uses nodeLinker: node-modules, since Plug'n'Play writes no node_modules to delete or count. A cold yarn 4 run starts with an empty yarn.lock, or it treats the repo root as its project.
  • yarn 1 uses its default registry.yarnpkg.com, a proxy of the npm registry. vlt has no default registry, so it gets --registries npm=https://registry.npmjs.org/.
  • Optional-dependency rules differ, so counts can differ by one or two packages. A manager that is fast because it installed less shows up in the counts.
  • Layouts and hardlinks versus copies change the apparent size on disk.

Time, memory and CPU

Only the install command is measured, by perl measure.pl, not the setup around it.

field meaning source
ms wall time CLOCK_MONOTONIC around fork and wait4
user_ms, sys_ms CPU time of the whole process tree wait4() rusage, exact
rss_bytes peak memory of the whole process tree /proc VmHWM summed, sampled every 10 ms
rss_process_bytes peak memory of the largest single process wait4() ru_maxrss, exact

Perl, because neither bash nor Node can read a child's rusage. Worker threads are part of their process, so they always count. A daemon that leaves the tree is not counted.

rss_bytes is what reports and charts show. It adds up the own peak (VmHWM) of each process alive at the same time, so helpers and wrappers count, and it is never below rss_process_bytes. Processes that peak at different times can make it read above the true combined peak. For a single-process manager the two match within about 1 MB. It can miss growth only in a process's last 10 ms.

  • CPU is user + sys, not divided by wall time; a manager using many cores has more CPU than wall time.
  • A run that fails before measure.pl starts has no memory or CPU fields, and its time comes from the shell.
  • Older results, from before managers ran from their own entry, include the jup launcher: about 40 ms, 40 ms of CPU and 56 MB for bun, deno, aube and pnpm 12.

Output

results/<stamp>.jsonl (gitignored) has one object per timed run:

{
  "runner": "upm",
  "version": "dist-c658757",
  "fixture": "nitro",
  "phase": "cold",
  "iter": 1,
  "ms": 936,
  "ok": true,
  "bytes": 45317721,
  "packages": 63,
  "cache_bytes": 52428800,
  "runner_bytes": 142301,
  "runner_packed_bytes": 49152,
  "rss_bytes": 264245248,
  "rss_process_bytes": 264245248,
  "user_ms": 1102,
  "sys_ms": 315,
  "ts": "2026-09-09T23:08:28Z",
  "registry": "npm"
}

bytes and packages describe node_modules. runner_bytes is the manager's own size on disk: its directory in the jup store, or dist/ (src/ with UPM_CLI) for upm. runner_packed_bytes is the same files as a POSIX tar through zstd -T0, the way actions/cache packs them. The size chart turns it into an estimated restore time, fitted to measured actions/cache restores on ubuntu-latest (RESTORE in chart.ts). The warm time chart loops between the measured installs and the same installs moved right by that estimate. With reduced motion it stays on the measured view.

report.ts

node report.ts <file.jsonl>... prints a markdown table per phase, then memory and CPU tables when the results have them. Options: --metric min|median|mean|max (default median), --phase (repeatable) and --measure time|memory|cpu.

results.ts holds the rules shared with the charts:

  • Only successful samples count. Partial failures show their count; an all-failed group shows its time to failure and can never win.
  • Bold marks the lowest value per phase and fixture, excluding failures and cache warnings. It is a ranking, not a significance test.
  • Sample counts are real counts per group. Different versions of a manager get their own rows, so several files never mix builds.
  • Missing pairs say not run. A bad JSONL line reports its file and line number.

chart.ts

Self-contained SVGs for READMEs, one per phase, since phase times differ by orders of magnitude.

node chart.ts                                  # newest results/*.jsonl, all phases
node chart.ts results/<stamp>.jsonl -o charts/ # charts/{cold,warm,repeat}.svg
node chart.ts --phase warm -o docs/warm.svg    # one phase, exactly that file
node chart.ts --measure memory                 # or cpu: <stamp>.<phase>.memory.svg
node chart.ts --size                           # <stamp>.size.svg
node chart.ts --size --readme ../README.md     # also fills the README's size markers

It also takes several result files and --metric like report.ts, and prints the paths it writes. "Newest" means most recently modified, not last by name.

  • One row per manager and version, ranked by score. For each fixture, a manager's time is divided by the best time there; the score is the geometric mean of those ratios. Only managers with a clean result in every fixture are ranked; the rest follow with a reason.
  • Shapes are fixtures (circle nitro, square nuxt, diamond next, triangle tiny, hexagon monorepo) and colors are phases (blue cold, orange warm, purple repeat). A light band marks upm. Each row ends with its fastest–slowest range.
  • A logo shows what each manager runs on: Node.js, Rust (Ferris), Bun or Deno. See RUNTIME in chart.ts and the artwork in icons.ts.
  • The axis is linear from zero, so twice as far right is twice as long.
  • Failures stay visible: all-failed groups are hollow red markers at their time to failure, partial failures get a red outline. Small cold caches and empty projects get a footnote.
  • Memory and CPU charts use the same layout and rules, scored on their own values.
  • --size draws bars of each manager's size on disk, smallest first, with the ratio to upm and, when recorded, its packed size and estimated CI restore.
  • Every chart has one canvas size (WIDTH × HEIGHT in chart.ts), so they line up in a README grid. Rows stretch to fill spare height; only a chart too tall for it grows.
  • The chart follows the viewer's color scheme: colors are drawn light, and a prefers-color-scheme: dark style swaps each for its pair in DARK in chart.ts. Add any new color there. The SVG has no scripts, fonts or external files. Open it directly to see exact values in marker tooltips.

For a PNG (light): rsvg-convert --zoom 2 results/<stamp>.cold.svg -o cold.png. After a layout change, regenerate a chart and look at it at its embedded size.

A/B of upm builds: ab.sh

bench/ab.sh <mode> <pairs> <label:dist> <label:dist>... -- <fixture>...
bench/ab.sh warm 10 base:/tmp/base/dist new:dist -- nuxt next

Compares two or more upm builds (each a directory with upm.mjs), alternating their order each pair. Every run goes through measure.pl into a rows file under .work/ab/, then summ.mjs prints medians and paired differences against the first build, with how many pairs the new build won.

  • Modes: cold, warm and repeat as above, with a private store per build, and:

    • cache: a warm store with no lockfile or node_modules, as on a fresh clone. Primed once per build; each run removes upm.lock and every node_modules, then installs.
    • lock: upm lock alone in a fresh project and store.
    • relock: upm lock over a warm store: primed once per build, upm.lock removed per run. The warm resolve without the link, e.g. AB_ARGS=--prefer-offline.

    cache, lock and relock fail if the builds' upm.lock differ.

  • A fixture is a name in fixtures/, or a path to a project directory (with a /), such as a workspace monorepo. Either is copied whole, without node_modules and upm.lock, once per project, so repeat keeps upm's up-to-date stamps. warm and cache delete every node_modules, a workspace's too.

  • Projects live under BENCH_WORK, outside the repo like bench.sh's.

  • Env: AB_ENV / AB_ENV_<label> add environment for all builds or one, AB_ARGS adds arguments to every command, AB_OUT names the rows file, AB_KEEP=1 keeps the work directories. The release-age gate is 1 day (BENCH_MIN_AGE_DAYS), as in bench.sh, so a primed store answers most picks unasked for a day even without --prefer-offline.

  • It holds .work/ab/.lock (via flock), so two runs on one machine wait for each other.

  • Use ten or more pairs before claiming a result: ../.agents/perf.md.

Startup and install profile: profile.sh

bench/profile.sh                  # 20 runs, `upm i` repeat on tiny
bench/profile.sh -n 50 -f nitro --warm

Builds dist/ once, then times, in rounds, an empty Node script, --version of this tree's upm, of the published upm and of pnpm 12's native binary (@pnpm/exe.<platform>), and upm i. It prints the median wall time, peak RSS and CPU of each, and for upm the difference from bare Node. A second table shows what getting each manager costs before it runs: curl downloads the published upm tarball and pnpm's binary package from registry.npmjs.org and tar unpacks each into an empty directory, timed separately.

It needs only bash, Node, curl and tar, so it runs on CI images without Perl: the harness times spawn to reap, and a --require hook writes each Node child's process.resourceUsage() at exit. The hook costs about 1 ms per start, the same for every Node command. pnpm's binary is not Node, so its peak RSS (~) is sampled from /proc in separate runs, and it has no CPU reading. --warm and --cold reset the project before each install as in ab.sh; see the script's header for options.