5 ms·
The semantics are the problem, as they require re-parsing every header transitively every time, and this defines new syntax with new semantics. Large C++ proje
by pjc50 12y ago
The semantics are the problem, as they require re-parsing every header transitively every time, and this defines new syntax with new semantics.
Large C++ projects end up with compile time tending towards O(n^2) in the number of files in the project; this will save tens of minutes to hours on every project build.
- oppositelock 12y agoPrecompiled 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.