Skip to content

In development. Expect rough edges and changes. The source code is not public yet.

Bun 3 min read Deep dive mediumAdept

500x faster postMessage(string)

Bun v1.2.21 makes postMessage(string) between workers nearly independent of string size, up to 500x faster with ~22x less peak memory on 3 MB strings (593 ns vs 326,290 ns in 1.2.20). JavaScriptCore strings are already immutable with atomic reference counts, so Bun skips Structured Clone serialization and shares the StringImpl pointer directly. Before sharing, it forces the lazy hash computation and marks the string never-atomicize. The fast path applies only to plain strings of at least 256 characters sent alone within the same process; atoms, symbols, substrings and ropes still get copied.

Assumes: Web Workers and postMessagestructured clone algorithmreference counting

Related posts

  • Bun v1.0.20

    Bun mediumAdept

    Bun v1.0.20 cuts memory usage in node:fs async operations by avoiding redundant cross-thread string clones. Benchmarks show fs.readlink and fs.stat dropping from 107 MB to about 45–71 MB RSS, and a fs.writeFile leak with large non-ASCII strings falling from 1,696 MB to 91 MB. HTMLRewriter.transform now accepts strings and ArrayBuffers and has a destructor-timing leak fixed, and fs.readFile/writeFile gain hex and base64 encodings. A Linux setTimeout high-CPU regression is fixed, Bun.spawn gains a resourceUsage report, and debug builds use macOS malloc zones to track native allocations.

  • Bun v0.6.9

    Bun mediumAdept

    Bun v0.6.9 focuses on memory reductions: zero-copy string Response bodies in Bun.serve() and Response (60 MB vs Deno's 425 MB and Node's 1414 MB after 1000 responses of a 12 MB string), 50% less memory for cold bun install, and fixed leaks when importing modules. It also fixes non-ASCII filename imports, mockResolvedValue and missing function properties on mocks in bun test, a GC-related crash in the CommonJS require() loader, and a ~192-byte-per-call leak in node:crypto hashing.

  • Bun v1.2.1

    Bun mediumAdept

    Bun v1.2.1 fixes 32 bugs and adds S3 storage class support, X25519 key generation in crypto.generateKeyPair, Node's --zero-fill-buffers flag, indented inline snapshots in bun test, and a bunfig option to disable minification for HTML imports. The most technical change fixes GC memory accounting: WebKit reports a ref-counted string's cost as its byte length divided by its reference count, so Bun's Zig bindings, which briefly held an extra reference, under-reported string memory (a 64 KB file read reported as 32 KB). A new single-step createUTF8ForJS pattern avoids that extra reference. Other fixes cover fs.Stats and bigint fstat parity with Node, EINTR retries in fs reads and writes, a child_process spawn race, Worker reliability, and memory leaks in Bun.serve() and Bun.pathToFileURL caused by refcount mistakes.

  • Bun v1.2.22

    Bun mediumAdept

    Bun v1.2.22 adds async stack traces that include awaited caller frames, a fast path making postMessage and structuredClone up to ~240x faster for plain objects of primitives, and Bun.YAML.stringify. The release fixes interactive /dev/tty reads after stdin closes and improves Bun.SQL's MySQL adapter with affectedRows and lastInsertRowid, corrected TINYINT and BIT type mapping, TLS, and mysql_native_password auth. It also fixes several Postgres driver bugs. Bundler and minifier changes cover new-expression and typeof-undefined minification, an onEnd plugin hook, jsxSideEffects and --keep-names, alongside Node compatibility additions (monitorEventLoopDelay, closeIdleConnections), RFC 6455 WebSocket subprotocol negotiation and Redis database selection via URL.

  • Bun v0.6.2

    Bun easyNovice

    Bun v0.6.2 pulls in JavaScriptCore performance work: number toLocaleString() is 79x faster, JSON.parse is up to 20% faster and JSON.stringify 15% faster on shallow objects, Proxy get/set is 2x or more faster, and Object.assign with empty sources and returning arguments are each 2x faster. Microbenchmarks on an M1 Max show JSON.parse dropping from 1.45µs to 1.1µs, versus 2.44µs on Node 20. It also fixes a minifier bug with rope strings in template literals, a bundler bug where imported assets were never copied to the output directory, and a bug where warnings incorrectly failed builds.

The quest for software engineering knowledge.

Look:
Layout: