What happened

A Zig core contributor published how the compiler's incremental compilation actually works, in four stages. Parsing to ZIR is embarrassingly parallel and cached per file. Semantic analysis decomposes work into "analysis units" — struct layouts, declaration types, const values, function bodies — with a dependency graph between them, so a source edit re-analyses only the affected units; function bodies can only have outgoing edges.

Codegen runs at function granularity, matching that scope. Linking uses link.MappedFile, which memory-maps the output binary and maintains a tree of nodes over file regions, resizing or reallocating them as functions change, with relocations applied during idle time. Net result on a real editor project: roughly a 5-second cold build against 50-70ms incremental rebuilds.

Why it matters

Sub-100ms rebuilds are what make one-person projects feel like a conversation instead of a build queue. The deeper point is a language-design one: function body analysis units can only have outgoing edges, because nothing in Zig can depend on the body of a runtime function — that single property caps how far an edit can propagate and is what makes the dependency graph tractable at all. Incremental compilation is mostly won or lost in the language semantics, years before anyone writes the compiler; the remaining difficulty then moves to linking, which is why the memory-mapped linker is the novel piece.

But, but, but…

The author profiles his own feature and publishes the embarrassing result: a traced 37ms rebuild spent its first 6ms doing all the actual work — file checks, ZIR update, semantic analysis, codegen, linking — and the remaining 31ms walking the reference graph, largely unnecessarily for that change.

That is 84% waste by his own trace, and he calls it 30ms still left to squeeze out. The other caveats are equally blunt: x86_64-linux only, other backends immature, requires the master branch invoked as zig build --watch -fincremental, full caching to disk is not automatic yet, and Zig 0.16.0 lacks linker features expected in 0.17.0. He explicitly warns of live bugs "probably including some false-positive compile errors and even miscompilations." Treat it as a fast inner loop, not a release build — and compare that honesty to any AI benchmark post this month.