I haven’t used C++ in quite a while, but aren’t templates a big part of this issue?
I haven’t used C++ in quite a while, but aren’t templates a big part of this issue?
https://www.godbolt.org/z/G18WGdET5
...add <string> and <algorithm> and you're at 45kloc:
https://www.godbolt.org/z/Whv73YPYh
...and those numbers have been growing steadily by a couple thousand lines in each new C++ version.
Multiply this with a few thousand source files (not atypical with the old 'clean code' rule to prefer small source files, e.g. one file per class), and that's already dozens to hundreds of million lines of code the compiler needs to process on a full rebuild, all spent on compiling <vector> over and over again.
TL;DR: the most effective way to improve build times in C++ is to split your project into few big source files instead of many small files (either manually, e.g. one big source file per 'system', or let the build system take care of it via 'unity' or 'jumbo' builds).
> which are the only ones that really matter to software development.
Debatable in this age of cloud CI builds ;)
A lot of time is spent in the linker because the linker needs to parse and deduplicate any monomorphized C++ classes (like vector). This takes time proportional to the number of compiled copies of the class / function that are kicking around.
So I'd expect linking times to also decrease if you're compiling fewer, larger source files.
Linking is pretty much just I/O-bound unless you're using LTO. This is assuming you're using a modern linker like mold.
Also, many C++ projects I've seen indirectly include almost anything into anything under the hood, so a header change on one end of the project may trigger a rebuild of seemingly unrelated source files.
Such solution introduces more funny failure modes into build though. People get quite irritated when no change edit in a single file breaks build :)
I also don't believe in tiny instantiation units, but when compiling real code, parsing the headers themselves is not necessarily the bottleneck.