Back to all articles

05 Aug 2022 • 4 min read

What Is Bun and Does It Live Up To The Hype?

featured image

Fullstack web developers are no strangers to new projects promising to make their lives easier, only to be let down after the hype dies down. One only has to look at examples like V to see why new projects with lofty claims are often taken with a grain of salt by veterans. However, when Bun, a new JavaScript bundler, was announced, there were a couple of very good reasons why a lot of people took notice. While it is still early days for Bun, it is already showing a lot of promise and is most certainly worth keeping an eye on for the future.

What Is Bun?

Bun is a fast, all-in-one JavaScript runtime that allows users to bundle, transpile, install and run JavaScript as well as TypeScript projects. It was built from scratch by Jarred Sumner, a former frontend engineer at Stripe, who describes it as "experimental software" (https://github.com/oven-sh/bun). Sumner wrote Bun in ZIG, which is a low-level programming language sharing similarities with C or Rust. Most of it was written entirely from scratch, including the JSX/TypeScript transpiler, npm client, bundler, SQLite client, HTTP client, WebSocket client, and more. 

What Is The Focus Of Bun?

There are already existing modern JavaScript runtimes like Node and Deno, so what exactly is it that sets Bun apart from these? According to the official Bun website, Bun focuses on three main things. First, it is designed to start fast; next, it should offer new levels of performance by extending JavaScriptCore (the engine). Finally, it is being designed to be a "great and complete" tool that includes everything from bundler and transpiler to package manager.

Bun's overall goal is to run most of the world's JavaScript outside of browsers and bring performance and complexity enhancements to the future infrastructure of users. Through the use of better, more straightforward tooling, it also aims to enhance developer productivity. 

What Separates Bun From Node and Deno?

While it fulfills the same functions as Node and Deno, a few things set Bun apart from the pack. As mentioned earlier, it is written in ZIG, which is a system language that is also currently still under development. This is in contrast to Deno, which is built on Rust, and Node, which uses C++. According to Sumner, he chose ZIG as the lack of hidden control flow makes it simpler to write fast software. The only potential downside is that ZIG does not have the built-in memory safety of Rust. Also, whereas Node and Deno use Google's V8, Bun makes use of the faster WebKit JavaScriptCore engine. In fact, the developer of Bun was able to implement a lot of performance fixes to JavaScriptCore in the process.

On his Twitter account, Jarred Sumner stated that one of the things he is most excited about is Bun install. According to Sumner, Bun for a simple Next.js app, Bun installs npm packages about twenty times faster than yarn and a whopping 49 times quicker than npm install. Sumner also revealed that Bun can handle over one million lines of JavaScript (input) per second. He added that Bun's WebSocket client has higher throughput than the "ws" npm package and Deno's. An infographic on the official Bun website shows far ahead of node and deno Bun is in terms of HTTP requests per second. In addition, it is supposedly 14 times faster than Next.js for reloading CSS and only takes a couple of milliseconds to clean projects from dist and node_module. To make Bun as fast as it is, an enormous amount of time was spent profiling, benchmarking, and optimizing things. 

Conclusion

As stated before, Bun is still an experimental project, but it is already apparent that it has a lot of potential. Its performance is undoubtedly eye-catching, and its npm module compatibility is a great feature. Most JavaScript projects still involve having to package the source into a more standard format, such as with Typescript, so having Bun automatically take care of these things simplifies the process considerably. For example, Bun can automatically transpile TypeScript files to JavaScript without the need for any extra configuration. The same applies to the web-specific APIs that are built into Bun.

In its current state, it will likely only be used in special scenarios, but given enough time and effort to mature, it can become a serious contender and is worth keeping an eye on. Since all the code for Bun is available on Github under an MIT license, it is easy to take a look at it yourself. In addition, Bun has an official Discord (https://bun.sh/discord) for anyone with questions or who wants to help with the project.

Featured Articles