DEV Community

Cover image for How Fast Is Bun.sh After All?
Devarshi Shimpi
Devarshi Shimpi

Posted on • Updated on • Originally published at blog.devarshi.dev

How Fast Is Bun.sh After All?

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

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

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

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.

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

Features

features 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!!!

This concludes our article on Bun.sh, Let me know what you think about it below.

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!

Top comments (2)

Collapse
 
joelbonetr profile image
JoelBonetR đŸĨ‡

I'm also wondering what will the performance difference be once bun implements the whole set of features of Nodes core API, specially those more resource-consuming.

The current support is growing nicely, see here: github.com/oven-sh/bun/issues/158

Gotta love that the repo's owner is oven by the way 😂

Collapse
 
devarshishimpi profile image
Devarshi Shimpi

True 😂😂