Click here to Skip to main content
Click here to Skip to main content

Reducing VisualStudio / C++ built times dramatically

By , 14 Jan 2010
 
When working with large C++ projects in Visual Studio built times can become a problem. I'm working on a project with 140000+ lines of code split into 23 Projects (1 Main App; 3 libs; 19 DLL's). Depending on the CPU speed built times could exceed 10 Minutes. May not sound much but if you have to change the framework often rebuilds are required several times a day and the total compilation time per day can quickly become a problem.
 
The usual time safers like precompiled headers, excessive use of forward declaration and building with support for multiple cores (/MP) were already in place. Time to try a solution I wouldn't touch under normal circumstances: Including all cpp files into a single compilation unit. (Kinda like precompiled headers just for the cpp files...)
 
Here is how it works:
  1. Create a few cpp files that include all your projects cpp files. For instance one to include all your gui code, one for the data handling, one for all utility files. Add those files to your project.
  2. Set the original cpp files to "exclude from build" in the project settings; Only your new include files shall be set to compile.
Instead of compiling a large number of small files you end up compiling a small number of large files. This is significantly faster.
 
Pros:
  • You can continue working with your solution normally, all your files are still listed, they are just marked as "excluded from build"
  • Built times will decrease dramatically
Cons:
  • Name collisions are possible when using global variables.
  • Partial build times will go up. This is managable if you don't put all your cpp files into a single include file. (use two or three)
 
This was'nt my idea so the credit goes to Noel Llopis from the gamesfromwithin blog. The original article is here:
 
http://gamesfromwithin.com/physical-structure-and-c-part-2-build-times
 
Read it to learn more about the background. I found this approach very helpfull for my case. Thanks to the original author for his in depth investigations into this.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

About the Author

iberg
Software Developer
Germany Germany
Member
No Biography provided

Sign Up to vote   Poor Excellent
Add a reason or comment to your vote: x
Votes of 3 or less require a comment

Comments and Discussions

 
Hint: For improved responsiveness ensure Javascript is enabled and choose 'Normal' from the Layout dropdown and hit 'Update'.
You must Sign In to use this message board.
Search this forum  
    Spacing  Noise  Layout  Per page   
GeneralSpeedup VS2008memberJimmyO27 Oct '10 - 8:35 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

Permalink | Advertise | Privacy | Mobile
Web03 | 2.6.130523.1 | Last Updated 14 Jan 2010
Article Copyright 2010 by iberg
Everything else Copyright © CodeProject, 1999-2013
Terms of Use
Layout: fixed | fluid