precompiled headers

GCC supports precompiled headers

What are you talking about? If you ask GCC to compile a file with a “.h suffix, it will write out a similarly named file with “.gch” tacked on the end. And then, when something includes that file, it’ll do some checks and if everything is equal, it’ll use that precompiled header.

(Note: the words “everything” and “equal” and “use” are implementation and implementer specific and as such are subject to interpretation, discussion, reinterpretation, adjustment, argument, debate, readjustment, consideration, evaluation, re-evaluation, alcohol, burning, smiting, testosterone imbalances, puberty, intent to reach puberty within the next couple of years, rejection, dismissal, disregard, disrepect and generally anything but clear definition – if you really want to know, all you have to do is read the source code, stay up to date with the latest revisions from source control, stay active on the mailing list and nearly 40 blogs which occasionally mention gcc, its not like we get paid to do this. Thank you for choosing Open Source!)

Before and After

Before my little weekend spree: Client took upto 10 minutes to build on my various boxes depending on how long before I started multi-tasking and what I was multi-tasking. Probably took around 5-6 minutes on Martini’s machine, and probably 6 minutes for a normal build on my work box if I left it alone. 4 minutes for a non-optimized debug build.

After: For a full, optimized build, the compile takes 55 seconds (61 seconds if you do a full rebuild including our teulKit network library). The link phase takes 2.5 minutes, most of which is “Generating code” (whole program optimization/link time code generation). So, it now takes┬áless time for a complete build than it used to take to build a quick debug build. The debug build takes 125 seconds.

We can probably shave another 20-30 seconds off the debug build and 30-60 seconds off the release build with a little simple reorganization. For instance, one of the header files with the most overhead has a dual-use which makes it unsuitable, but I think I can fix that with a little project configuration.

Precompiled headers

Our project just takes too long to compile. It’s only a few hundred thousand lines of code, but it compiles like there are millions.

I’ve spent most of last night and today reorganizing header files and project files and turning our primary include file set into a single, precompilable header.

Visual Studio, dramatic effect: just over 2 minutes 27 seconds off the time to build the entire project while also adding our network API to the build! Xcode seems about the same or slower (I’ll benchmark that next week) and I got tired of wrestling with autoconf/automake under Linux for the host.