Bun update brings Chrome debugging and controversial S3 API, PostgreSQL client coming soon

Bun update brings Chrome debugging and controversial S3 API, PostgreSQL client coming soon

Version 1.1.3 of Bun, a toolkit and bundler for JavaScript and TypeScript applications, is out. And while it has new features including an API for S3 storage, support for Chrome debugging, a large number of fixes, and the promise of a PostgreSQL client in Bun 1.2 (scheduled for delivery next week), the project is currently attracting criticism for including vendor-specific APIs and too many features which could be in libraries rather than the core.

S3 (Simple Storage Service) is an AWS service whose API (or part of it) has been adopted by others including Google Cloud, Digital Ocean, Cloudflare and more. There are two ways to initialize the API, Bun.s3 which reads credentials from environment variables and Bun.S3Client which uses explicit credentials. It is also possible to generate a presigned URL with an expiry, which then works without credentials.

When the S3 API was first presented, some developers were unhappy that “vendor specific APIs in a runtime aren’t a great idea.” AWS could change the API which would then break Bun. Bun author Jared Sumner responded on social media that “S3 is over 15 years old. There are enough old S3 clients and S3-compatible APIs that breaking API changes are effectively impossible to ship.”

Another new feature bundles html and CSS (Cascading Style Sheet) files as well as JavaScript, though this currently requires the flags –experimental-html and –experimental-css flags, until 1.2 is released. The output will have just one JavaScript file and one CSS file, including tree-shaking (removing unnecessary code) and optimization for JavaScript and TypeScript. Images and other assets are also copied into the output directory, and references updated. The idea is to build static sites and web applications.

Debugging Bun memory usage in Chrome Dev Tools

Bun is written in Zig and uses WebKit’s JavaScriptCore for its JavaScript engine. According to Bun’s developers, this reduces startup time and memory usage versus the more widely used V8 engine which powers Google Chrome and the open source Chromium project. This does add some friction though. One example is mitigated in this version, which is that Bun can now output a V8 heap snapshot, so that Chrome DevTools can be used to debug memory usage.

Bun already has a built-in Sqlite driver for local databases. This will soon be accompanied by a PostgreSQL client, which Sumner described as “one of my side projects.” The new client will be included in Bun 1.2, or tried in the current canary (preview) build. 

There are also a large number of fixes in this release, including a memory leak in the WebSocket client, and a stack overflow error when large numbers of if statements are used. “The statement parsing step for if statements was always recursive, even if the if statement was not nested. This recursion used too much stack space. Now it’s no longer recursive,” Sumner remarked.

Node.js compatibility is also improved, with 100 percent of node:path tests now passing, and 98.08 percent of node:zlib tests (including a fix for a memory leak in the node:zlib module). Bun is still not a complete drop-in replacement for Node.js; Sumner said that this occupies the majority of the team’s time though “it is less shiny to talk about that.”

Bun 1.0 was released in September 2023, just 16 months ago, and development continues at a rapid clip. New features in Bun are introduced regularly, whereas Node.js, for which version 23.6 was released earlier this month, evolves at a more sedate pace, perhaps befitting its maturity.

Nevertheless, there is debate about whether some new features, including the PostgreSQL client as well as the S3 API, belong more properly in libraries than in Bun itself. Making these features part of Bun may create long term bloat and a maintenance burden – despite which, some “love the batteries included attitude.”