Node.js Performance 2023 and Bun v0.6

Node.js Performance 2023 and Bun v0.6

Newsletter

JavaScript Jam Live on Wednesday

Join us this Wednesday for another open mic to discuss all the JavaScript news of the week. Last week, we discussed announcements from Google I/O about changes to Core Web Vitals. We were also joined by Monica Powell to hear about her upcoming RenderATL talk on creative coding. Check out the recording below:

Stories of the Week

State of Node.js Performance 2023

Node.js TSC member Rafael Gonzaga has created an incredible resource for JavaScript performance nerds and published it under the title, State of Node.js Performance 2023. The article presents a comprehensive performance analysis of different Node versions, focusing on versions 16.20.0, 18.16.0, and 20.0.0. Three benchmark groups were utilized in his research:

  • Node Internal Benchmark: An opinionated set of benchmarks grouped by module targeting high-impact operations for Node developers.
  • nodejs-bench-operations: An open source repository with benchmark operations for all major Node versions, including the last three releases of each version line.
  • HTTP Servers: A pragmatic HTTP benchmark that uses Express and Fastify to send requests to various routes and return JSON, plain text, and errors. The results for this group will be published in a subsequent article.

The analysis used an AWS Dedicated Host with a c6i.xlarge computing-optimized instance. The benchmarks covered various Node modules/namespaces, such as fs (file system), events (EventEmitter/EventTarget), http (HTTP server + parser), and more.

The statistical method applied in the study required performing each benchmark several times. The data was analyzed to determine the percentage of performance improvement along with a level of confidence in the improvements. Key findings include:

  1. File System (fs): An improvement of 67% was observed when upgrading from Node 16 to 18 using fs.readfile API with ascii encoding. However, there was a regression of 27% in Node 20 which is expected to be addressed in future minor releases. Other fs methods like opendir, realpath, and readdir showed improvement from Node 18 to 20.
  2. EventTarget: Event dispatching performance improved by about 15% when upgrading from Node 16 to 18 and up to 200% when upgrading from Node 18 to 20 with a single listener.
  3. HTTP Servers: An 8% improvement was noticed from Node 16 to 18 and a seemingly massive 96.13% improvement was found from Node 18 to 20. However, other more reliable benchmarking tools only showed an improvement of 9%, suggesting limitations or errors in the previous benchmarking method.
  4. startup.js: Significant improvement in the Node process lifecycle was observed with a 27% boost from Node 18 to 20 and 34.75% from Node 16 to 20.
  5. trace_events: Observed a 7% improvement from Node 16 to 20 and a 2.39% improvement from Node 18 to 20.
  6. require(): Observed improvements between Node 18 and 20 when requiring .js files (4.20%), .json files (6.58%), and reading directories (9.50%), thus contributing to faster startup times.
  7. Streams: Some operations related to streams became slower between Node 16 and 18. Also, certain types of streams (like Transform) regressed in Node 20.
  8. URL Parsing: The introduction of the Ada URL parser in Node 18 resulted in performance improvements of up to 400% when parsing URLs, with further enhancements observed in Node 20 due to an upgrade to Ada 2.0.
  9. Buffers: Node 20 fixed two major regressions from Node 18 and showcased significant improvements in handling binary data, particularly in Buffer.concat() and Buffer.toJSON() functions, making it the fastest version for dealing with buffers.
  10. Text Decoding and Encoding: Node 20 brought substantial performance improvements in TextDecoder and TextEncoder over Node 18, with the addition of simdutf for UTF-8 parsing leading to a 364% improvement in decoding and a 25% performance boost in comparison to Node 18.

While the overall benchmark results show a few setbacks, most of the areas of concern demonstrate that significant improvements were made in Node's performance across versions 16, 18, and 20. Most importantly, these benchmark results can help guide future optimizations and assist in avoiding regressions.

Bun v0.6

Dubbed, "the biggest release of Bun yet," Bun v0.6 introduces a built-in JavaScript and TypeScript bundler and minifier. Users can now bundle their frontend apps or convert code into standalone executables (meaning they do not require a Bun installation for execution). v0.6.2 quickly followed with numerous performance improves and then v0.6.3 added support for node:vm.

The bundler is seen as the first step towards Bun.App, an integrated API combining Bun's bundler, HTTP server, and file system router. The bundler can be used through the bun build CLI command or the new Bun.build() JavaScript API. Other key features and improvements include:

  • import.meta.main can be used to check if the current file is the entry point that started Bun.
  • New testing methods were added and bun test now reports test run times.
  • Performance enhancements include a 20% speed increase for writeFile() on Linux.
  • Improvements to Node.js and Web API compatibility.

Composability Summit

In Thomas Heinrichs' talk, Loosely or Lousily Coupled, Thomas aims to explore various composable communication methods in modern distributed architectures, including event streaming, asynchronous messaging, and REST. He discusses their limitations, tradeoffs, and impacts on component coupling while emphasizing how these concepts influence architecture and team productivity.

Podcasts of the Week

One More Thing

While at Remix Conf, I had the pleasure of interviewing Glauber Costa (CEO of Turso) and Igor Minar (Senior Director of Engineering at Cloudflare). We discussed the future of developing web applications at the edge and how databases and web frameworks will influence the way those applications are built. You can check out the recording here:

JavaScript Jam on the Web

Find us online at the following links: