How Fast Is Bun.sh After All?
Tags: webdev, javascript, node, opensource
Published: 2022-09-02 05:29:34

Bun is the ultra fast JavaScript runtime that has taken the internet by storm and that is set to dominate the JavaScript development market in the coming years. At least that's what people are saying online. But whether there's any truth to that, is another story.

![bunhomepage](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/4pz8y7eiuem63hn3diky.png)

## What is a JavaScript engine?

Before we get into Bun directly, let's get into what a JS engine actually is and does.

For as long as developers can remember, JavaScript was mainly confined to running inside of a web browser.

And to do so, it needs some kind of engine to parse the JavaScript and to turn it into a functional application that users can interact with and see.
Welcome to JavaScript engines.

There is a good chance that you have at least heard of 1 popular JavaScript engine, that being the V8 engine created by Google and intended for use on Chrome. It is also the engine used by Node.js currently.
It's popular and for good reason. It's well maintained and it is backed by Google. Two big reasons. But there are a few competitors that it needs to contend with.

SpiderMonkey is the JavaScript engine that Mozilla uses for its FireFox browsers, which also implements WebAssembly as well.

And JavaScriptCore is the engine created by Apple for it's Safari browser. And JavaScriptCore is fast. Typically faster than the other 2.

You can see a pattern here. Essentially, every major browser currently on the market had to create its own JavaScript engine. But in some cases, they might use an existing engine such as Opera, which uses V8 internally.

## What is a runtime?

And a runtime, is essentially where a program is executed on your machine, using one of these engines.

Node.js and Deno are currently the dominant forces in that area, both using the V8 engine from Google and both created (and co-created) by Ryan Dahl.


![bunfast](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/7ycm9vtko8uidb4kbwiu.png)

## What is Bun?

Bun is a JavaScript runtime, much like Node.js and Deno, that is built from the ground up to focus on speed and overall performance and if the benchmarks are true, then it pretty dominates over its competitors. And it comes out of the box with plenty of features (down below) that can definitely replace your current JavaScript engine implementations.

![Bun.sh graph](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/7zk3cuv9j9n7k5xyzvvp.png)

Bun implements hundreds of Node.js and Web API's and it supports fs, path and Buffer as well. You can currently install Bun on MacOS x64, Linux x64 or Windows Subsystem for Linux (WSL).

The official GitHub page for Bun can be found [here](https://github.com/oven-sh/bun).

But let's get into the features that really make Bun standout above the rest, because there's quite a few.

## Features

![features gif](https://c.tenor.com/y438NMTZ_F8AAAAS/awesome-feature-sh1n-boo.gif)

Bun currently supports Web API's, such as `fetch`, `WebSocket` and `ReadableStream`. And from the sounds of it, it looks like it will be able to support any new API's added in the future.
Bun also transpiles every file, meaning that TypeScript and JSX work out of the box without requiring any extra dependencies.

Bun also automatically loads environment variables from any `.env` files with needing any extra requires or imports. Meaning overall less overhead when it comes to setting up a new project.

And currently, Bun implements around 90% of Node API functions, again, meaning that incorporating the new runtime into your projects will be a near seamless process.

And lastly, though not least, Bun also comes packaged with a SQLite3 client, bun:sqlite. And based on the queries per second that it can perform, it is several times faster than some of its competitors, such as better-sqlite3 or deno.

So in a sense, Bun is a feature-rich, built from scratch, and high performing JavaScript runtime with vital components built right into the engine from the start.

## Will it replace Node.js?

Personally, I love what I see being done here with Bun. The performance first approach will become vital in the coming years as applications get more and more complex and as data sets get larger and larger.

But it still has a long way to go before it can play with the big players. For one, most vendors currently do not support Bun as an official runtime.

More notable though, is that Bun is still very young and it isn't done implementing all current Node.js API's. And once it has done so, we still have to see if it performs equally as well. Because what Node.js and Deno have going for them is that they have been around for a while now, so plenty of bugs have come to light and have been fixed.

## Happy Coding!!!

Thank you for reading! If you found this blog post helpful, please consider sharing it with others who might benefit. Feel free to check out my other blog posts and visit my socials!

- [Profile](https://bio.link/devarshishimpi)
- [Linkedin](https://linkedin.com/in/devarshi-shimpi)
- [Twitter](https://twitter.com/devarshishimpi)
- [Youtube](https://youtube.com/@devarshishimpi)
- [Hashnode](https://devarshishimpi.hashnode.dev)
- [DEV](https://dev.to/devarshishimpi)

### Read more

- [Top 10 VS CODE Extensions You Need In 2022!](https://blog.devarshi.dev/top-ten-vscode-extensions-you-need-in-twentytwentytwo)
- [Complete Markdown Tutorial for Beginners](https://blog.devarshi.dev/complete-markdown-tutorial-for-beginners)
- [Everything You Need To Know About Github Copilot!](https://blog.devarshi.dev/everything-you-need-to-know-about-github-copilot)