---
title: "500x faster postMessage(string)"
description: "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)."
url: "https://swe.quest/articles/500x-faster-postmessage-string-575e19a5ee69829f"
canonical: "https://bun.com/blog/how-we-made-postMessage-string-500x-faster"
source: "Bun"
published: "2025-08-20"
difficulty: "medium"
kind: "Deep dive"
reading_minutes: 3
tags: ["runtimes","javascript","performance","concurrency"]
---

# 500x faster postMessage(string)

A post on [Bun](https://swe.quest/sources/bun.md), published 2025-08-20, 3 min read, Deep dive. Original: [https://bun.com/blog/how-we-made-postMessage-string-500x-faster](https://bun.com/blog/how-we-made-postMessage-string-500x-faster)

## Summary

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.

Written by swe.quest, not by the author.

**Difficulty:** Medium: assumes a working developer; shows how it is built or done

## Topics

- [Runtimes & VMs](https://swe.quest/tags/runtimes.md) (Compilers & runtimes)
- [JavaScript](https://swe.quest/tags/javascript.md) (Languages)
- [Performance engineering](https://swe.quest/tags/performance.md) (Reliability & operations)
- [Concurrency](https://swe.quest/tags/concurrency.md) (Compilers & runtimes)

## Prerequisites

- Web Workers and postMessage
- structured clone algorithm ([easy posts on Algorithms](https://swe.quest/tags/algorithms.md?difficulty=easy))
- reference counting

## Keywords

Bun, JavaScriptCore, postMessage, Structured Clone Algorithm, WebKit, StringImpl

## Related posts

- [Bun v1.0.20](https://swe.quest/articles/bun-v1-0-20-4c5d451d499e769b.md): Bun · 2023-12-24 · Medium · 6 min read · JavaScript, Runtimes & VMs, Memory management, Performance engineering
  Bun v1.0.20 cuts memory usage in node:fs async operations by avoiding redundant cross-thread string clones.
- [Bun v0.6.9](https://swe.quest/articles/bun-v0-6-9-0635261452349fca.md): Bun · 2023-06-13 · Medium · 3 min read · JavaScript, Runtimes & VMs, Memory management
  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.
- [Bun v1.2.1](https://swe.quest/articles/bun-v1-2-1-aab3e8d9e0004536.md): Bun · 2025-01-27 · Medium · 7 min read · JavaScript, Runtimes & VMs, Memory management, Zig
  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.
- [Bun v1.2.22](https://swe.quest/articles/bun-v1-2-22-c985f96b20e06efe.md): Bun · 2025-09-14 · Medium · 16 min read · JavaScript, Runtimes & VMs, Build systems, MySQL, Debugging
  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.
- [Bun v0.6.2](https://swe.quest/articles/bun-v0-6-2-b67998d40f2097f2.md): Bun · 2023-05-17 · Easy · 3 min read · JavaScript, Runtimes & VMs, Performance engineering
  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.

Browse: [Latest posts](https://swe.quest/index.md) · [Topics](https://swe.quest/tags.md) · [Sources](https://swe.quest/sources.md) · [Topic map](https://swe.quest/map.md) · [Site guide (llms.txt)](https://swe.quest/llms.txt)
