Discussion:
Precompiled headers and templates
Yang Zhang
2009-03-20 09:20:25 UTC
Permalink
Have people found precompiled headers to make significant difference
with template-heavy headers, esp. things like Boostified projects? I've
been trying to look up details on what the pre-compilation entails, but
I still don't have a good handle on this. I'm mainly wondering whether
it speeds up anything for templates that are instantiated outside of the
header (i.e. at the use site). I'm guessing not, since template
instantiation can induce arbitrary computation. If I'm right, then do
most folks try to include explicit instantiations in their precompiled
headers?

I plan to experiment with this, but am curious to know what others have
witnessed.
--
Yang Zhang
http://www.mit.edu/~y_z/
Ian Lance Taylor
2009-03-20 14:45:59 UTC
Permalink
Post by Yang Zhang
Have people found precompiled headers to make significant difference
with template-heavy headers, esp. things like Boostified projects?
I've been trying to look up details on what the pre-compilation
entails, but I still don't have a good handle on this. I'm mainly
wondering whether it speeds up anything for templates that are
instantiated outside of the header (i.e. at the use site). I'm
guessing not, since template instantiation can induce arbitrary
computation. If I'm right, then do most folks try to include explicit
instantiations in their precompiled headers?
Producing a pre-compiled header is actually quite simple.

http://gcc.gnu.org/onlinedocs/gcc-4.3.3/gcc/Precompiled-Headers.html#Precompiled-Headers

However, including explicit instantiations in the precompiled header
won't make any significant difference to compilation time. The
precompiled header saves on parsing and name lookup time, it doesn't
save on code generation time.

I don't personally find that precompiled headers help with compilation
time all that much. However, for some projects, ones with millions of
lines of header files included in every compilation, I expect that they
would help.

Ian

Loading...