[geos-devel] How to make compilation time shorter

Mateusz Łoskot mateusz at loskot.net
Sun Mar 5 18:15:57 EST 2006


Hi,

GEOS compilation time is quite long.
Some days ago, I was talking about it with strk and we compared how long
does it take with GCC vc VC++.
The time varies from 3 to a few tens of minutes (strk can say what's the
latter value).

Today, I was working on Unit Tests and I noticed that geom.h file
defines all geometry classes and then it's included in (almost) every
.cpp file.

And if I apply small change to geom.h, e.g. Envelope class then it will
require almost complete rebuild of GEOS to update binaries.
It really slows down development.

I'd suggest to refactor the source code that every class is splitted
into separate .h/.cpp file. geom.h would be the first candidate :-)

So, then envelope.cpp could include *only* envelope.h file.
If something in envelope.h is changed then it will required to recompile
envelope.cpp file + files that include envelope.h.

This second group of files could be yet refactored to minimize
compile-time dependencies, according to some of Herb Sutter's suggestions:
http://www.gotw.ca/gotw/007.htm

Short example:

// a.cpp file
#include "envelope.h"
struct A
{
   Envelope* pe;
   void foo(Envelope* e);
};

In the example above we can safely remove #include "envelope.h" because 
compiler does not need here definition of Envelope class.
We can replace #include "envelope.h" with forward declaration:

// a.cpp file

class Envelope;

struct A
{
   Envelope* pe;
   void foo(Envelope* e);
};

After more such cases would be refactored, then compilation time should 
be significantly shorter. So, development could run faster :-)

What is your opinion?

Cheers
-- 
Mateusz Łoskot
http://mateusz.loskot.net



More information about the geos-devel mailing list