Rewriting Bun in Rust
Bun, a 535k-line Zig JavaScript runtime, was mechanically ported to Rust over 11 days using about 50 continuously running Claude Code workflows.
Topics Languages
Zig language.
Bun, a 535k-line Zig JavaScript runtime, was mechanically ported to Rust over 11 days using about 50 continuously running Claude Code workflows.
Custom automation that doesn't fit CI, such as TigerBeetle's fleet running the VOPR deterministic simulation fuzzer, works best when it lives in the main repository, is written in the project's own language, and auto-deploys from the tip of main.
TigerBeetle uses a strict naming convention to catch off-by-one and index-space bugs that types don't easily prevent: `count` is a number of items, `index` points at an item (invariant `index < count`), `size` is a byte count (`size = @sizeOf(T) * count`), and `offset` is the bytewise counterpart of index. `length` is banned because it is ambiguous, for example Rust's byte-size `str::len` versus Python's code-point `len`.
TigerBeetle's Adaptive Replication Routing (ARR) puts the primary in the middle of a replication ring so no single dropped message is critical.
Synadia and TigerBeetle are jointly donating $512,000 to the Zig Software Foundation over two years, with no strings attached.
Instead of threading a full virtualized Clock interface through every component, two lighter patterns often suffice for handling time in reliable systems.
Bun's package manager installs dependencies roughly 7× faster than npm, 4× faster than pnpm and 17× faster than yarn because it treats installation as a systems programming problem: the bottleneck on modern NVMe hardware is system call and thread-coordination overhead, not I/O wait. strace benchmarks show bun making ~166k syscalls versus ~1M for npm and ~4M for yarn, with almost no futex contention, because its Zig code calls the kernel directly instead of going through Node's libuv thread pool.
Zig's comptime reflection (std.meta.DeclEnum) can turn a data structure's public API into an enum that drives a model-based property test, so adding a new public method triggers a compile error from the non-exhaustive switch until the test covers it.
TigerBeetle replaced its Docusaurus docs site with a custom static site generator built on Zig's build system and Pandoc.
TigerBeetle has added Vortex, a non-deterministic, generative full-system test harness that complements its Deterministic Simulation Testing by exercising real production binaries and client libraries from the outside in.
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.
Struct-of-Arrays has a dual for tagged unions: an Enum of Arrays, where one tag covers a whole batch of homogeneous payloads instead of each element carrying its own tag.
Bun v1.1.39 introduces bun.lock, a JSONC text lockfile enabled via `bun install --save-text-lockfile`, replacing the hard-to-review binary bun.lockb and planned as the default in Bun v1.2.
Bun v1.1.33 fixes 8 bugs, mostly in `bun install`. The default maximum of simultaneous network connections drops from 256 to 64 to avoid install slowdowns, `optional = false` in bunfig.toml now actually skips optional dependencies, and failed optional-dependency postinstall scripts are ignored and their half-installed directories removed.
Bun v1.1.17 fixes four bugs and makes two small macOS performance improvements.
A minimal snapshot testing library can be built without macros, external tools or editor integration: the core primitive is a self-updating string literal that records its source file and line (via Zig's @src()) and rewrites itself in place on mismatch.
Bun v1.1.5 replaces unsymbolicated crash output with a compact ~150-byte bun.report URL that encodes platform, subcommand, commit SHA, a 64-bit feature-usage bitfield, crash type and message, and ASLR-adjusted stack addresses as base64 VLQs, with no personal information.
Design by contract mostly reduces to types and assertions, but a real contract needs two parties: the same condition asserted at both the definition site and the call site.
Reading Zig's emitted LLVM IR as plain text and grepping it is a practical substitute for staring at disassembly when chasing implicit memcopies and binary bloat.
TigerBeetle's deterministic simulator, the VOPR, is compiled to WebAssembly via Zig and wrapped in a playable browser game that runs real TigerBeetle replicas across three levels.
Bun v0.6.13 adds Date mocking in bun test via setSystemTime, which affects Date.now(), new Date() and Intl.DateTimeFormat without mutating the Date object as Jest does.
Treating a fuzzer's byte slice as a finite PRNG unifies coverage-guided fuzzing with structured property-based testing: the entropy length measures input complexity, gives test-case minimization almost for free, and tells interactive simulations when to stop injecting faults.
TigerBeetle builds every language client as a thin wrapper over a single Zig client library, tb_client, exposed through FFI.
TigerBeetle's I/O layer wraps io_uring on Linux and kqueue on macOS behind a single callback-based, completion-oriented API, so business logic can schedule reads and writes anywhere instead of in one giant switch loop.