DEV Community

Cover image for A first look at Bun: is it really 3x faster than Node.js and Deno?
Steve Sewell for Builder.io

Posted on

A first look at Bun: is it really 3x faster than Node.js and Deno?

Love it or hate it, the JavaScript tooling landscape is the subject of a lot of chatter yet again.

The latest: Bun. A new JS runtime focused on performance and being all-in-one (runtime, bundler, package manager, transpiler). So think of it like Node.js, plus NPM, plus tsc, plus rollup - but faster.

It makes big claims, such as being 3x faster at server-side rendering React. So, we put it to the test.

What makes Bun fast?

"What makes bun fast" visual overview

The Bun team attributes their performance to a few things:

  • Tons of time spent profiling, benchmarking and optimizing
  • Using the Zig language for it's low-level memory control and lack of hidden control flow
  • Using JavaScript Core, the engine inside of Safari, instead of V8, the engine inside of Chromium

So, is it faster?

We chose to dig into this specific claim from Bun.sh:

Visual of Bun's site claiming to be 3x faster at server-rendering React

At first look, wow! But then I imagined my Next.js site suddenly being 3x faster... and just frankly found that hard to fathom.

But who knows, so I dug in. The first thing that stood out to me was the source code of the benchmark. To put it shortly... this is not the most "real life" example of a React app to server render.

The "hello world" App used in Bun's benchmark

I don't know about you, but every time I've server rendered React for a real app - theres a lot more going on. A much larger component tree with business logic, libraries, props, state, context, etc.

So I made a more full fledged React app, and decided to run some benchmarks.

Methodology

I created a dashboard app in Mitosis (source). It has a full tree of components, business logic, dependencies, uses props and state and other typical React features.

Mitosis was chosen so that we can generate code for many frameworks to compare their performance in this more "real world" oriented app, as well as variations - such as React vs Preact, CSS vs styled-components, etc.

I created a basic app with Node.js, Deno, and Bun. To more closely attempt to replicate Bun's results, note that we used their custom fork of react-dom/server.

I at first wanted to avoid this, but Jarred (the creator of Bun), made a good case for platform-specific implementations of react-dom/server is already a thing (such as browser vs node specifically), and likely will continue to be. They intend to merge this into React core ultimately, so we will cautiously optimistically assume this is on the horizon.

We then used autocannon to measure the throughput (requests per second) of each runtime server-rendering our React app.

So, what were the results?

Running on my 2.6 GHz 6-Core Intel Core i7, using Bun version 0.1.10, Deno version 1.25.0, Node.js version 16.14.0 my results were:

┌─────────┬──────────────────┬─────┬─────┬─────┬───────┬─────────┐
│ (index) │       name       │ 1%  │ 50% │ 99% │  Avg  │ Std Dev │
├─────────┼──────────────────┼─────┼─────┼─────┼───────┼─────────┤
│    0    │ 'react-ssr-bun'  │ 500 │ 669 │ 718 │ 650.8 │  71.7   │
│    1    │ 'react-ssr-deno' │ 550 │ 600 │ 630 │  601  │  20.89  │
│    2    │ 'react-ssr-node' │ 267 │ 375 │ 394 │ 366.5 │  35.04  │
└─────────┴──────────────────┴─────┴─────┴─────┴───────┴─────────┘
Enter fullscreen mode Exit fullscreen mode

View the full source for the benchmarks (and let me know if you see ways the methodology can improve).

In this, we are seeing Bun handling about 75% more requests per second than Node.js, with Deno falling in between (closer to Bun than Node).

I have to say, I was surprised. Yes, it's not 3x faster - but it is in fact faster by a healthy margin.

So, should I switch to Bun now?

Well, probably not. It is currently in beta and not production ready (with many users reporting that there are notable bugs). But it is likely worth keeping your eyes on.

I have to say, using the Bun CLI in particular feels very snappy.

Gif of using the Bun CLI

Installation in particular feels so fast I have to double take to confirm to myself that it actually happened.

To me, this is one of the more exciting areas of Bun, considering how slow even Yarn can be in my experience for medium to large projects.

But, this is just one person's results and opinion. What do you all think?

Latest comments (37)

Collapse
 
seanpietz profile image
sean pietz

There is nothing remotely wrong with a startup having passion-driven hard work as company value. And your argument makes no sense - if people want to become part of a company that shares their values, what is wrong or exploitative about that. If you're making a Marxist argument about capitalism being exploitative in and of itself then make that argument, and I'd take you much more seriously. Are there any values that a for-profit startup is allowed to have that aren't exploitative? What if they said they were "committed to social justice and if you arent then it's probably the wrong company for you", would that be problematic for you? What is your actual argument, are you against hard work (i.e. pro laziness), or against capitalism in general, or both? Which would be more exploitative and immoral: 1. A startup where everyone passionately works really hard and as a result everyone gets rewarded with company equity and fulfillment, or 2. A startup where everyone apathetically works 25 hours a week and all end up poor and/or unemployed (I'm not posing this as a necessary dichotomy, I'm just curious to know your answer for this particular hypothetical case).

Collapse
 
bacloud22 profile image
aben • Edited

I'm curious to see these benchmarks being done over network, and preferably from different clients over seas across the globe, with every connection available.

You will see then that the biggest factor is old same old in the context of a "website", it is NETWORK assuming you are running your threads in best practices, like no blocking loop and doing parallelism, these are assured by design in programming languages and by web servers already, like just don't block the event loop (in node) and don't block when requesting your data from files or DB and stuff like that,
You will soon find that these differences play really a little in business,
You can always use CGIs by the way ! and plain files instead of DBs etc, you will probably get faster servers, but at what cost ?! This is to mention, the real deal is not running plain code on bare metal and benchmarking that in that same process or machine. and this is exactly what I'm seeing about 99% of benchmarks !
People still use PHP and I guess it does work great for them.

Developers are using NodeJS because it is faster and safer JavaScript, and JavaScript is easy or has been well adopted by large, that's it;

Collapse
 
bacloud22 profile image
aben • Edited

Like the Rust and Go fever, nearly no need for a regular website, that does go back and forth between a database and the most sophisticated algorithm that could use is a Radix Trie, some CSS and animations in the front and the client is more than happy.

 
zakharsmirnoff profile image
Zakhar Smirnoff

Okay, I would choose my friend. What about 100k loan for opening up my new business? Would a friend give me this amount of money? If yes (because I don't know about your friends, mine are not that rich), then are you 100% sure, that your friend would not expect a share in your business or at least some percent off 100k, say 2-3%? Money is not free, your friend could choose a deposit in the bank or buy Tesla shares or else.

Let me point this out: no one in the comment section or in the actual post tried to shill Oven job to you or anyone else. Let's just admit: YOU started the thread about their work culture, and now you are complaining that someone might have recommended this job to you.

If you don't recommend the job, it's totally fine. That's your opinion. But there are other people with their opinions who think it's totally fine to work there. Again: it's totally legal, so no one should worry about. Just DYOR about the company and make your own choice. It's like you are trying to ban this company just because you don't like it. Well, if you don't like it, don't work there. It's that simple, yes

 
zakharsmirnoff profile image
Zakhar Smirnoff

No one forces you to sign an agreement, lol. The conditions are transparent and known beforehand.

According to your logic, it’s not ok for banks to issue loans since they just steal your money. You took from them 100 USD, but you owe them 110 USD. That’s definitely a deceive, I think we should sue them. F*ck the agreement, we will just tell them the logic of Luke Shiru.

Collapse
 
mr_superhaggis profile image
Nick Winfield

Will definitely be keeping an eye on this runtime - a drop-in replacement is a no-brainer and the benchmarks thus far are very favourable. Confident the company behind it will deliver once they do the necessary crunching required to get it over the line.

 
zakharsmirnoff profile image
Zakhar Smirnoff

I don't understand. If overtime hours are paid and you signed an agreement which is clearly saying that sometimes you would stay overtime and get paid for that. Where is the problem?

 
joaovictorvp profile image
João Victor VP - N • Edited

If I had a company and I needed my employees to work more than the established hours, I would ask them, and if it was within my power, I would reward them properly for their effort. Of course what I would do is not what you would do, or what this company did, I am not approving or disapproving of their behavior but simply pointing out that this is not an exploratory act per se and that it may actually be justifiable depending on of the circumstances.

 
joaovictorvp profile image
João Victor VP - N

This was not a fallacy, what I brought was the lack of ability to analyze the state of affairs from an objective point of view due to a lack of practical experience in the world. You can certainly complain and find a country's environmental or political problems horrific, but do you have the capacity to say that you have a solution to the problems it presents? That's a paramount point (and I'm not saying anyone even has these answers, doesn't they). Of course we can talk about things that we have no experience with, but that doesn't mean we should be blind to the set of things we don't really know, you don't really know the difficulty of "just hiring one more dev" and clearly you don't understands the fact that "just don't hire someone" is nowhere near the solution to any problem, so my point was that your statement was empty in itself, if you lack real knowledge about something then most likely your statements about that something will be addicted to whatever ideological or pre-established views you may have had before. Of course, if you think I'm wrong, feel free to answer me, but don't reduce my points to mere fallacies.

 
joaovictorvp profile image
João Victor VP - N

Have you ever come even remotely close to opening a company in your life?

 
joaovictorvp profile image
João Victor VP - N

Calm down, the friend there didn't say that there is no exploitation nor did he make any absurd point. Exploitation certainly exists in large corporations, but that doesn't mean overtime is exploitative, you're just looking at things from the employee's side when the dance is two-way, the programmer is not obligated to work at that company if he doesn't want to. in no way do overtime, and that is specifically why it is not exploitation, or at least, it is not unwarranted or negative exploitation per se. Things would be different if we were talking about people like Beezos for example, they are cases and cases that need to be analyzed. It also doesn't mean he thinks these extra hours are cool or that he's not being "empathetic to other devs", just that he's considering all facets of this issue.

Collapse
 
adzetko profile image
Maxim "Adzy" Hohengarten

I tend to consider these work practices to be self-destructive (I don't actually have any proof what I say, and just the unethical part of such claims should suffice). I wouldn't put my trust into the long term support of a product made by a company with a self-destructive behaviour.

However, as I'm pretty new to JS runtimes, I didn't knew about Deno, so as this whole post put the spotlight on it, I'll definitely look forward to it!

Collapse
 
tamusjroyce profile image
tamusjroyce

When it gets stable, deno will switch to webkit javascript core too. very shortly deno will have full npm support. so why not stick with what is stable. And it will get drastic stable speed increases going forward

But I do wish bun the best of luck for quick stability. deno needs this speed improvement too.

No one needs really needs the bun language. doesn’t seem like rust motive for security & stability (took me a while to think about rust over C)

Some comments may only be visible to logged-in visitors. Sign in to view all comments.