TNS
VOXPOP
Where are you using WebAssembly?
Wasm promises to let developers build once and run anywhere. Are you using it yet?
At work, for production apps
0%
At work, but not for production apps
0%
I don’t use WebAssembly but expect to when the technology matures
0%
I have no plans to use WebAssembly
0%
No plans and I get mad whenever I see the buzzword
0%
Frontend Development / JavaScript / Software Development

Bun 1.0 Ships as Node.js and Deno Alternative

Bun 1.0 has been released; it's designed to be a drop-in replacement for Node.js. Bun is fast, but is speed the only factor that matters?
Sep 11th, 2023 12:55pm by
Featued image for: Bun 1.0 Ships as Node.js and Deno Alternative
Image via Bun

One of the hardest things about shipping the 1.0 version of Bun, creator Jarred Sumner shared via X (Twitter), was removing the frontend server that was part of the beta.

“The thing I wish we had more time for is making Bun good for frontend development,” Sumner said during an X (Twitter) Q&A after the Thursday launch. “It’s not bad for it — you can use […] the tools you already use. But I still think there’s a big opportunity there for something where the runtime is directly integrated with the frontend build tools.”

That said, no one responding about Bun seemed to care after its release. Feedback from users made it clear that it was fine to remove the frontend server, he noted, and the majority of the responses to this news on social media was positive. By Friday, the buzz over Bun was all about its speed and ease of use.

Built for Speed

Bun competes with Node.js and the Rust-based Deno, which were both created by Ryan Dahl. In fact, it’s designed to be a drop-in replacement for Node.js, according to a release livestream that aired Thursday. Bun writes three times faster than Node.js and reads files up to three times faster, the team said during the livestream. Ashcon Partovi, product manager at Oven, the company that created Bun, addressed Bun runtime.

“There are a lot of tools in the Bun toolkit,” Partovi said. “But the crown jewel is the Bun runtime. Bun is a drop in replacement for Node.js that’s backward compatible, and can run Typescript and TSX files, no dependencies necessary.”

He added that Bun can replace any npm run command with a Bun run instead, with npm taking about 150 milliseconds to start running a script on a MacBook Pro. That’s compared to 30 milliseconds for Bun, he said.

“Npm feels noticeably laggy. Whereas Bun feels instantaneous,” Partovi said.

Bun gets a boost from using JavaScriptCore from WebKit, which is known for being exceptionally fast, according to full-stack developer Shalini Tewari, who shared her thoughts about the speed via X (Twitter).

“Node.js, Bun and Deno are all server-side js runtimes, but they have completely different goals.

Choosing between Bun and Node.js depends on your project’s needs,” Tewari suggested. “If you need speed and a straightforward, lightweight experience, go for Bun. If you want a broader ecosystem and community support with lots of tools, Node.js is a solid choice. You can even use both to make your JavaScript applications strong and efficient.”

Benchmarking Runtimes

James Konik, a software engineer with the developer security platform Snky, recently compared the three runtimes and found Bun outperformed both Node.js and Deno.

“Powered by Zig, its aim is to be an all-in-one runtime and toolkit with a focus on speed, bundling, testing and compatibility with Node.js packages,” he wrote.”One of its biggest draws is its performance, which is demonstrably faster than both Node.js and Deno. This makes it a very attractive proposition if it can deliver on all of that.”

He noted that the Bun maintainers provided an example benchmark running an HTTP handler that renders a server-side page with React. Bun handled about 68,000 requests per second compared to about 29,000 and 14,000 for Deno and Node.js, respectively.

In his own tests of an earlier version of Bun, Konik found Node.js handled 21.29 average queries per second, while Deno rated 43.50. Bun handled 81.37 average queries per second.

“In another comparison between Node.js, Deno and Bun, Bun is the fastest to handle concurrent connections. Its requests per second are quite higher too,” Konik wrote. “For instance, with 10 concurrent connections, Bun achieves 110,000 requests per second while Node.js achieves 60,000 and 67,000 for Deno.”

It’s worth noting that a different comparison found Deno and Bun performed very similarly.

Of course, speed isn’t the only factor to consider in a runtime. In a Deno discussion, developer markthree pointed out each runtime had its strengths.

“Bun is more concerned with performance, so it is much better than the other two runtimes in terms of performance right now,” he wrote. “Deno is synonymous with safety, in my opinion, I can safely use packages from the community without worrying about them doing things to my system that I don’t know about. Node is now starting to make a big push on performance and security, too.

“Competition is good, js runtime is starting to evolve,” he added.

More to Come from Bun

That said, Bun is still a work in progress. For instance, Bun Install is ready for Linux and Mac OS but the team was struggling to get the Windows version working, Sumner revealed during an X (Twitter) Q&A held after Thursday’s release. Bun provides a limited, experimental native build for Windows. At the moment, only the Bun runtime is supported, according to the documentation.

“Bun Install will probably be two weeks later is my guess,” Sumner said. “And this is going to be super unoptimized in the first release for Windows. It’s going to take some time before it actually is fast. “

In addition to the runtime, Bun has baked in features that will make developers’ lives easier, said Sumner, such as:

  • Support for both common JS and ES modules
  • Support for hate reading using –hot server.ts
  • A plug-in API that lets developers define custom loaders

“You can extend the Bun runtime to support things like .Yaml imports,” he said. “It uses an API that is inspired from ES build, which means many ES build plugins just work in Bun.”

Group Created with Sketch.
TNS owner Insight Partners is an investor in: Deno.
THE NEW STACK UPDATE A newsletter digest of the week’s most important stories & analyses.