Friday, 14 August 2009

Faster Compile Pussycat

The problem we often face with games development is debug cycles and how long between getting into the game and back to the problem. There are two issues at stake here, one is the rate at being able to get back to where you are once the game code has recompiled, the other is how long it takes to recompile.

I'm going to talk about the latter.

Header file changes. They cost you a rebuild-most if it's a relatively important header. A rebuild all if it's a base file, and at least a rebuild few if it's a relatively unused one. If it is only going to cause one file to rebuild, then why is it a header?!?

If you want faster compile times overall, use precompiled headers. Use them to reduce the number of times your compiler has to load up the whole windows.h tree of includes.
Of course, even though this will make your rebuild alls take about 25% of the time they used to take, it will mean that any header change will cause a rebuild all.


So, take off precompiled headers?

Well, you can, but you will get the headache inducing compilation times back for actual rebuild-alls... except there is an alternative. if you think about how long it takes to compile a simple piece of code, think also about how long it took to link the CRT...

no, i don't mean use libs liberally, that can be cumbersome, tedius to debug, generally a pain in the what-not. No, just think like a library. I library is an object file generated from multiple CPP files right? well, you can do that mid project if you like.

for example:

-- MyFile --

#include "stdafx.h" // for the pch

#include "MyModule.cpp"
#include "MyHelpers.cpp"
#include "MyMaths.cpp"
#include "MyGUI.cpp"
#include "MyDataBase.cpp"
#include "MyLogic.cpp"

-- End --

okay, what does this give us?

it gives us a cpp file that compiles quickly (because it's only including one set of headers), and it compiles to one object that can be linked like any other single CPP object in your project.

so, at the expense of looking after namespace collisions between inlcluded CPPs, we have a vast reduction in recompilation speed approximately the same as using PCHs that will still only rebuild-most when we change a header file.

WIN-WIN... except some people will think it's ugly and bad engineering. Oh well.


Unknown said...

Which works fine, except on compilers that don't follow include dependencies for .cpp files. Then your clever bulk compile turns into a missed-update-fuck-recompile-all-yet-again situation. (MW compiler for EPPC, I'm looking at you here...)

fabs(); said...

not rebuild all, just compile the joined up compiling file.