Richard Waller

Incremental Everything

Software is never done. Requirements change, bugs are found, optimizations are needed. Yet most build systems treat compilation as an all-or-nothing affair: change one file, rebuild everything.

This is wasteful. Most changes are local—a function modified here, a type changed there. The dependencies are usually small. But traditional build systems are conservative: if a file changes, everything that might depend on it must be rebuilt.

The Dependency Problem

The challenge is tracking dependencies accurately. Coarse-grained dependencies—“file A depends on file B”—are easy but imprecise. If you change a function in B that A doesn’t use, A shouldn’t need recompilation. But the build system doesn’t know.

Fine-grained dependencies—“function A depends on function B”—are precise but expensive to compute. You need to parse source files, build ASTs, track cross-references. The dependency analysis can take longer than the compilation itself.

The solution is persistence. Compute the dependency graph once, store it, update it incrementally. When a file changes, update only the affected parts of the graph. Modern build systems are moving in this direction.

The Compiler Problem

But dependency tracking isn’t enough. Traditional compilers aren’t designed for incremental compilation. They parse the entire file, build the entire AST, generate code for everything. Even if only one function changed, the entire file is recompiled.

Incremental compilation requires compiler support. The compiler must:

  • Track what it compiled (to avoid recompiling unchanged code)
  • Track dependencies (to know what to recompile when dependencies change)
  • Support partial compilation (to compile only what changed)

This is hard. Most compilers aren’t designed this way. But the benefits are enormous: sub-second rebuilds even in large codebases.

The Cache Problem

Even with incremental compilation, you might compile the same code multiple times. Different developers, different machines, different branches—all might compile the same unchanged code.

Build caches solve this. Compile once, cache the result, reuse it everywhere. But traditional caches are fragile: any change invalidates the cache, even if the change doesn’t affect the compiled output.

Content-addressable caches are better. Hash the inputs (source code, compiler flags, dependencies), use the hash as the cache key. If the hash matches, the output is the same. This approach is becoming standard in modern build systems.

The Human Problem

But the biggest challenge isn’t technical—it’s human. Developers are used to “clean builds.” They’re suspicious of incremental builds. “Did it really rebuild everything?” “Is the cache stale?” “Should I do a clean build just to be sure?”

This requires cultural change. Incremental builds must be trustworthy. The tooling must make it clear what was rebuilt and why. Debugging must work with cached artifacts.

The Future

As codebases grow, incremental builds become essential. A 50,000-file codebase that takes 45 minutes to build cleanly is unusable if every change requires a full rebuild. But with incremental builds, a single-file change can rebuild in under a second.

The technology exists. Modern build systems prove it’s possible. The challenge is adoption: getting compiler writers to support incremental compilation, getting build system authors to implement fine-grained dependencies, getting developers to trust the tools.

Conclusion

Incremental compilation isn’t just an optimization—it’s a fundamental shift in how we think about builds. Instead of “compile everything,” we “compile what changed.” Instead of “rebuild from scratch,” we “rebuild incrementally.”

This requires better tools, better compilers, better dependency tracking. But the result is worth it: builds that are fast enough to be invisible, fast enough that compilation isn’t a barrier to iteration.

References