Basic Bun Overview
We are passionate about performance at HarperDB, which is why we have heavily leveraged the power of Node.js for our technology. And when Bun was first starting to receive some attention several months ago, I was eager to investigate. I was able to get early access and do some testing of some of the packages I maintain. Jarred was extremely helpful in getting Bun running, and we were able to collaborate on testing different aspects of Bun's performance. I also helped test the early NAPI implementation, since I work on a few libraries that heavily leverage NAPI, and built a test case for further improving NAPI compliance. There is great progress in being able to support high-performance native libraries directly in Bun.
Handle Bun with Care (For Now)
And as mentioned before, it is important to remember that V8 really is and continues to be an incredibly performant JS engine. It would probably be unrealistic to expect that JSC can consistently outperform V8 in every form of JS usage. Each engineering team has made different design decisions with different optimizations and trade-offs. And in fact, you should expect V8 to still demonstrate better performance and efficiency in many situations. Consequently, evaluating the best future use cases for Bun requires understanding where it truly excels and does best. And I will try to share some of my testing observations to demonstrate the distinct performance profiles of Bun/JSC and Node.js/V8 to find the best potential for Bun.
Where Bun Excels
One of Bun’s primary advertised advantages is in HTTP processing. The home page readily advertises over three times the speed of Node.js with HTTP response rates. And this level of HTTP processing provides an immediate advantage for any web application server. Web frameworks are already rapidly springing up to take advantage of this.
I also noticed that Bun seemed to be faster at updating object properties and array entries. This is an area where trade-offs seem to be in place: V8 seemed to be able to generate faster bytecode for quick access to properties (and consequently methods), which can often be heavily used in much application code. V8 also seems to generally be faster at iterating through properties (with a for-in loop). Bun also currently has a performance issue with async/promises, but will probably be resolved.
I have found plenty of other places where Bun/JSC outperforms V8, including Map usage, random numbers, garbage collection, and many native methods. But tests can vary widely, often Bun runs many times faster than Node.js for certain operations, and sometimes you might observe the complete reverse. Overall, I would expect most applications really will probably go faster on Bun, but testing your application will be important.
Finally, in comparing benchmarks, JSC and V8 actually seemed to be optimized for different CPU architectures. Not surprisingly, JSC seems to really outperform V8 more frequently on M1’s ARM architecture, whereas V8 tended to often do better on an x86 CPU.
A Greener Future?
While much of the attention on Bun has been focused on performance, perhaps the most potentially world-changing and revolutionary aspect of this combination of optimizations yields a fascinating synergy: Bun may be opening the doors for web applications with unmatched power/energy efficiency and lower costs. By being specifically optimized for ARM processors (with excellent power efficiency), and extremely low overhead HTTP and string processing capabilities, the next generation of ARM servers running Bun may be capable of handling many billions of web requests per kilowatt-hour; levels of green, low-energy server capabilities that would be extremely difficult to achieve with other technologies. In an age with disappointing levels of energy resources consumed by some software, this is an encouraging development with real and significant potential and value for humanity.
HarperDB will continue to provide stable and high-performance databases built on the capabilities and maturity of Node.js, and Bun’s NAPI implementation needs some fixes before we can use it. But we are excited about the future possibilities of potentially using Bun for future applications, and our software already has updates in place to leverage Bun’s fast FFI capabilities. Bun has demonstrated a remarkable trajectory, with constant improvements and optimizations, we are looking forward to leveraging them in the future, for the opportunity of both better performance and efficiency.
HarperDB’s integrated application + data platform is orders of magnitude faster and more flexible than last-generation alternatives. Easily replace SQL and NoSQL databases for cloud, edge, on-prem, peer-to-peer, and multi-deployment use cases. From validating an idea to delivering global scale, HarperDB grows with your application and saves you time and money every step of the way. Start for free today.