Rust vs Zig Compilation Time
I thought Bun’s controversial rewrite from Zig to Rust would be an<br>ideal benchmark for compilation time. Unfortunately neither Anthropic nor Andrew<br>Kelly seem to want to benchmark both, so I have done a quick<br>test.
My hardware is has an AMD Ryzen 9 3950X 16-Core CPU at 3.5 GHz, with<br>128 GB of RAM (DDR4). This was top of the line about 5 years ago, and is<br>still a powerful machine (no more Moore’s law) but it was very cheap<br>second hand (~£300).
Zig
Bun has a quite complex build system so to get just the Zig times, I<br>built it first (b8ecc78b03c998c228be4520bb8d2f888624e4a1<br>just before the Rust rewrite) using bun run build, then<br>deleted build/debug/cache/zig and<br>build/debug/bun-zig.*.o, then ran<br>time bun run build.
I’m not too familiar with Zig but this seemed to cause it to do a<br>complete rebuild.
Total real time: 39.1s.
This is a lot slower than Andrew Kelly’s claim of 16s. Maybe he has<br>an enormous machine?
Rust
For Rust (23427dbc12fdcff30c23a96a3d6a66d62fdc091d just<br>after the Rust rewrite) you still build with bun run build,<br>so I did that, and then deleted build/debug/rust-target,<br>which is sufficient to cause a complete Rust rebuild.<br>time bun run build reports
Total real time 1m33s.
Incremental?
What about incremental compilation time? I don’t know how to enable<br>incremental builds in Zig so I’ll take Andrew Kelly’s word that it’s<br>super fast (he claimed 90ms).
For Rust I edited src/runtime/lib.rs (seemed like a<br>reasonable typical case) and this gave a build time of 21.8s. Definitely<br>significantly worse. Although it does seem like Rust only actually takes<br>10.0s and does some other stuff for 11s, not sure what is going on<br>there.
...<br>Compiling bun_bin v0.0.0 (/home/tim/d1/bun/src/bun_bin)<br>Finished `dev` profile [unoptimized + debuginfo] target(s) in 10.02s<br>[2/4] link bun-debug<br>[3/4] bun-debug --revision<br>1.3.14-debug+23427dbc1<br>[build] done
real 0m21.487s<br>user 0m39.053s<br>sys 0m9.560s<br>So for clean builds Zig has a way smaller compile time advantage over<br>Rust than I expected, but it looks like for incremental builds Rust<br>still has a way to go.