Jump to content
  • Advertisement
Sign in to follow this  
clapton

How to reduce time of compilation?

This topic is 4950 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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'

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
- 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) ;)

Share this post


Link to post
Share on other sites
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

Share this post


Link to post
Share on other sites
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).

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
Also be sure to turn off any anti-virus software you may be running.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!