Me using JavaScript#
I developed my first JavaScript project in 2016 when I was in Uni. It was research project to build Ground Control Station (GCS) Dashboard using Node.js for KOMURINDO-KOMBAT — It's competition held by LAPAN. Fortunately, my team and I secured 3rd place.
Why Node.js? — Simply because it's asynchronous and I need to handle realtime data from serial communication to transmit them over WebSocket. Plus, I developed the user interface as a web application, so using one language for the entire project made sense. You can find the repository for my first javascript project on KASUARI-Node.
Well, that's my first time fly into JavaScript world!
Package Manager#
I used to rely on npm as it's the default package manager for Node.js. However, as I developed more projects, I encountered new package managers like Yarn, PNpM, and Bun.
Managing JavaScript dependencies can lead to a massive node_modules
folder, which requires efficient algorithms and strategies. Each package manager has its pros and cons. You can read more about this in this Medium article.
For me, performance is the top priority. So, I'm curious to benchmark and compare the performance of dependency installations using different strategies for this website, which is built with the Next.js framework.
Benchmark#
It all started when I came across this Benchmarks of JavaScript Package Managers page and noticed that the Bun package manager wasn't included. The benchmarks are generated using a script from the pnpm.io repository.
I thought, "Hmm, should I contribute to the repository and add a commit?" It seemed like a simple task — just add Bun to their list of package managers, right? But as I looked into it, I found some bugs and areas for improvement. So, I decided to take on the challenge. Plus, it was a Sunday, and I had plenty of time to explore.
Result#
The section below was originally generated by the script. I've made a few modifications — I removed the app's package.json
line and adjusted the image source.
Benchmarks of JavaScript Package Managers#
Last benchmarked at: Sep 30, 2024, 00:13 AM (daily updated).
This benchmark compares the performance of bun, npm, pnpm, Yarn Classic, and Yarn PnP (check Yarn's benchmarks for any other Yarn modes that are not included here).
Here's a quick explanation of how these tests could apply to the real world:
clean install
: How long it takes to run a totally fresh install: no lockfile present, no packages in the cache, nonode_modules
folder.with cache
,with lockfile
,with node_modules
: After the first install is done, the install command is run again.with cache
,with lockfile
: When a repo is fetched by a developer and installation is first run.with cache
: Same as the one above, but the package manager doesn't have a lockfile to work from.with lockfile
: When an installation runs on a CI server.with cache
,with node_modules
: The lockfile is deleted and the install command is run again.with node_modules
,with lockfile
: The package cache is deleted and the install command is run again.with node_modules
: The package cache and the lockfile is deleted and the install command is run again.update
: Updating your dependencies by changing the version in thepackage.json
and running the install command again.
Satrya Personal Website#
action | cache | lockfile | node_modules | bun | npm | pnpm | Yarn | Yarn PnP |
---|---|---|---|---|---|---|---|---|
install | 3.4s | 48.8s | 23.9s | 30.5s | 18.1s | |||
install | ✔ | ✔ | ✔ | 127ms | 493ms | 412ms | 267ms | n/a |
install | ✔ | ✔ | 1.6s | 3s | 2.1s | 5.6s | 5.7s | |
install | ✔ | 1.5s | 5s | 6.6s | 21.9s | 14.1s | ||
install | ✔ | 1.5s | 14.5s | 26.6s | 5.5s | 5.3s | ||
install | ✔ | ✔ | 96ms | 495ms | 1.1s | 13.8s | n/a | |
install | ✔ | ✔ | 30ms | 403ms | 425ms | 268ms | n/a | |
install | ✔ | 32ms | 451ms | 15.5s | 11.4s | n/a | ||
update | n/a | n/a | n/a | 4.7s | 38.3s | 6.4s | 40.5s | 4.7s |
Conclusion#
I found that Bun came out as the winner in this benchmark. Keep in mind, the results may vary depending on network speed and the machine used. For this test, I used a MacBook Pro M3 with a network speed of 50Mbps.