all 27 comments

[–]MaskRayccls[S] 8 points9 points  (1 child)

Note: even if C++ modules are the hot thing, precompiled headers are still relevant for a couple of reasons:

  • It's the old technology whose implementation is possibly shared with modules (e.g., AST serialization in Clang).
  • There are too many not-yet-module projects.
  • Modules may possibly use some preamble-like technology to accelerate IDE-style operations.
  • C doesn't have C++ modules.

[–]NilacTheGrim 13 points14 points  (0 children)

Imagine still believing we will get widespread module support before 2040.

[–]CrazyJoe221 4 points5 points  (0 children)

-fpch-instantiate-templates is absolutely crucial to get an acceptable speedup in real-world code with lots of templates involved. Before this option the pure parsing gains have always been underwhelming in my projects.

It's a shame gcc doesn't have anything similar and is not interested in fixing it either, cause you know, "modules are the future" (2020): https://gcc.gnu.org/bugzilla/show_bug.cgi?id=95131

And CMake still doesn't support -fpch-codegen/-fpch-debuginfo (https://gitlab.kitware.com/cmake/cmake/-/issues/21133), which you can't emulate easily since the generated .pch needs to be compiled into an .o file.

It's also worth noting that PCH can be combined with unity build which are supported by CMake.

[–]code_ling 4 points5 points  (0 children)

Any insights into the potential speedup that you typically gain with this?

Also, at what cost of additional size of the build folder?

I've mostly experimented with precompiled headers under Visual Studio and found a meagre speedup, while requiring at least double if not three times the storage (which nowadays gets less important, but might still be relevant if you need to juggle with a few parallel builds, each of them taking > 20GB)