Why Should I Care About Bun?
Bun is getting hyped up a lot lately. There’s a ton of videos and articles explaining what it is, and how powerful it is. In this post, I wanted to share a few important facets that should make its value understandable for anyone working in or near software development, and how you can very quickly try them out for yourself.
You can read more about Bun’s benefits on their website, but here’s a quick summary:
It’s incredibly fast
Typescript works out-of-the-box
A lot of basics are provided without needing separate library installs, such as environment variables, SQLite3, top level await support, and more
Bun was written in Zig, which is a low-level programming language like Rust and C. Zig has no hidden control flow, no hidden memory allocations, and no preprocessor. Bun is one of the first popular large-scale applications built off of Zig, so Zig is also getting more attention as a result. You can read more about Zig here.
How can I quickly experience the benefits of Bun?
There is a really easy way to see the speed benefits of Bun: Create a new React web app.
1. Open terminal and change your directory to an empty test folder
2. Run this command with the time prefix so that terminal outputs how long it takes to run everything:
time npx create-react-app node-app
3. Take note of how long this takes. For myself, on an M1 Mac, it finished and outputted the following:
npx create-react-app node-app 20.04s user 7.65s system 143% cpu 19.269 total
About 20 seconds. Not too bad!
Let's try the same thing but with Bun:
time bun create react ./node-app
The output for my setup was the following:
bun create react ./node-app 0.87s user 0.23s system 56% cpu 1.952 total
0.87 seconds! Yikes. That’s a striking difference! I like to use this example because it’s simple, and there’s a lot of installs that have to take place to get a React web app ready to go.
Sounds great! Should my team immediately try to use it for our project?
Not so fast! Bun is still in an experimental stage, so use caution. I would encourage you to try it out in isolated environments. The reason is because it doesn’t yet have 1:1 support as a drag-and-drop substitute for npm, one of Bun’s largest competitors.
As of today, here are a few major limitations I’ve experienced while trying out Bun, that directly impact my own work:
The major server library Express isn’t supported yet. However, it’s being actively worked on as noted here
React Native transpiling is not supported yet. However, from my own testing, I’ve been able to use Bun just as a package manager without issue
Bun has other limitations currently, but most of the rest don’t impact my own workflow, but they may be more relevant to you. You can see their roadmap here, and Bun’s current limitations here.
Written by David Crawford, Mobile App Developer