[general] Speeding up compilation?

<alert comment="stl newbie"> vc7.1 Visual C++ user: Sorry if this has been asked before. My impression is that this is the nature of templates, since code is being generated as objects are instantiated. Are there guidelines for speeding up compilation/linkage of code that moderately/heavily uses templates? It seems to take a looooong time, even on a relatively modern development computer. Precompiled headers don't seem to help .... perhaps it is counter-productive to use precompiled headers with stl/boost? Or I'm ignorant about proper usage? Are there vc7.1 / vc8 settings to speed up development? GCC? Is this #define applicable (and/or perhaps others): BOOST_MPL_USE_PREPROCESSED_HEADERS </alert>

Sorry if this has been asked before. My impression is that this is the nature of templates, since code is being generated as objects are instantiated.
Are there guidelines for speeding up compilation/linkage of code that moderately/heavily uses templates? It seems to take a looooong time, even on a relatively modern development computer.
That's certainly true for libraries like xpressive / spirit / ublas that make heavy use of template metaprogamming and/or expression templates. Boost.Regex avoids this by moving most of the template instances you will likely use into the library (so they don't get instantiated in your object files), and precompiled headers are certainly a big win in this case.
Precompiled headers don't seem to help .... perhaps it is counter-productive to use precompiled headers with stl/boost? Or I'm ignorant about proper usage?
Are there vc7.1 / vc8 settings to speed up development? GCC?
About the only thing you can do is isolate the problem to one or two source files: for example by hiding the templates behind a non-template interface. If you're developing a parser with spirit then that's typically what you would do anyway, for other libraries it may be harder, or certainly less convenient to do that. John.

John Maddock wrote:
Boost.Regex avoids this by moving most of the template instances you will likely use into the library (so they don't get instantiated in your object files), and precompiled headers are certainly a big win in this case.
FWIW - this is the approach used by the serialization library. All "known" instantiations are built and added to the library. The linker just adds in the appropriate instantiation. The permits things like xml serialization (which depends upon spirit) to be used without constantly recompiling this code every time that archive is used. But still if one serializes a lot of class types, it can take a while. So the recommended approach is to divide one's code into smaller modules that don't have to be recompiled as often. The serialization library also includes a test/demo (demo_pimpl) which illustrates how to do this with one's own serialization. In fact, I find it useful to explicitly instantiate all the combinations I might use and add them to an "application library". The final application link draws from this library only the instantiations actually use. To summarize - in theory one can just include headers willy-nilly and let the compiler-linker handle everything. In practice, there is a lot of benefit to investing some effort to divide one's application into smaller modules each with fewer dependencies. That's my advice. Robert Ramey

John Maddock wrote:
Boost.Regex avoids this by moving most of the template instances you will likely use into the library (so they don't get instantiated in your object files), and precompiled headers are certainly a big win in this case.
vc7.1 WinXp-SP2 Would it be feasible/advantageous for some/many/most boost libraries to have an installation procedure a'la regex to build a whole series of .lib libraries? (at least for vc6/7/7.1/8 .... not familiar with Linux development) They are bulky, but who cares. They seem to speed up development builds a LOT.

John Maddock wrote:
That's certainly true for libraries like xpressive / spirit / ublas that make heavy use of template metaprogamming and/or expression templates.
Boost.Regex avoids this by moving most of the template instances you will likely use into the library (so they don't get instantiated in your object files), and precompiled headers are certainly a big win in this case.
You get really spoiled by split second compilation times. Perhaps one of my top memories related to programming is the first time I used the Borland Turbo Pascal compiler (early-to-mid 80's?) on a dual floppy PC. The competing Pascal compilers took several minutes for a 500 line program (with disk swapping mid way thru). Turbo Pascal was just DONE when you pressed the enter key. Less than a second, IIRC. My first thought was, "What did I do wrong ... it CAN'T be done already. No way!" Way. I have never experienced, before or since, such a quantum leap in technology. It revolutionized software development and transformed the task from mostly drudgery to "a hoot" (and my real job at the time was COBOL programming where you submitted a card deck and came back later for output from a multi-million $ computer .... you kids have it soooooo easy <g> .... sorry for the "war story").

Lynn Allan wrote:
You get really spoiled by split second compilation times.
Perhaps one of my top memories related to programming is the first time I used the Borland Turbo Pascal compiler (early-to-mid 80's?) on a dual floppy PC. The competing Pascal compilers took several minutes for a 500 line program (with disk swapping mid way thru). Turbo Pascal was just DONE when you pressed the enter key. Less than a second, IIRC.
I had the exact same experience, wow was it fast. As for compilation of Boost, some libraries do generate a large hit. For example the lambda library. However, I find Microsoft pre-compiled headers make a huge difference. Just make sure to use manually created pre-compiled header files and not the automatic option. BTW, this is very easy to do with MPC (www.ociweb.com/products/MPC). Just create files called {whatever}_pch.* and MPC will do the rest. KevinH -- Kevin Heifner heifner @ ociweb.com http://heifner.blogspot.com Object Computing, Inc. (OCI) www.ociweb.com

Lynn Allan wrote:
Are there guidelines for speeding up compilation/linkage of code that moderately/heavily uses templates? It seems to take a looooong time, even on a relatively modern development computer.
You might play with the include path ordering. I achieved big speed improvements by placing boost first in the list, along with moving to last a path with a truly huge number of header files. Additionally, I use MS briefcase to keep a local copy of that last path, which resides on our network. I'm using VC7.1, boost_1_33_1. Jeff
participants (5)
-
Jeff Flinn
-
John Maddock
-
Kevin Heifner
-
Lynn Allan
-
Robert Ramey