Skip to content

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

TigerBeetle 3 min read Deep dive mediumAdept

Enum of Arrays

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. Amortizing the tag saves memory, avoids padding waste between differently sized variants, and replaces per-item unpredictable branches with a single branch per batch, which also opens the loop to SIMD. TigerBeetle applies this by processing homogeneous batches of about 8k accounts or 8k transfers rather than mixed operations, mirroring a control plane/data plane split.

Assumes: struct memory layout and paddingtagged unionsSIMD basicsbranch prediction

Related posts

  • Swarm Testing Data Structures

    TigerBeetle mediumAdept

    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 tests its intrusive queue against a ring-buffer model and adds swarm testing: rather than picking operations uniformly, each run randomly chooses a subset of operations and random weights for them, so runs reach states like long queues that uniform push/pop never produces. Code is included for weighted enum sampling, random weight generation and an allocation-free k-combination helper.

  • Writing High-Performance Clients for Tigerbeetle

    TigerBeetle mediumAdept

    TigerBeetle builds every language client as a thin wrapper over a single Zig client library, tb_client, exposed through FFI. This avoids reimplementing the VSR protocol, io_uring and static allocation in each language. Zero-deserialization works directly with Go and C# structs. Java instead uses a ByteBuffer-backed Batch object so JNI can read contiguous memory without per-object copying or GC pressure. tb_client runs a dedicated thread with completion callbacks, which each binding wraps in its own concurrency idiom: goroutines, async/await and CompletableFuture. A client-side benchmark of 1M rejected transfers shows near-native throughput (Zig 1.56M/s, C# 1.52M/s, Go 1.47M/s, Java 1.27M/s). Zig's cross-compilation offsets the cost of per-platform builds.

  • Arch-specific SIMD in Go

    The Go Blog hardMaster

    Go 1.27 extends the experimental architecture-specific SIMD API (simd/archsimd, enabled with GOEXPERIMENT=simd) from amd64 to arm64 NEON and wasm 128-bit SIMD. The design uses typed vector structs, readable method names unified across architectures, opaque mask types that the compiler peepholes into masked instructions, and new zero-cost reinterpretation methods (ToBits, ReshapeToUint<W>s) that replace Go 1.26's As<Type> methods. Worked examples reverse bits with GFNI affine transforms and transpose an 8x8 matrix with AVX2 lane-grouped permutes. Practical advice: guard code with CPU feature checks, which avoid SIGILL and also enable fused AVX-512 lowering; write loop bounds as i < len-n+1 so bounds checks are eliminated; and pass vectors as separate values rather than arrays or structs so they stay in registers.

  • Index, Count, Offset, Size

    TigerBeetle mediumAdept

    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`. Zig examples from NodePool and an EWAH decoder show wrong combinations becoming visible from names alone. The convention works together with big-endian naming (qualifiers as suffixes) and equal-length dual names like source/target, which line code up so mistakes stand out.

  • Shipping a Trillion Parameters With a Hub Bucket: Delta Weight Sync in TRL

    Hugging Face hardMaster

    Between consecutive RL optimizer steps, about 99% of bf16 weights stay bit-identical because Adam updates at RL learning rates fall below bf16's rounding threshold (|Δw| < |w|/256). TRL exploits this by detecting changed elements with optimizer pre/post-step hooks, encoding them as sparse safetensors deltas (int32 indices plus bf16 values), with full anchors every N steps, and pushing them to a Xet-backed Hugging Face Bucket that vLLM pulls from. On Qwen3-0.6B the per-step payload drops from 1.2 GB to 20–35 MB, and inference pauses for about a second instead of the full sync time. Because the bucket is the only shared channel, the trainer, vLLM server and environment can run on separate machines or Spaces with no shared cluster or RDMA.

The quest for software engineering knowledge.

Look:
Layout: