Boost logo

Boost :

From: Brey, Edward D (EdwardDBrey_at_[hidden])
Date: 2002-02-06 09:48:37


> From: Peter Dimov [mailto:pdimov_at_[hidden]]
>
> Too broad a topic, but one thing is certain, no programmer likes to
> recompile all translation units that use scoped_ptr because
> shared_array has changed.

Ahh, but this isn't really true. I personally do like this. Why? you
rightfully ask. I know that the time recompilation I am paying now has been
and will be paying huge dividends in avoided recompilation time during other
program changes. Why? The reality of precompiled headers makes the
difference. Suppose I'm coding along in my project and I find I need a
scoped_ptr. I include <boost/smart_ptr.hpp> in my precompiled header. I
pay for a recompile of everything. It's worth it, of course, because
subsequent incremental compilations are much faster. Now suppose I need
scoped_array. Well, as luck would have it, I don't have to recompile
everything. Had I been using maximally small granularity, I would have had
to put <boost/scoped_array.hpp> into my precompile header and paid for a
full recompile. Instead, by paying for a trivially longer precompilation,
which included some classes I didn't immediately use, I saved myself time in
the long run.

Additionally, management of the precompiled header is simpler, since there
are a small number of "family" headers, rather than a header for each class.
Since I have to manage (including garbage collect) the list of includes
myself, it saves on human seek time if the list is small. It would be nice
for C++ to index all the source files and figure out the #includes on its
own, but alas, it's not there yet.

A detailed analysis reveal three variables that affect recompilation in
real-world projects that use precompiled headers:

1. How often the precompiled headers change.
2. How often non-precompiled code needs / stops needing a new precompiled
header.
3. How likely unused precompiled code will change without used precompiled
code also changing.

In my experience, (1) happens about once a quarter, whereas (2) happens
about once a month. I've never seen (3) happen. That is to say, even
though I've never used shared_array, it's never cost me any time, except a
trivial amount of time to precompile just that class, since it has never
changed without scoped_ptr, which I do use, also changing.

The key to minimizing recompilations (on environments with precompiled
headers) is grouping classes into families such that classes in the family
tend to change together and programs that use a class in the family are
likely to already be using the family (a form of locality of reference).
This sounds a lot like the concept of modules in other languages.


Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk