belgattitude / nextjs-monorepo-example

Collection of monorepo tips & tricks
MIT License
1.64k stars 214 forks source link

RFC: Move to pnpm #2771

Open belgattitude opened 2 years ago

belgattitude commented 2 years ago

Is it worthy to move to pnpm and reduce carbon emissions ?

WIP PR in https://github.com/belgattitude/nextjs-monorepo-example/pull/2765

Criteria

Checklist

Tested on this monorepo with nextjs 12.3.1. At first sight pnpm is faster, but going into details... not sure.

Check Yarn 4rc Pnpm 7 Winner
Laptop (cold cache) 71.410 ± 1.835 34.696 ± 1.413 pnpm (x2)
Laptop (warm cache) 21.576 ± 0.390 10.780 ± 0.881 pnpm (x2)
Github action (cold) ±2m ±1m20 pnpm (x1.8)
Github action (warm) ±1m20 ±50s pnpm (x1.3)
Vercel (warm) ±2m20 ±3m30s yarn
Vercel (ssr lambda size) 25MB (8.88Mb) 50MB (25Mb zip) yarn
Vercel (api routes) 68Mb (22Mb zip) 49.4 MB (22.6Mb zip) pnpm

PS: locally bench were done with hyperfine, timings on github are based on few runs and include the install and the action/cache (de-)compression. As yarn already compress the archives, the post compression is very fast (zstd is disabled for files that does not compress)

Links

belgattitude commented 1 year ago

Not sure to move to pnpm. Might be too early

So in the end, yarn still rocks for this repo example and covers most needs... the one lacking most is pnpm deploy (but it's okay with standalone support in nextjs or turbo with docker)

Benchmarks

📥 Install speed

Measured through github actions. See latest run

With cache

CI Scenario Install CI fetch cache Total Cache size CI persist cache
yarn4 mixed-compression 34s 3s 37s 201Mb (±5s)
yarn4 no compression 26s 2s 28s 155Mb (±8s)
pnpm8.5.1 16s 9s 25s 253Mb (±30s)

Without cache

CI Scenario Install Diff with cached run
yarn4 mixed-compression / no cache ±83s slower than 37s
yarn4 no compression / no cache ±45s slower than 28s
pnpm8 / no cache ±48s slower than 25s