TExcelTAD

Toolkit: Compiler Caches & Distributed Builds

A map of the tools for making builds faster, what each is for, and where this track covers it. "In the image" means it runs for real in this course's sessions.

Compiler and build caches

Tool What it caches Sharing Notes
ccache C/C++/ObjC/CUDA compiles local dir; remote file:, http:, redis: in the image (4.14); this course's main tool
sccache C/C++, Rust, CUDA compiles local, S3, GCS, Azure, Redis, Memcached, GHA cache, WebDAV lesson; also distributed mode
buildcache C/C++ (GCC, Clang, MSVC, also some other tools via Lua wrappers) local + remote (Redis, S3, HTTP) smaller project; good MSVC support
Gradle build cache Gradle task outputs local + HTTP remote (Develocity, open-source cache node) Maven & Gradle
Bazel remote cache every action's outputs, by action digest HTTP/gRPC (bazel-remote, BuildBuddy, EngFlow…) Bazel
Nx / Turborepo cache JS monorepo task outputs local + remote (Nx Cloud, Vercel, self-hosted) Turborepo & Nx
vcpkg / Conan binary caches built packages files, HTTP, NuGet, Artifactory, conan_server vcpkg binary caching
Docker BuildKit cache image layers, RUN --mount=type=cache dirs registry (--cache-to type=registry), GHA Docker

Distributed compilation and remote execution

Tool Model Notes
distcc ship preprocessed source to helper daemons needs identical compilers; pump mode; lesson
icecream (icecc) distcc + central scheduler + shipped toolchains good for office pools of desktops
Incredibuild commercial process virtualisation strong on Windows, Visual Studio, game studios
FASTBuild its own build system with caching and distribution popular in games (used for Unreal-scale C++ codebases)
sccache-dist scheduler + sandboxed build servers C/C++ and Rust
recc + BuildBarn / Buildfarm / BuildGrid / NativeLink REAPI client for plain compilers + REAPI servers remote execution without switching to Bazel
Bazel / Buck2 / Pants + REAPI service build system designed for remote execution Remote Execution, Bazel

Measuring and analysing

Tool Use
ninja -d explain, ninja -t …, .ninja_log what ran and why
ninjatracing .ninja_log → Chrome/Perfetto timeline
Clang -ftime-trace per-TU profiles
ClangBuildAnalyzer aggregate -ftime-trace over a whole build: worst headers, templates, files
include-what-you-use, clangd include cleaner, clang-tidy misc-include-cleaner include hygiene
cmake --profiling-format=google-trace profile the configure step
Gradle build scans / Develocity, Bazel --profile, MSBuild binlogs the same questions for other build systems
Build Insights (vcperf, Visual Studio) MSVC's equivalent of -ftime-trace + analyzer

Faster linking

Tool Notes
lld LLVM's linker, in the image; -fuse-ld=lld, CMAKE_LINKER_TYPE=LLD
mold usually the fastest ELF linker; CMAKE_LINKER_TYPE=MOLD
-gsplit-dwarf, dwp keep debug info out of the link (lesson)

Quick reference: where did a ccache setting come from?

ccache -p prints every option with its origin, which settles most "why doesn't it hit?" arguments:

bash · try it yourself
ccache -o max_size=2G > /dev/null                   # writes the config file
export CCACHE_BASEDIR=$HOME CCACHE_SLOPPINESS=pch_defines,time_macros
ccache -p | grep -E ' (base_dir|cache_dir|compiler_check|hash_dir|max_size|sloppiness) '
(environment) base_dir = /home/learner
(environment) cache_dir = /home/learner/.cache/ccache
(default) compiler_check = mtime
(default) hash_dir = true
(/home/learner/.cache/ccache/ccache.conf) max_size = 2.0 GB
(environment) sloppiness = pch_defines, time_macros

The origin is (default), (environment) for CCACHE_* variables, or the path of the configuration file that set it. Environment variables override the file, which overrides the defaults.

Test yourself

Which tool aggregates -ftime-trace output from every TU into a ranking of the worst headers and templates?

  1. ninjatracing
  2. ClangBuildAnalyzer
  3. IWYU
  4. ccache

You need remote execution for a CMake project without migrating to Bazel. Which combination fits?

  1. distcc + Bazel
  2. recc with a REAPI server such as BuildBarn or Buildfarm
  3. ccache with base_dir
  4. mold

In ccache -p, what does (environment) before a setting mean?

  1. It's the default
  2. It was set by a CCACHE_* environment variable, which overrides the config file
  3. It was set in /etc
  4. It's ignored