What is Bun?
Bun features a native bundler that converts the dev codes/files into minified and merged (bundled) output files, a task runner for automating repetitive tasks, and a transpiler, which transforms one source code into another before execution. Other notable features include support for a range of Node and web APIs; the ability to use NPM, Node.js’ package manager; and increased performance, according to the Bun websites.
Amazing performance makes it special.
There are certain quick benchmarks created by the contributors of Bun:
- 14x faster than Next.js for reloading CSS
- Dist and node_modules are cleaned within a couple of seconds.
Jarred Sumner, a former front-end engineer at Stripe is the founder of Bun Framework. Bun was released publicly in 2022.
Advantages of Bun.js:
It was built to focus on three main things:
- Fast speed
- Comprehensive tools (bundler, transpiler, package manager).
Bun vs Node vs Deno:
Bun, however, comes with a lot of tooling baked in, a lot of speed, and a bunch of convenient practices.
Comparatively, Node.js is slower than Deno and Bun. The newer runtimes are between 2 to 3 times faster than the market leader, Node.js. Node.js offers about 75K Receive Packet Steering (RPS), while Deno goes around 180K and Bun goes around 195K. This is a huge difference.
Bun framework and Deno have similar performance however, 180K vs 195K isn’t a big difference. Deno uses flash server API Deno.serve and it performs pretty well.
Ultimately, Bun’s CPU usage is the same as others. However, Bun exhibits excellent performance since it utilizes less system resources and memory.
Why is Bun fast?
The Bun team attributes their performance:
- Tons of time was spent profiling, benchmarking, and optimizing.
- Using Zig, a general-purpose programming language, adds to its low-level memory control and lack of hidden control flow. No hidden memory allocations. No preprocessor, no macros.
To install Bun you need to execute the following commands:
curl -fsSL https://bun.sh/install | bash
# Manually add the directory to your $HOME/.bashrc (or similar)
To check the version:
You will notice that it has not reached the 1.0.0 version yet. It is still not production ready.
Certainly, Bun is new, and it has bugs but there are a lot of expectations placed on it from both Sumner and developers. Sumner is aware of this and attributes a portion of its flaws to the absence of widespread testing. Of this, he says, “bun doesn’t have enough test coverage and that’s why it’s so buggy.” Sumner stated, “I’ve been coming from the perspective of ‘it needs to work as much as possible with the existing ecosystem because people shouldn’t have to rewrite their code’ but maybe I should start thinking more about what if we make/what new things are possible because the APIs bun enables.”
If you want to know more about it, reach us.