Faster Compilation (C++)
C++ is too slow to compile. How to improve compile time ? - r/cpp
- time-trace - timeline / flame chart profiler for Clang
- Faster C++ builds
- Using Precompiled Headers
- 2 tips to make your C++ projects compile 3 times faster
Super fast linker
Replace defauld linker with a faster one (mold)
CCache
Speeds up recompilation by caching previous compilations and detecting when the same compilation is being done again. (mainly for make clean ; make)
-
If you ever run make clean; make, you can probably benefit from ccache. It is common for developers to do a clean build of a project for a variety of reasons, and this discards the results of your previous compilations. By using ccache, recompilation goes much faster.
-
Another reason to use ccache is that the same cache is used for builds in different directories. If you have several versions or branches of a project stored in different directories, many of the object files in a build directory can often be taken from the cache even if they were compiled for another version or branch.
-
A third scenario is using ccache to speed up clean builds performed by servers or build farms that regularly verify that the code builds.
-
You can also share the cache between users, which can be very useful on shared compilation servers.
CCache can be used as delegation mechanism to icecream:
CMake → ccache → icecc → compiler (gcc/clang)
- CMake only sees ccache as the compiler launcher
- ccache delegates to icecc
- Icecream handles distributed compilation
Cached object are in ~/.cache/ccache
# Configure CCache options
$ ccache --show-config
$ ccache --set-config=max_size=10G
$ ccache --set-config=compiler_check=content
# show cache statistics
$ ccache --show-statsInstallation
Ccache can be installed by nix,
yet it make sense to have it available globally (not in a flakes)
$ nix profile add nixpkgs#ccacheCMake
# ccache must be explicitly enable to operate
$ cmake -G Ninja .. \
-DCMAKE_C_COMPILER_LAUNCHER=ccache \
-DCMAKE_CXX_COMPILER_LAUNCHER=ccacheIcecream
Distribute C/C++/CUDA compilation accross several machine.
Architecture
- icecc scheduler – keeps track of available workers and distributes compile jobs.
- icecc worker – runs on client or server machines, executes compilation tasks.
- icecc client – submits compilation jobs (e.g., via icecc gcc).
Workers need to know where the scheduler is. On LAN, workers can broadcast to find schedulers automatically. You may need to disable Firewall for first test to make this happens (and then set appropriate rules latter on).
Setup
We recommend that you use packages maintained by your distribution if possible. Your distribution should provide customized startup scripts that make icecream fit better into the way your system is configured.
# On each Ubuntu machine you want in your compile cluster:
$ sudo apt install icecc
# check
$ sudo systemctl status iceccdOne machine as to run the sceduler
$ sudo systemctl start icecc-scheduler
$ sudo systemctl enable icecc-scheduler
# check
$ sudo systemctl status icecc-schedulerConfig
Using icecream in heterogeneous environments
Under normal circumstances this is handled transparently by the icecream daemon, which will prepare a tarball with the environment when needed. This is the recommended way, as the daemon will also automatically update the tarball whenever your compiler changes.
CCache
The easiest way to use ccache with icecream is to set CCACHE_PREFIX to icecc (the actual icecream client wrapper):
$ export CCACHE_PREFIX=icecc
# or
$ ccache --set-config=prefix_command=iceccicecream-sundae
Commandline Monitor for Icecream. To compile from source => easy setup
require libicecc-dev
see also
- Icemon - Icemon is an Icecream GUI monitor.
see also
- Distributed C++ Compiler
- nocc
- SN DBS - Used by a lot of game developers, to spread mostly compilation (but also shader compile, or custom jobs).
- IncrediBuild - https://www.incredibuild.com/
- Fast build
- icecream - A more modern alternative to distcc, often easier to set up.
- distcc
- Goma
- Bazel / buck / like with various RBE back ends
- ElectricAccelerator
