Speeding up C++ build times
C++ developers are revisiting the long‑standing problem of slow compile times, prompted by a Figma blog post that many see as rediscovering decades‑old advice. Commenters emphasize that excessive header inclusion, heavy template use, and fragmented translation units are major culprits, and point to practical mitigations like ccache, distributed builds, precompiled headers, “unity” builds, strict include discipline, and PIMPL for ABI stability. Others argue that deeper fixes—such as C++20 modules or alternative languages and build models—are needed, while noting that current module and tooling support remains immature for large real‑world codebases.
Overall reaction to the blog post
- Many commenters find the post shallow and self-promotional, arguing it “reinvents the wheel” and rehashes decades‑old C++ knowledge (headers, IWYU, PIMPL, etc.).
- Some say the interesting part is the attempt to auto‑refactor a large C++ codebase and the pain of tooling (libclang, LibTooling), but they still wanted more technical depth and data.
- A few defend the topic as valid, but think solutions like ccache, distcc, unity builds, and linkers are under‑emphasized.
Headers, includes, and PIMPL
- Strong focus on reducing included headers: IWYU, forward declarations, PIMPL, Rob Pike–style “no headers-in-headers,” and avoiding transitive include explosions.
- Others argue modern compilers optimize away duplicate header parsing via include guards /
#pragma once, so header discipline mainly helps via reduced dependencies, not raw re-parsing. - PIMPL sparks heated debate:
- Pro: improves ABI stability, hides implementation, and can help build times.
- Con: feels like a hack, adds indirection/boilerplate, highlights C++’s inability to cleanly separate interface from layout.
Build tooling and workflows
- Common “practical fixes”:
- Compiler caches (ccache/sccache), distributed builds (distcc, icecream, Incredibuild), and remote workers (Bazel).
- Faster linkers (mold) and parallel builds (ninja, CMake presets).
- Precompiled headers and explicit template instantiation.
- Several note that for large projects, link time and template-heavy optimization (e.g., Eigen) dominate, not just preprocessing.
- Some report dramatic improvements (minutes to seconds) from ccache or unity builds; others say incremental builds and linker bottlenecks limit these gains.
Unity / jumbo / single-TU builds
- Widely discussed technique: concatenate many or all .cc files into few big translation units (unity/jumbo/master files).
- Benefits: fewer redundant header parses and more inlining; cited 5–10× compile-time speedups in games and projects like SQLite.
- Downsides: harder incremental builds, tricky failure modes, reduced parallelism unless carefully batched.
Language and ecosystem limitations
- Frustration that C++’s header/preprocessor model is fundamentally flawed; comparisons made to Ada, D, Jai, Rust, and Go.
- C++20 modules seen as a potential big win but currently “bleeding edge,” poorly integrated in tooling/build systems, and not widely adopted (tracked by “are we modules yet” resources).
- Some argue that C++ culture tolerates slow builds and over-complex features, making real fixes slow to arrive.