How to reduce time of compilation?

Started by
20 comments, last by clapton 19 years, 4 months ago
Hello! I use C++ compiler from VS2003. I would like to ask you for some suggestions about reducing time of project compliation. Currently I am working on a bigger project (contains > 30 files) and it's making me terribly annoyed when I have to wait a couple of MINUTES until everything rebuilds. Is there any chance of speeding things up? OK, I understand that when I change a single header file it needs to be pre-compiled but why to rebuild the whole projects? If I simply SHIFT+F5 I get linking errors. Are there any settings in the compiler that might be helpful? Thanks in advance for your help, See ya'
___Quote:Know where basis goes, know where rest goes.
Advertisement
Minutes?

I can do a full build of my 21,000 lines of C++ code in about one minute on my P4 2.53ghz, and it uses Boost and STL in more than a few places, along with some of my own template classes.

If said header file is referenced in every header, then changing that file will have a ripple effect on compilation times. The contents of a precompiled header shouldn't change much after first setting it up, you'll gain the time back eventually. If you can, get a copy of John Lakos' Large-Scale C++ Software Design. It is probably one of the only books that covers physical layout of a project in great detail.
--God has paid us the intolerable compliment of loving us, in the deepest, most tragic, most inexorable sense.- C.S. Lewis
Make sure your header files have specific, preferably fairly small groups of information of a common concept, and only include the files that you need. Be sure that each of your files includes the bare minimum required for functionality and nothing more. As well, remember that you don't need to include the full definition of a type if you are just working with it indirectly, so you don't necessarily have to include the file with the definition of whatever you are working with, you can often just forward declare I.E. when working with pointers or references to a class-type or when the class type only appears in a declared function's signature.

This is important because each translation unit (cpp file) parses through the files on their own, so if your cpp files include more headers than are needed, you have to remember that not only are you needlessly parsing through the data, but you are doing so in every single cpp that uses your files, whether directly or indirectly. If your headers include more information than are needed, your compile time is going to be needlessly inflated proportional to the number of translation units in which your files are included.

Another alternative way of decreasing compilation times is to use pre-compiled header files, though that's not really standard.
- use #pragma once in your headers (if your compiler supports this);
- use pre-compiled headers (only put stuff that rarely changes in there);
- only include the headers you need;
- switch off antivirus software (or at least stop it from scanning your source- and objectfiles).
- make sure the code you change is in a cpp file (not a header) ;)
use interfaces to sheild your code from the effects of implementation changes.

Its really helped us. Its also promotes loose coupling which can reduce your link times.

Cheers
Chris
CheersChris
Get a new computer really. One of my projects with hundreds of files and tens of thousands of lines builds in under a minute.

Programmatically just make sure you don't have to rebuild everything every time. Better code division can make that happen easily; or the simplest solution is above (even just getting more RAM if you have very little or getting a better processor can make a big difference).
i thought using makefiles helped?
or am i dead wrong?

Beginner in Game Development?  Read here. And read here.

 

Couple of snippets from GoTW:

Compile time dependencies
The Pimpl idiom

HTH,
Jim.
You can also try the digital mars compiler, its very very fast at compiling things. I find it especially usefull for when I'm just running the compile-every-5-minutes-to-test-for-mistakes thing.
Also be sure to turn off any anti-virus software you may be running.

This topic is closed to new replies.

Advertisement