Skip to content

CMake: Add option to build with PCH

Clemens Wasser requested to merge clemenswasser/cmake:build-opt into master

This MR introduces PCH for the most expensive includes to improve build times. Additionally, I did some other smaller improvements without using PCH. PCH is only activated when using the Clang or MSVC compiler on any Platform, and for all compilers on Windows. These restrictions exist since Gcc is much slower with these changes.

Here are some Benchmarks that measure the build time of the complete CMake codebase:

All were run on this machine:

CPU: i7-12700k @ 5.0 GHz p-core, 4.0 GHz e-core
RAM: 32 GB, DDR4 @ 3200 MHz
DISK: 1TB NVME 970 EVO Plus
OS: Windows 11 22H2 22621.1848
Windows, Ninja 1.11.0, CMake 3.26.4, BUILD_TYPE=Debug
Before:
  Time (mean ± σ):     44.377 s ±  0.113 s    [User: 577.322 s, System: 95.428 s]
  Range (min … max):   44.260 s … 44.611 s    10 runs
After:
  Time (mean ± σ):     21.530 s ±  0.238 s    [User: 189.654 s, System: 66.940 s]
  Range (min … max):   21.238 s … 21.986 s    10 runs

~2.06x faster

Windows, Clang 16.0.6, Ninja 1.11.0, CMake 3.26.4, BUILD_TYPE=Debug
Before:
  Time (mean ± σ):     49.358 s ±  0.088 s    [User: 710.828 s, System: 70.272 s]
  Range (min … max):   49.237 s … 49.484 s    10 runs
After:
  Time (mean ± σ):     29.211 s ±  0.753 s    [User: 409.431 s, System: 56.650 s]
  Range (min … max):   28.037 s … 29.979 s    10 runs

~1.7x faster

Debian unstable/experimental (WSL2 6.1.21.1-microsoft-standard-WSL2+), Clang 16.0.5, Ninja 1.11.1, CMake 3.25.1, BUILD_TYPE=Debug
Before:
  Time (mean ± σ):     34.459 s ±  0.291 s    [User: 603.326 s, System: 38.245 s]
  Range (min … max):   34.169 s … 35.216 s    10 runs
After:
  Time (mean ± σ):     19.959 s ±  0.163 s    [User: 319.371 s, System: 29.997 s]
  Range (min … max):   19.650 s … 20.167 s    10 runs

~1.73x faster

Topic-rename: build-pch

Edited by Brad King

Merge request reports

Loading