Bun.js – JavaScript’s Newest Runtime Shows Increased Speed and Performance in Building Applications

The JavaScript ecosystem is known for getting new frameworks really often. Bun.js, its latest addition, brought intense hype in the JavaScript community, turning it into the rising star of Javascript Runtime Environments.

A good option for edge use cases and the simplicity of writing faster software make Bun.js a better alternative for Deno or Node.js. Read below to find out why.

What is Bun.js?

Bun.js is described as “a fast all-in-one Javascript runtime”, and aims to “compete” with Node and Deno, the other two main JS runtime environments. 

The interesting thing about Bun.js is that it uses the JavaScriptCore engine (from WebKit). This is totally different from Node.js and Deno, both using V8, and it’s one of the reasons why it’s such a fast runtime.

Additionally, Bun lets you use any of your favorite npm modules just like you would use them in Node.

Here’s exactly how Bun.js stands out among other runtime environments.

Why Should You Be Interested in Bun.js?

It’s Really Fast

An essential element that makes Bun.js stand out is the fact that it starts really fast, which can boost the emerging “on the edge” paradigm even further, making apps feel faster and smoother. What makes Bun so fast is Zig, a programming language that allows low-level efficient memory control, which leads to almost 4x faster start times compared to Node and almost 2.5x faster start times compared to Deno.

It Comes with Typescript Available Right Out of The Box

The second selling point is that Bun.js comes pre-configured with Typescript support. Additionally, it has its own bundler, transpiler, and package manager (most npm packages work, and this manager is really fast, ~4x-80x on Mac).

Basically, you can say goodbye to npm’s dependency errors and tricky Webpack/Babel configurations.

Other features include:

  • Fetch, WebSocket and ReadableStream
  • Most of Node-API, fs, path, Buffer, etc.
  • Transpiler (already supports a wide array of files like svg, css, ts, tsx, jsx), Typescript and JSX simply work out of the box
  • Automatically load .env files
  • Really fast web server and SQLite client called bun: SQLite
  • Bun implements Node.js’ module resolution algorithm, so you can use npm packages
  • Really fast start time (~4x times faster than Node) – very beneficial if the app runs on the edge

Comparing Bun.js With Its Competitors

For straightforward benchmark testing, check out Bun. js compared to its competitors ( Node.js and Deno) in these categories:

  • creating a React app
  • installing a package
  • server performance

I used these prerequisites:

*Key details: I ran all the tests on a Macbook Pro 2020 M1 with 16GB RAM.

The results may vary depending on the internet connection and type of computer.

If time is an important thing for you in the development process, the section below will reveal some interesting facts.

Creating a React App – Bun Vs. Node

If you bootstrap a new React app using “bun create react” vs traditional ”npx create-react-app,” the execution time of the script will decrease from an average of 10 seconds to an average of 2.5 seconds (depending on your machine and internet connection). 

Installing extra packages which are necessary for development will also add value in terms of saving time.

Installing a package – Bun Vs. Node

Let’s take as an example “react-router-dom” – a package that allows you to create dynamic routing in React applications.
By using “npm”  command, the installation time is 3.9 seconds, while bun installs the same package in 0.56s:

If you use the bun command, the installation time is 0.5 seconds:

The results are: Bun.js – 0.5695s against Node.js – 3.9049s.

Server Performance – Bun Vs. Node Vs. Deno

For this experiment, I created three servers with three different js runtimes: (Bun, Node, and Deno). Using the AutoCannon tool that fires several requests on the servers, I compared them in terms of requests/s.After I ran all of them concurrently, I used the AutoCannon benchmarking tool script “autocannon -c300 -d20 -v8 -l”  for measurement with the same parameters for each server, where:

  • c is the number of concurrent connections to use
  • d is the number of seconds to run the autocannon
  • w is the number of worker threads to fire the request
  • l prints the latency

Bun.js Runtime

Deno Runtime

In terms of average number of requests per second (~85k), Deno proves to be ~2x slower than Bun, making Bun significantly faster.

Node.js Runtime

Comparing to Bun and Deno, it can be seen that Node is the slowest one with 79.461k average requests per second.

Check out a graph with the comparisons of these three runtimes based on the number of requests / second:

The Bottom Line – Bun.js Seems Promising In Terms of Speed and Performance

All in all, Bun.js is exciting news for the JavaScript ecosystem and shows great promise because it has the potential to become a game changer for JavaScript runtime environments. Fields like AI/ML or game development, where performance is critical, will likely adopt Bun. js

It’s still in its early stages, and has limited support. For now, Bun. js isn’t an option for production-ready software; as the developers advise, “Only use Bun.js for development, not production”. 

Still, we can only hope this nice tool will be updated more and more to the point where it will be a real competitor to Node and Deno.
Until then, use this github link if you want to report or solve any issues with Bun.js. It’ll help Bun creators improve this JS runtime environment.