Loading source
Pulling the file list, source metadata, and syntax-aware rendering for this listing.
Source from repo
pnpm 10.x reference skill covering workspaces, catalogs, patches, peer deps, overrides, and CI/CD caching strategies.
Files
Skill
Size
Entrypoint
Format
Open file
Syntax-highlighted preview of this file as included in the skill package.
references/best-practices-performance.md
1---2name: pnpm-performance-optimization3description: Tips and tricks for faster installs and better performance4---56# pnpm Performance Optimization78pnpm is fast by default, but these optimizations can make it even faster.910## Install Optimizations1112### Use Frozen Lockfile1314Skip resolution when lockfile exists:1516```bash17pnpm install --frozen-lockfile18```1920This is faster because pnpm skips the resolution phase entirely.2122### Prefer Offline Mode2324Use cached packages when available:2526```bash27pnpm install --prefer-offline28```2930Or configure globally:31```ini32# .npmrc33prefer-offline=true34```3536### Skip Optional Dependencies3738If you don't need optional deps:3940```bash41pnpm install --no-optional42```4344### Skip Scripts4546For CI or when scripts aren't needed:4748```bash49pnpm install --ignore-scripts50```5152**Caution:** Some packages require postinstall scripts to work correctly.5354### Only Build Specific Dependencies5556Only run build scripts for specific packages:5758```ini59# .npmrc60onlyBuiltDependencies[]=esbuild61onlyBuiltDependencies[]=sharp62onlyBuiltDependencies[]=@swc/core63```6465Or skip builds entirely for deps that don't need them:6667```json68{69"pnpm": {70"neverBuiltDependencies": ["fsevents", "cpu-features"]71}72}73```7475## Store Optimizations7677### Side Effects Cache7879Cache native module build results:8081```ini82# .npmrc83side-effects-cache=true84```8586This caches the results of postinstall scripts, speeding up subsequent installs.8788### Shared Store8990Use a single store for all projects (default behavior):9192```ini93# .npmrc94store-dir=~/.pnpm-store95```9697Benefits:98- Packages downloaded once for all projects99- Hard links save disk space100- Faster installs from cache101102### Store Maintenance103104Periodically clean unused packages:105106```bash107# Remove unreferenced packages108pnpm store prune109110# Check store integrity111pnpm store status112```113114## Workspace Optimizations115116### Parallel Execution117118Run workspace scripts in parallel:119120```bash121pnpm -r --parallel run build122```123124Control concurrency:125```ini126# .npmrc127workspace-concurrency=8128```129130### Stream Output131132See output in real-time:133134```bash135pnpm -r --stream run build136```137138### Filter to Changed Packages139140Only build what changed:141142```bash143# Build packages changed since main branch144pnpm --filter "...[origin/main]" run build145```146147### Topological Order148149Build dependencies before dependents:150151```bash152pnpm -r run build153# Automatically runs in topological order154```155156For explicit sequential builds:157```bash158pnpm -r --workspace-concurrency=1 run build159```160161## Network Optimizations162163### Configure Registry164165Use closest/fastest registry:166167```ini168# .npmrc169registry=https://registry.npmmirror.com/170```171172### HTTP Settings173174Tune network settings:175176```ini177# .npmrc178fetch-retries=3179fetch-retry-mintimeout=10000180fetch-retry-maxtimeout=60000181network-concurrency=16182```183184### Proxy Configuration185186```ini187# .npmrc188proxy=http://proxy.company.com:8080189https-proxy=http://proxy.company.com:8080190```191192## Lockfile Optimization193194### Single Lockfile (Monorepos)195196Use shared lockfile for all packages (default):197198```ini199# .npmrc200shared-workspace-lockfile=true201```202203Benefits:204- Single source of truth205- Faster resolution206- Consistent versions across workspace207208### Lockfile-only Mode209210Only update lockfile without installing:211212```bash213pnpm install --lockfile-only214```215216## Benchmarking217218### Compare Install Times219220```bash221# Clean install222rm -rf node_modules pnpm-lock.yaml223time pnpm install224225# Cached install (with lockfile)226rm -rf node_modules227time pnpm install --frozen-lockfile228229# With store cache230time pnpm install --frozen-lockfile --prefer-offline231```232233### Profile Resolution234235Debug slow installs:236237```bash238# Verbose logging239pnpm install --reporter=append-only240241# Debug mode242DEBUG=pnpm:* pnpm install243```244245## Configuration Summary246247Optimized `.npmrc` for performance:248249```ini250# Install behavior251prefer-offline=true252auto-install-peers=true253254# Build optimization255side-effects-cache=true256# Only build what's necessary257onlyBuiltDependencies[]=esbuild258onlyBuiltDependencies[]=@swc/core259260# Network261fetch-retries=3262network-concurrency=16263264# Workspace265workspace-concurrency=4266```267268## Quick Reference269270| Scenario | Command/Setting |271|----------|-----------------|272| CI installs | `pnpm install --frozen-lockfile` |273| Offline development | `--prefer-offline` |274| Skip native builds | `neverBuiltDependencies` |275| Parallel workspace | `pnpm -r --parallel run build` |276| Build changed only | `pnpm --filter "...[origin/main]" build` |277| Clean store | `pnpm store prune` |278279<!--280Source references:281- https://pnpm.io/npmrc282- https://pnpm.io/cli/install283- https://pnpm.io/filtering284-->285