Disk Usage Compared

Disk use has two parts, the project and the tool's cache. When they share hard-linked files, the honest total is du over both in a single call, since du counts each file once per run.

disk.sh: project, cache and combined size after the last warm installShell
#!/usr/bin/env bash
# disk.sh - what each package manager left on disk after bench.sh's last warm install.
cd ~/v5-ch1/bench
kb() { du -sk "$@" | awk '{ s += $1 } END { printf "%.1fM", s / 1024 }'; }
printf '%-9s %8s %7s %8s %9s\n' tool project files cache together
for t in npm pnpm bun yarn-pnp yarn-nm; do
  printf '%-9s %8s %7d %8s %9s\n' "$t" "$(kb "$t")" "$(find "$t" -type f | wc -l)" \
    "$(kb "cache/$t")" "$(kb "cache/$t" "$t")"
done
Output
tool       project   files    cache  together
npm           5.3M     741     9.2M     14.5M
pnpm          5.7M     731     7.9M      9.3M
bun           5.2M     740     6.6M      7.2M
yarn-pnp      0.6M       5     5.1M      5.6M
yarn-nm       5.4M     777     5.1M     10.5M

Every node_modules tree weighs 5.2-5.7 MB in about 740 files. The difference is duplication. npm 2,036 keeps compressed tarballs in its cache and extracted copies in the project, 14.5 MB together. pnpm 69,400 and Bun 73,307 hard-link the project to their caches, so a second BookNest would cost them only 1.4 MB and 0.6 MB. Yarn 11,798 PnP keeps five files in the project and 5.6 MB in total, the smallest footprint; its node-modules linker extracts the zips and doubles that. Across twenty projects on a laptop, these ratios matter more than seconds.