Pages

Friday, April 29, 2011

On Compile Time

The other day, someone had asked me how long it took to recompile the entire Elpis solution. As far as I could remember, this was around 1 minute, but when was the last time I did a full recompile and watched it? My habit is to do something online or to get some food when something will take a while, so it is likely that my assumption was wrong.

So, I enabled build timings in VS, started a full recompile and got myself a snack. Upon returning a few minutes later, I was disgusted to see that it was still compiling! After it was done, I recompiled a few more times and averaged the recompile time to around 4 minutes.

Problems
The first problem was caused by languidness towards header structure and inclusion. One of Elpis' main header files was being included by a large majority of the headers and source files across all projects. This header happened to include the entirety of the DXUT framework, several major boost headers and quite a few other things. Convenient, but dirty.

The second problem had to do with class' being fully defined within their header, rather than within the source file.

Solutions
The first and second problems could easily have been corrected during development, but I was foolish and allowed it to accrue into the devastating creature it had become.

The solution to the first was to divide the mega-all-encompassing header into several categorized headers and to be careful that the heavy headers were only included when needed (a basic rule I've been ignoring for too long).

The solution to the second problem was to simply move definitions to the appropriate source files where possible.

Worth it?
After all of this, compile time had improved to approximately 1 minute. A last optimization was done to some of the large projects that get updated frequently, and that was to use precompiled headers. A feature I've never taken advantage of. This reduced full recompile time to ~40 seconds for the entire solution. Pre-compiled headers will be a big bonus in the long run, since the solution compile time is a tiny fraction of the original time.
 
There are plenty of other opportunities to improve the compile time in Elpis, but full recompiles have been rare. Each project now takes, on average, 5 seconds to fully recompile. Until I fully adopt TDD, or full recompiles become the norm, I'll be more than happy with my improved compile times.

No comments:

Post a Comment