At work we came up with an interesting trick for speeding up the compilation of C++ libraries: create a dummy cpp file which just #includes all the other cpp files, and compile that.
The advantage of this is that all the headers are only read once. Since most of the cpp files in any given project will depend on the same headers, and since headers tend to account for the majority of the time involved in compiling a C++ file, this can result in a huge speedup. Basically it's like getting precompiled headers for free, and without any unportable pragmas.
The disadvantage of this is that sometimes the compiler gets overwhelmed and hangs.
I hear that this trick reduced the compile time on one of our platforms from 45 minutes to 4 minutes.
Posted on October 26, 2004 05:16 PM
More programming articles
I was listening to some of the records of the ottowa linux symposium, where one of the speakers was an open-office developer, who talked about some of the problems faced by the OO.org guys.
Apparently the speed increase gained between the 1.1.0 -> 1.1.1 was because the first thing oo.org does when it starts is goes and mmaps and reads all the files required for startup. Thus caching all the files and reducing seek time dramatically.
One of the other interesting facts he pulled out was that >30% of OO.org's binaries and libraries are symbol tables, because no matter how private your funcitons and variables are, all other C++ applications need to know their addresses for a multitude of reasons.
Oh well, I thought they were interesting facts ;)
Posted by: Stephen Thorne at November 1, 2004 07:09 PMI don't know why c, c++ still need headers.
Posted by: Naveen Garg at April 22, 2008 08:04 PM