A new JavaScript/TypeScript runtime called Bun promises exceptional performance, with its own benchmarks showing three times more HTTP requests per second than Node.js and nearly four times what Deno can deliver.
Bun, which describes itself as “experimental software”, is a project founded by Jarred Sumner, formerly a frontend engineer at Stripe. It is open source under the MIT license. Sumner introduced the public beta of Bun yesterday, describing it as “an incredibly fast all-in-one JavaScript runtime.” It can bundle over 1 million lines of JavaScript per second, he said on Twitter.
The presentation on the official website ticks lots of boxes for developers. Like Deno, Bun accepts TypeScript with automatic transpilation, as well as JavaScript. Bun also transpiles React’s JSX (JavaScript XML) syntax. Node.js module resolution is supported, with both CommonJS and EcmaScript modules (ESM), but ESM is used internally since this is the web standard.
This means that many npm packages work, however. Native code can be called from Bun JavaScript using bun:ffi (foreign function interface). A SQLite database engine is also included. “Most of Bun is written from scratch including the JSX/TypeScript transpiler, npm client, bundler, SQLite client, HTTP client, WebSocket client and more,” states the description.
Unlike both Node and Deno, Bun uses the WebKit JavaScript Core engine, stated to be “a little faster than traditional choices like V8.” Another point of differentiation is that Bun is written in Zig, a system language which is also under development, currently at version 0.9.1.
“Zig’s low-level control over memory and lack of hidden control flow makes it much simpler to write fast software,” say the Bun team. Sumner told Hacker News that “I started Bun a little over a year ago … On Linux, it installs dependencies for a simple Next.js app about 20x faster than any other npm client available today.”
Getting started with Bun is delightfully simple, though it requires Linux, macOS or Windows Subsystem for Linux. Run the install script, write a few lines of JavaScript, type: bun run demo.js, and a web server is up and running.
Most observers so far agree that Bun merits attention for performance alone, and that npm module compatibility is a huge advantage. That said, Zig lacks the built-in memory safety of Rust, used by Deno. Bun is in its early stages and whether the project will achieve the momentum it needs to thrive is an open question, though for sure it is one to watch and will be influential if nothing else.