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?

Top comments (47)

Collapse
lukeshiru profile image
Luke Shiru

Sadly the work culture at Oven (the brand behind Bun) is far from ideal. They deleted this tweet because it had a big backslash and it wasn't addressed, just silently ignored.

Screenshot of tweet showing how Bun asks for candidates to grind and had a unhealthy work/life balance

And even if I liked the idea of having a highly optimized JS runtime, I can't in good conscience get behind a company like that.

Collapse
ivictbor profile image
Ivan Borshchov • Edited on

It is an awesome tweet for a company which have all chances to influence the future. Same to "There are way easier places to work, but nobody ever changed the world on 40 hours a week""

Collapse
lukeshiru profile image
Luke Shiru • Edited on

nobody ever changed the world on 40 hours a week.

The problem here is that the company benefits from the effort of others. I already said it in another reply, but you can push yourself for your own company if you want, is your life. Now asking others to burn themselves out for your benefit is not ok.

One illustration that depicts this quite clearly is this one showing Jeff Bezos going to space:

Art showing Jeff Bezos in top of a human pile of Amazon employees, reaching the starts

Some folks were like "Go Jeff! Reaching space as the great entrepreneur you are!" but is like the forget that Amazon is between one of the worst paying jobs out there, with lots of shady practices, so he basically got there by exploiting people. If your success depends on pushing and burning out others instead of yourself, is not success, is exploitation.

Collapse
bsmirh profile image
Bill Haack

Not ideal for whom? Some of us like that kind of work environment. You act as though there is some ethical code is being violated. Is there a new ethic against hard word and long hours now? I missed that memo.

Collapse
lukeshiru profile image
Luke Shiru

Not ideal for anyone aware of work ethics of this century. If a company was able to convince you that is "cool" to invest your personal time on the company, I'm really really sorry for you...

Thread Thread
eezing profile image
Eric Zingeler • Edited on

Work ethic(s), there’s irony here. It’s not a company, it’s a startup, I’m sure equity is part of the package.

Thread Thread
lukeshiru profile image
Luke Shiru

Equity in a non-public company is not worth a penny. Is an equity that requires time to vest, and when you’re going to be burn out in a year, is completely useless. We have to learn as a community to push back on this practices and not being ok with folks ingenuity being exploited.

Thread Thread
eezing profile image
Eric Zingeler

Some may not see it that way and they’ll be the ones to apply. Is it not a good thing that the company disclosed their expectation publicly?

Thread Thread
lukeshiru profile image
Luke Shiru

Putting a sign on the door that says "we'll exploit you" doesn't make that exploitation ok. Is actually not that hard: Pay fairly for 40hs of work per week. Need more hours? Hire more people. Can't afford that? Don't open a company.

Thread Thread
joaovictorvp profile image
João Victor VP - N

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

Thread Thread
lukeshiru profile image
Luke Shiru

🤣 gotta love the "you don't own a company so you can't complain about shitty company practices" argument. I'm guessing you are happy about the economy in your country because you never came close to owning a country, and happy about the state of the world climate because you never came close to owning a planet. Sorry but that kind of fallacy doesn't work here 😅

Thread Thread
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.

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
arden144 profile image
Arden

Oven is one person. He’s trying to start a business and setting expectations is perfectly valid. If someone isn’t willing to work long weeks, then surely they won’t work there.

Collapse
lukeshiru profile image
Luke Shiru

If his company or product doesn't work without making his employees do overtime, then he shouldn't start a company in the first place. We have enough "successful companies" based on exploitation out there to add more to the pile...

Thread Thread
arden144 profile image
Arden

Mandatory overtime isn’t exploitation. Nobody is being forced to work there, and it’s not slave labor. Some devs want the extra money from working overtime.

Thread Thread
lukeshiru profile image
Luke Shiru

"Mandatory overtime isn't exploitation", now this is something I wasn't expecting to read today.... or ever. You could get well paid without having to work more than 8 hours/day, 5 days/week, like you know, in any descent work... if is really that hard for you to be empathetic towards other devs, imagine a friend of yours is applying to work overtime. Would you actually be ok with that company abusing your friend? Having a sign in the door that reads "we'll abuse you" doesn't make that abuse ok.

Thread Thread
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.

Thread Thread
lukeshiru profile image
Luke Shiru

Your point here is that we should be also empathetic towards Oven, but I will make it as simple ad possible for you: If you had the VC founding for a company of yours and you had the option of rapid development with exploitative practices and slow development or even failing as a company without those practices, what option would YOU choose. I consider myself ambitious, but I would rather risk failure than exploiting my employees (is MY sacrifice, not theirs). Maybe you disagree with this, but tbh that wouldn't make my point about Oven not being ok any less valid.

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

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.

Collapse
Sloan, the sloth mascot
Comment deleted
Collapse
lukeshiru profile image
Luke Shiru • Edited on

🤦🏻 are you seriously defending/justifying this behavior? This is not ok. Nobody should make people prioritize work over life, no matter if you're a big company or an "underdog". One thing is to do that for yourself (to each their own), but asking others to do it for your company is ridiculous.

If you actually think this is ok, I really hope you aren't in charge of anything, because I would feel really bad for the people "under" you. There is no good excuse to exploit people. If you can't afford to pay a fair compensation for regular working hours, then you shouldn't hire. That's it.

Thread Thread
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?

Thread Thread
lukeshiru profile image
Luke Shiru

Putting a sign on the door that says "we'll exploit you" doesn't make that exploitation ok. Is actually not that hard: Pay fairly for 40hs of work per week. Need more hours? Hire more people. Can't afford that? Don't open a company.

Thread Thread
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.

Thread Thread
lukeshiru profile image
Luke Shiru

Wow! You're almost starting to get it! Let's use your analogy since it looks like the actual problem is not easy to understand for you: If a bank is offering a loan of 100 in 1 day, but you'll own them 110, while a friend would lend you 100 and you'll own them 100 whenever you can pay, would you still choose the bank?

Even if the company is "transparent" about their shitty practices, that transparency doesn't make their practices good or recommendable. And there are thousands of software companies that would gladly pay the same or more for 40hs/week. I don't know if you're able to see this, but this discussion is basically like:

  • I can't recommend this company knowing their overwork practices.
  • But they are transparent!
  • Transparency doesn't make it ok.
  • But there are other things that are bad and transparent.
  • And they are still not recommendable.

I don't know how to make it simpler for you. If a company had a sign at the door that reads "If you enter, we'll hit you in the face" would you enter yourself or recommend others to enter just because "at least the company is being transparent"? I mean if you see someone else enter still, is their problem, yes .... but at least you tried to warn them that other companies would not hit them in the face upon entry.

Your only comments on DEV are to argue this, if you really still don't get the point, I find it quite useless for me to keep arguing with you, so I'll leave it at that 😅

Thread Thread
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

Collapse
sushruth profile image
Sushruth Shastry

just because that's the only way we know how to do something, doesn't mean that's the only possible way. we at best are at the infancy of history of software companies. chances are we will have a future where human side of things in making a company are equally important, if not more, than the product side of things.

one thing is evident based on human history - comfort always wins popular choice.

Collapse
staidwinnow profile image
Staid Winnow

Yes, requiring workers to give away their personal time is a way of subsidizing costs.

It's a race to the bottom. More startups fail than succeed, and of the few that succeed, the ones who burned out are...burned out.

Bun deleted their tweet because?

Thread Thread
Sloan, the sloth mascot
Comment deleted
lukeshiru profile image
Luke Shiru

If they are burned out in a year or less, they'll not see the benefits of their "hard work". Is kinda hard to be "respectful" of an opinion that enables and approves exploitation.

Thread Thread
staidwinnow profile image
Staid Winnow

I mean, I am open to any opinions that earn respect. One that attempts to justify corporations demanding free labor is not one of those.

Collapse
themartes_ profile image
Matej Bunček 🤔

We wouldn't be nowhere close to todays state of engineering, if everybody would be working 9 to 5. You should wake up from the dream of todays generation called work-life balance, becasue sadly that doesn't exists if you want to be really successful. Some people want to make successful products therefore they'll join the company bcs they want their work to be refelected on entire spectrum of devs.

Collapse
lukeshiru profile image
Luke Shiru • Edited on

By that reasoning we wouldn't be here if it wasn't that we were caveman first, so feel free to go back to your cave. There's a thing that you might have heard called "progress", which is the opposite of doing things like we did it in the past, learning from mistakes, such as making humans work more than 40hs per week. That "convention" didn't came out of nowhere, is the result of evaluating the amount of time a human being can work and keep being productive, without "wearing out". So even if you lack empathy, is still a bad decision for productivity.

Graphic that show how overtime produces more work initially, but way less work over time than just working 8 hours ever day

Thread Thread
themartes_ profile image
Matej Bunček 🤔

But this is purely individual, you can't just take a graph and put it on everybody. For me it seems like you haven't really do anything youre passionate about because then the 40 hour bullshit is something you don't care about at all. If you're hating your work sure, do 40 hours and call it a week, but if you really care those 40 suddenly becomes 60-70 and you wont give a shit about it. And it's not about empathy nor producitivity. If you don't want to work just say so, but dont be mad when somebody doing same work as you do will be more successful just becasue he put extra 20 hours in it more.

Thread Thread
lukeshiru profile image
Luke Shiru

The thing that you don't seem to understand is the difference between working for your own projects and working for a company. It looks like companies really made you believe that being a "passionate developer" is working extra hours for them, instead of just liking to code. You can code in your spare time (I most certainly do that), but that coding you do should be for you, when you actually feel like it, not by request of a company.

It's about empathy because you should care about other folks in your same line of work being exploited, so that it doesn't become a trend/standard. And is about productivity because as it was proven several times, if you really want to get value from human beings, you shouldn’t take them to the edge of burn-out to do so.

You try to make the conversation about "hating work", but this conversation is not about work, is about exploitation. Even doing what you love, if you're exploited doing it, you'll dislike it in the long run. And if you really can't understand that, then I congratulate you for being so lucky to stay oblivious about exploitation, but I advise you to do some investigation before defending shitty company practices.

Collapse
christian_go3 profile image
Christian GO

Thanks for sharing Steve, I will definitely keep an eye on Bun!

Collapse
kostyfisik profile image
Konstantin Ladutenko

Bun is in beta, so... Have you considered using experimental HTTP server from deno, they're claiming it to become 3x faster? deno.com/blog/v1.25#new-experiment...

Collapse
steve8708 profile image
Steve Sewell Author • Edited on

Ya! Latest benchmarks use that github.com/BuilderIO/framework-ben.... Note tho that what they optimized was the HTTP server, but this tests the performance of a full application which will mostly be impacted by the other business logic and react components rendering. That said tho Deno moved up a bit from the latest beta server

Collapse
kostyfisik profile image
Konstantin Ladutenko • Edited on

Sorry, I am still a bit confused. Could you please share results both for Deno 1.25 in normal and experimental mode? If I got you right, using smth like real-world-app shows no performance gain. May be this is due to the fact, that in experimental mode Deno is only capable of http/1.1, which is not important for hello world app... and it still outperform http/2 web server for a full fledged app...

Thread Thread
steve8708 profile image
Steve Sewell Author

Here are the results before and after - before is on (I believe) Deno 1.24, after is on Deno 1.25 with experimental mode github.com/BuilderIO/framework-ben...

But what I’m trying to say is the server speed is not usually the main bottleneck for a real world application. Most CPU cycles are spent on the business logic of the application, rather than the details of the server implementation

Thread Thread
steve8708 profile image
Steve Sewell Author

All that said all of the code is open source so you are more than welcome to replicate the results yourself too in any way you like and/or send PRs for feedback and improvements

Thread Thread
kostyfisik profile image
Konstantin Ladutenko

Deno and Bun are almost twice as fast as Node for your app... with no change in business logic for all cases. So your results do not support the claim, that "Most CPU cycles are spent on the business logic". Is it possible somehow to profile, where main CPU power really goes?

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)

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.

Collapse
baturdev profile image
Batur Akkurt

Hi, I tried to create the next.js app with bun last week but it doesn't work correctly. Also after creating next.js app w/ bun, the project is not directly compatible with yarn/npm.

🌚 Browsing with dark mode makes you a better developer.

It's a scientific fact.