Skip to content

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

TigerBeetle 11 min read How-to mediumAdept

Copy Hunting

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. A small line-by-line tool, copyhound, flags large `llvm.memcpy` calls per function and also sums IR lines per generic function name to expose monomorphization blowup, the same idea as cargo-llvm-lines. In TigerBeetle it traced copies to `std.meta.eql`, which was replaced with a comptime-checked word-wise byte comparison. In the Zig compiler it found an inlined float-parsing slow path costing 10 KB of stack, fixed with `@setCold`. Making comptime parameters runtime in a version-printing function cut 300 bytes from the binary.

Assumes: Zig or Rust basicscompiler optimization basicsgenerics and monomorphization

Related posts

  • Synadia and TigerBeetle Pledge $512,000 to the Zig Software Foundation

    TigerBeetle easyNovice

    Synadia and TigerBeetle are jointly donating $512,000 to the Zig Software Foundation over two years, with no strings attached. The post explains why TigerBeetle chose Zig over Rust and C in 2020. TigerBeetle uses static allocation per NASA's Power of Ten rules and runs single-threaded because transaction contention defeats partitioning, so Rust's borrow checker mattered less than Zig's bounds checking, checked arithmetic by default and absence of hidden allocations or control flow. Three bugs the borrow checker would have prevented were caught by fuzzing on 1,000 dedicated cores, and the upgrade to Zig 0.15.2 made debug builds 2x faster and LLVM release builds 1.6x faster.

  • bun.report is Bun's new crash reporter

    Bun mediumAdept

    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. Instead of shipping 9–250 MB of debug symbols or uploading core dumps, Bun computes module-relative addresses using platform APIs (GetModuleHandleExW, dl_iterate_phdr, dyld image slide). A server then fetches symbols by commit and symbolizes them with llvm-symbolizer before pre-filling a GitHub issue. Zig comptime reflection generates the packed feature bitfield automatically from a struct of counters.

  • Speculative Optimizations for WebAssembly using Deopts and Inlining

    V8 hardMaster

    V8 in Chrome M137 adds speculative call_indirect inlining and deoptimization support for WebAssembly, using runtime call-target feedback gathered by the Liftoff baseline compiler so TurboFan can inline up to four likely callees behind cheap instance and target checks. When an assumption fails, the Deoptimizer serializes the optimized frame into a FrameDescription, rebuilds the matching Liftoff stack frame and resumes in baseline code mid-function. This lets the optimizer drop generic slow paths that would otherwise block further optimization. The gains matter most for WasmGC languages like Dart, Java and Kotlin: over 50% average speedup on Dart microbenchmarks and 1–8% on realistic applications, with one microbenchmark dropping from 675 ms to 90 ms.

  • Rewriting Bun in Rust

    Bun mediumAdept

    Bun, a 535k-line Zig JavaScript runtime, was mechanically ported to Rust over 11 days using about 50 continuously running Claude Code workflows. The motivation was a steady stream of use-after-free, double-free and leak bugs that came from mixing JavaScriptCore's garbage-collected values with manually managed Zig memory. The port was done all at once in a deliberately Zig-shaped style, guided by a porting guide and a lifetimes map, and validated against Bun's language-independent TypeScript test suite. Adversarial review in separate context windows caught bugs such as Box drops before async uv_close, negative-time timespec errors, and eager unwrap_or evaluation; cleanup toward idiomatic, less-unsafe Rust is planned after v1.4.

  • Speeding up LZ4 in ClickHouse

    ClickHouse hardMaster

    LZ4 decompression often tops ClickHouse query profiles because highly compressible, cached columnar data shifts the cost onto CPU, yet storing data uncompressed proved impractical due to disk space. LZ4 is an LZ77 variant whose compressed blocks alternate literals and matches within a 64 KB sliding window, and whose compressor finds matches through a hash-based "cache table". Decompression speeds up when generic memcpy is replaced by inlined over-copying routines such as wildCopy8, which may safely read and write extra bytes inside buffer bounds. The fast decoder skips bounds checks on match copies, so untrusted input needs checksums, guard pages or the safe decoder.

The quest for software engineering knowledge.

Look:
Layout: