News for hackers. Stuff that matters.
Re:C++ Cheat Sheets by woodruffw on Sunday March 06, 2022 @05:31PM (#30581935)
This is all solid advice (particularly using a faster linker).

IME, the single best way to reduce your C++ compile times is to compile less code:

* Remove all unnecessary headers. Template expansion is slow, and preprocessing is even slower. Some of the standard includes (like `<regex>` and `<iostream>`) are notorious for slowing individual translation units to a crawl. `#pragma once` for your own headers also helps with cpp-time performance.

* Forward-declare as much as you can. Forward type declarations mean that the compiler doesn't need to process all of `Foo` when it sees `Foo&` or `Foo`.

Use pImpl wherever you can (and makes sense). Private implementations similarly reduce the amount of code the compiler needs to analyze.

For better or worse, the current winds suggest that C++ compilation times will only continue to get worse (more constexpr/consteval, even more complex templating features/concepts, etc.).

Re:C++ Cheat Sheets by ncmncm on Sunday March 06, 2022 @09:39PM (#30583621)
Constexpr improves compilation speed by the degree that it displaces template metaprogramming. Template metaprogramming runs at Python speed, where constexpr runs orders of magnitude faster. Anywhere you have a choice between them, choose constexpr.

Substantial improvement in compilation speed might depend on use of JIT techniques, running generated code in the compiler to perform template evaluation. I.e., a template is not just a data structure, it is a compile-time function that, where used much, is compiled to optimized machine code, its run-time values being what we think of as types. Thus far, all these functions are run like an interpreter walking a syntax tree.

Precompiled headers, or module intermediate files, could have this code in them already optimized.

Re:C++ Cheat Sheets by McKayDavis on Sunday March 06, 2022 @06:33PM (#30582358)
> * Remove all unnecessary headers. Template expansion is slow, and preprocessing is even slower. Some of the standard includes (like `<regex>` and `<iostream>`) are notorious for slowing individual translation units to a crawl. `#pragma once` for your own headers also helps with cpp-time performance.

> * Forward-declare as much as you can. Forward type declarations mean that the compiler doesn't need to process all of `Foo` when it sees `Foo&` or `Foo`.

I've found the include-what-you-use (IWYU) tool [1][2] can help immensely with automating this process, especially on large code-bases.

It uses LLVM/Clang to analyze a .cpp file / translation unit and produces the minimal subset of exactly which includes are necessary and what types can be forward declared.

[1] https://include-what-you-use.org/

[2] https://github.com/include-what-you-use/include-what-you-use

Re:C++ Cheat Sheets by jcelerier on Monday March 07, 2022 @03:24AM (#30585411)
Yep, all of this is good advice but requires being able to change the code, which is far from a given in c++ where you may have to work with a dozen proprietary SDKs.

I personnally use clang -ftime-trace to see which headers take the most time and then Qt Creator's "find all places where this file is included" feature to try to make the most efficient cleanups