What are ways of improving build/compile time?

Buy a faster computer


At my previous job we had big problems with compilation time and one of the strategies we used was called the Envelope pattern see here.

Basically it attempts to minimize the amount of code copied in headers by the pre-processor by minimizing header size. It did this by moving anything that wasn't public to a private friend class, here's an example.

foo.h:

class FooPrivate;
class Foo
{
public:
   Foo();
   virtual ~Foo();
   void bar();
private:
   friend class FooPrivate;
   FooPrivate *foo;
};

foo.cpp:

Foo::Foo()
{
   foo = new FooPrivate();
}

class FooPrivate
{
    int privData;
    char *morePrivData;
};

The more include files you do this with the more it adds up. It really does help your compilation time.

It does make things difficult to debug in VC6 though as I learned the hard way. There's a reason it's a previous job.


Fixing your compiler warnings should help quite a bit.


The biggest improvement we made for our large C++ project was from distributing our builds. A couple of years ago, a full build would take about half an hour, while it's now about three minutes, of which one third is link time.

We're using a proprietary build system, but IncrediBuild is working fine for a lot of people (we couldn't get it to work reliably).