← Mon, Nov 30 digest

So, I rewrote my game in C3

read article ↗ hn thread ↗

A developer rewrote a 100k LoC game engine from Zig to C3 to fix slow Windows compilation times and created a fast hot-reload scripting subset called SL3.

read it It offers a concrete technical post-mortem on migrating a systems-level game codebase from Zig to C3, complete with performance metrics and architecture details for hot-reloading.

summary

The developer of the game Traction Point migrated a 100,000 LoC codebase from Zig to C3 to overcome sluggish Windows compilation and LLVM linking times, dropping build times from over 15 seconds down to roughly 3 seconds. Because C3 shares a similar explicit, garbage-collection-free memory model with Zig, the porting process was largely mechanical. To maintain rapid iteration during development, the author also built SL3, a strict subset of C3 that compiles to bytecode for virtual-machine-based hot-reloading or native DLLs for production performance.

key points

  1. Full un-cached debug builds for a 100k LoC project dropped from roughly 24 seconds in Zig (with 15s incremental rebuilds) to around 3 seconds in C3.
  2. C3 was chosen for its C-like syntax, lack of garbage collection or RAII, and explicit memory management, allowing a near-mechanical port from Zig.
  3. SL3 is a strict subset of C3 compiled either to bytecode running on a VM for instant hot-reload or natively for peak runtime performance.

who should read it

Game developers and systems programmers interested in alternative languages, build performance, and hot-reload architectures.

discussion positive

consensus

Commenters focus heavily on why Zig compilation is significantly slower than Clang or C3, identifying Zig's monolithic LLVM module generation and single-threaded emission as the primary bottlenecks.

pushback

Some suggest that cross-compiling Zig for Windows from a Linux host or WSL2 mitigates filesystem and build speed issues.

best comment by cornstalks ↗

The vast majority of time is spent in LLVM, though, as reported by `--time-report`.

I did a little research and it looks like Zig puts everything into one module and feeds it to LLVM. That approach is inherently single-threaded because there's just one giant module. Clang, on the other hand, treats each translation unit as a module, so it works in parallel. Presumably c3c works the same but I'm not familiar with it.

I really wish Zig would parallelize the object file emission in a way that would benefit any selected backend (i.e. whether LLVM or their own backend).

It pinpoints the exact structural reason why Zig compilation is slower than Clang or C3: feeding a single giant module to LLVM instead of processing translation units in parallel.

Generated by an LLM from the article and thread. Check the sources before relying on it.