Zig versus Rust and C++: who decides where the memory goes?

New Programming Languages versus Rust / C++

Two teams took the same decision in opposite directions. The people behind Bun, a tool for running JavaScript, replaced much of their Zig code with Rust. The people building the Roc compiler went from Rust to Zig. Both had already shipped software. Both knew what it cost to start again. The disagreement becomes easier to understand once you ask what each team wanted its compiler to catch before a program ever reached a user.

What a sound editor can teach a language designer

Consider a program that must supply the next fragment of sound before the loudspeaker needs it. A pause to find more memory may be inaudible on one machine and a click on another. The engineer has a good reason to know which operations can request memory, how failures are reported and which work can be done in advance. Kelley came to language design from audio software. In his 2016 introduction he set out to build a practical alternative to C and showed how the caller could control storage. His later work at OkCupid gave him another vantage point, maintaining C++ written years before he joined. Kelley’s original design account.

Three ways to own a buffer

Suppose a terminal receives a long line of text. It might fit in the space already reserved. Otherwise someone must find more memory, copy the characters and decide when the old space may be released. In Zig, library code that needs to allocate commonly accepts an allocator from its caller. The caller can give it a fixed buffer, a general allocator, or an arena that releases many objects together. An allocation can fail. An error can travel back to the caller. The same routine can therefore be tested with very little memory and used with a different allocation policy in production. Zig’s worked examples.

A C++ team can also choose an allocator. A standard vector manages its storage and releases it when the owning object is destroyed. If growth moves the elements elsewhere, a pointer to the old storage can become invalid. Safe Rust makes a different promise. A reference cannot be used after its owner’s lifetime ends, and the borrow checker can reject code that keeps a reference across an incompatible mutation. Zig gives the programmer more responsibility for these relationships. Its Debug and ReleaseSafe modes check operations such as indexing past the end of an array. Those checks cover different mistakes from Rust’s lifetime rules. ReleaseFast and ReleaseSmall disable many safety checks by default. The build mode belongs alongside any claim about either safety or speed. Zig language reference · Rust ownership · C++ resource management.

From source to a program somebody can run

Zig compiles ahead of time. A developer selects a target architecture and operating system, then builds an executable or a library. Some computations explicitly take place during compilation. For instance, a routine can use the fields of a known type to generate specialised code before the application starts. Zig’s toolchain also works with C, a practical advantage when a new component must fit into an existing application. Cross-compiling can spare a team a separate build machine for every target. Testing on the destination and supplying the libraries or SDK it requires still matter. Zig’s compiler itself was once implemented in C++. The project subsequently retired that implementation in favour of its own. Compiler and cross-compilation examples · The compiler’s transition from C++.

What five million orbital steps actually measure

An independent benchmark collection provides a modest test that readers can inspect. Programs advance a small system of gravitating bodies through five million steps. The published run of 1 August 2025 used four available cores on an AMD EPYC 7763 host. The table gives elapsed time for individual programs. Its first column takes the fastest listed entry in each of the three languages for this input. Its second column follows the entries named 1 in those languages, using GCC for both C++ entries. Shared file numbers do not establish identical algorithms or optimisation effort.

Fastest listed times: Rust 163 ms, C++ 167 ms and Zig 198 ms. For the programs named 1: Rust 229 ms, C++ 316 ms and Zig 315 ms.
One calculation, six implementations. Shorter bars indicate shorter elapsed times. Graphic by The Bible of AI from Hanabi1224’s n-body results. Enlarge figure.
Elapsed time and source file for each reported run
CompilerFastest listedVariant named 1
rustc 1.88.0163 ms · 4-i.rs229 ms · 1.rs
g++ 11.4.0167 ms · 0-i.cpp316 ms · 1.cpp
Zig 0.14.1198 ms · 3.zig315 ms · 1.zig

Choose the fastest entries and Rust finishes 35 milliseconds before Zig. Choose the second column and a single millisecond separates C++ and Zig, comparable to the variation reported for those runs. Changing just the Zig program moves its time by 117 milliseconds. This is one numerical workload on one machine with earlier compilers. It tells us little about the responsiveness of a terminal, the time required to compile an application or the number of faults a team will have to investigate. Measurements and individual source links · Comparison programs.

Who stayed, who left and what they learned

Ghostty offers direct evidence of continuing use. Its platform-specific interfaces share a terminal core written in Zig. For the Roc compiler team, explicit allocators and control over data layout helped justify rewriting a Rust implementation in Zig. That decision had costs. Roc’s own retrospective identifies two cases in which its rewritten error-reporting code used freed memory and displayed a damaged filename. Its authors say Rust’s borrow checker would have caught both. They also changed the compiler’s architecture during the rewrite, which makes a simple before-and-after speed comparison misleading. Ghostty’s architecture · Roc’s experience report.

Bun went the other way. Its creator, Jarred Sumner, began using Zig in 2021. As the runtime grew, his team wanted stronger tools for tracking ownership across a large codebase. A socket, for example, can be referenced by several parts of a program while an operation is pending. Releasing it too early can surface much later as a crash. Sumner describes trying to enforce ownership conventions in Zig and then moving the runtime’s Zig implementation to Rust. Bun 1.4 shipped the change. Kelley’s response places greater weight on the implementation practices he observed and on the two projects’ different priorities. These are first-hand accounts of the same departure from different positions. Sumner’s account · Bun’s release · Kelley’s response.

Individual departures are harder to count. One developer who moved from Zig to C3 publicly explained that C3 offered features they had missed in Zig. It is evidence of a personal choice. Together with Bun it establishes that people have left, while providing no denominator from which to calculate how often that happens. The developer’s explanation in the discussion.

A foundation, a change of host and two different roles for AI

The Zig Software Foundation stewards the language and publishes its funding information. The former GitHub repository points readers to Codeberg. In the migration announcement, Kelley cited problems scheduling automated jobs on GitHub Actions that had held up Zig’s own checks, alongside a broader disagreement with the platform’s direction. That is a specific, attributed account of what happened to one project. Readers can follow its development at the new address. Foundation · Migration announcement · Former GitHub home · Current repository.

Zig’s contribution policy expressly bars work generated with large language models in the project spaces it governs. Bun has a different policy. Sumner discloses that he used Claude extensively for Bun’s move to Rust. The distinction matters. One project makes the compiler, another uses it, and a single programmer may encounter both policies in the course of a working day. Zig’s contribution policy · Bun’s disclosure.

The decision a team can test

Return to that growing line of text. If the hard part is fitting it into a fixed memory budget, Zig makes the allocation decision visible to the caller. If the recurring fault is a reference surviving the object it belongs to, Rust can rule out an important class of errors before release. An established C++ team may already have an allocator, ownership conventions and years of tests for precisely that component. A useful trial would take its real workload, force the allocation to fail, change the buffer size and measure both latency and the effort required to find a mistake. That would tell the team something a league table cannot tell it about its own next release.

Liked this post? Follow this blog to get more.