Log in to GraphQL EditorGet started
Bun: a new and really fast JavaScript runtime

Michał Tyszkiewicz

7/20/2022

Bun: a new and really fast JavaScript runtime

In 2018 Node.js creator Ryan Dahl gave his famous talk titled "10 Things I Regret About Node.js". It outlined regrets he had about some fundamental decisions made during the creation of Node like the package management, the build ecosystem, GYP and the lack of core TypeScript support. That’s why in the same talk he announced Deno, a completely new JavaScript runtime made from scratch, to avoid the drawbacks of Node and written in TypeScript and Rust. Deno had a lot of hype and the community was a bit split on the subject with some wanting to hop over to Deno asap and others wanting to stick with Node.

Deno vs Node

While Deno is obviously an upgrade over Node (it's made by the same person after all) and has many interesting improvements, there has been a lot of hesitancy about moving over due to various reasons. Deno is fairly new (ver 1.0 came out in May of 2020) so it hasn't been that battle tested yet, and it has a much smaller community, so third party packages are way less abundant and most importantly while it is an improvement over Node in a lot of aspects, it still is often in the same ballpark performance-wise. That will obviously probably change as Deno becomes more mature and if things go well it might even replace Node. But what if I told you that you don't have to wait for that anymore and its no longer just a two horse race?

Bun

Bun is a new all-in-one JavaScript runtime and a competitor to Node and Deno. It's written in Zig, a somewhat new (2016) low level programming language designed for “robust, optimal, and reusable software”. The creators of Bun point out Zig as one of the main reasons for its performance saying its low level control over memory and lack of hidden control flows make it better suited to write fast software. The other key is the engine as, unlike Deno and Node, Bun is not based on Google’s V8 engine but on Apple’s JavaScriptCore, the engine used in Safari and many MacOS apps, which claims to be significantly faster. Its JIT compiler is named FTL for 'Faster Than Light' so you get the idea.

Can this really challenge Node and Deno?

Well the big selling point for Bun is performance, it's not just faster by a bit in this or that use case, it's faster by whole orders of magnitude. Sure it's always good to take measurements you get from the creators with a grain of salt, but in this case we can easily find various tests done by a number of people all pretty much confirming the same thing: it's blazingly fast. Going by Bun’s official benchmarks:

  • bun.serve: 3 times faster when server rendering react
  • bun.sqlite: almost 3 times faster when running database queries
  • bun.ffi: almost twice as fast when executing native code with foreign functions

Speed has been the main focus since that is the thing that jumps out at you first and that justifiably has fueled a lot of the hype Bun has gotten over the past couple of weeks. But Bun also has a number of quite enticing features related to dev experience and some neat quality of life solutions. It also uses a bit of a best of both worlds approach. Like Deno it has top-level await and prioritizes WebAPI’s like fetch, WebSocket and ReadableStream. As for Node it supports a lot of Node core modules already and has a Node API which will support a number of npm packages as well. It also uses Node’s module resolution algorithm so you can install from npm and do it a lot faster as well. And that's not all:

  • native bundler instead of relying on something like Webpack
  • native transpiler for built-in TypeScript support and auto transpiling JSX
  • native test runner like Jest which runs really fast
  • automatic loading of environment variables from .env files so no more dotenv

Great things have small beginnings

Bun started out as a side project simply because its creator Jarred Sumner thought Next.js was just too slow. The idea behind it is clear, max performance and better dev experience to work both faster and with less hassle. It blew up and its scope is now quite a bit bigger. It's obvious Bun is not production ready just yet, it's just version 0.1 after all and its creator freely admits there’s a lot of bugs and he just wanted to get it out before he ran out of steam. But there is really a lot worth checking out here and the hype is definitely justified. I think a lot of people jumped at it simply because the whole Node vs Deno debate got a bit stale and they got bored of waiting for some kind of resolution. Bun on the other hand is something to be excited about already as it brings a lot of new stuff to the table and offers taking a big leap instead of taking gradual steps in terms of improvements, especially if we’re looking at performance. Obviously I wouldn't assume Node and Deno are dead just yet, but it's worth it to check out Bun just to get some idea of all the possibilities it has just opened.

Check it out on GitHub: https://github.com/oven-sh/bun

Check out our other blogposts

Unlocking the Power of React 19
Tomasz Gajda
Tomasz Gajda
Unlocking the Power of React 19
1 min read
23 days ago
Zeus update - GraphQL spread operator
Michał Tyszkiewicz
Michał Tyszkiewicz
Zeus update - GraphQL spread operator
1 min read
2 months ago
What is GraphQL Zeus?
Michał Tyszkiewicz
Michał Tyszkiewicz
What is GraphQL Zeus?
1 min read
2 months ago

Ready for take-off?

Elevate your work with our editor that combines world-class visual graph, documentation and API console

Get Started with GraphQL Editor