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

Tagged as

Reducing VisualStudio / C++ built times dramatically

, 14 Jan 2010 CPOL
Rate this:
Please Sign up or sign in to vote.
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...
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)

Share

About the Author

iberg
Software Developer
Germany Germany
No Biography provided

Comments and Discussions

 
GeneralSpeedup VS2008 PinmemberJimmyO27-Oct-10 9:35 

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

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

| Advertise | Privacy | Terms of Use | Mobile
Web02 | 2.8.1411023.1 | Last Updated 14 Jan 2010
Article Copyright 2010 by iberg
Everything else Copyright © CodeProject, 1999-2014
Layout: fixed | fluid