3 ms·
Precompiled headers were supposed to help this, but don't work well in practice, since they become hundreds of MB in size, which is just as slow as #includes, s
by oppositelock 12y ago
Precompiled headers were supposed to help this, but don't work well in practice, since they become hundreds of MB in size, which is just as slow as #includes, so on large projects that I've worked on we took the inverse approach; concatenating all the source code for each linkage unit.
Say you're building a library comprised of files a.cpp, b.cpp, c.cpp, ..., z.cpp, many of which share various #includes.
Generate an intermediate file that contains the following.
#include "a.cpp"
#include "b.cpp"
...
#include "z.cpp"
And compile that instead.
I realize it's an ugly hack, and doesn't play well with using global variables (though you shouldnt do this anyway!), and you have to be very careful with include guards, but if you make these simple accommodations, you can get large C++ projects to compile significantly faster, at the cost of huge RAM usage for each "everything.cpp" that you compile. A nice side effect is that the optimizer has more context to work with, so you sometimes end up with smaller or faster executables.