Speed up compilation in Visual Studio 2005
What are the best ways to speed up compilation time in Visual Studio 2005 for a solution cont开发者_开发百科aining mainly C++ projects?
Besides pre-compiling headers, there are number of other things that could be slowing you down:
- Virus checking software - can have a nasty impact on builds. If you have a virus checker running try to turn it off and see what sort of improvement you get.
- Low RAM - Not enough RAM will cause many more disc reads and slow you down. cont ->
- Slow HDD - You have to write to disc regardless and a slow drive, like those present in many laptops and lower-end systems, will kill your builds. You can get a faster drive, a RAID array or SSD
- Slow processor(s)... of course.
- Unlikely, but: Check and see if your projects are referencing network shares. Having to pull files across the network with each build would a big slowdown.
EDIT Few more thoughts:
- If your solution contains a large number of projects you could consider creating other "Sub" solutions that contain only the projects that you're actively working on. This possibility depends on how interrelated your projects are.
- The project builds can have pre and post build event commands associated with them. Check the properties of your projects to see if there are any costly build events specified.
You can create a pre-compiled header of the files which normally wont change frequently. This can dramatically increase your compilation time.
At the code level, it's helpful to minimize the amount of headers included by other headers. Repeatedly loading and reading files can have a big impact. Instead, forward declare things wherever possible. For example:
#include <iosfwd>
#include <string>
#include "M.h"
#include "R2.h"
#include "A2.h"
class M2;
class A;
class R;
template<class C> class T;
class X{
M member; // definition of M is required
M2 *member2; // forward declaration is sufficient for pointers & references
public:
// forward declaration of argument type A is sufficient
X(const A &arg);
// definition required for most std templates and specializations
X(const std::string &arg);
// forward declaration of your own templates is usually okay...
void f(T<int> t);
// unless you're defining a new one. The complete definition
// must be present in the header
template<class Z>
void whatever(){
// blah blah
}
R f(); // forward declaration of return type R is sufficient
// definitions of instantiated types R2 and A2 are required
R2 g(A2 arg){
return arg.h();
}
// ostream is forward-declared in iosfwd
friend std::ostream &operator << (std::ostream &o, const X &x);
};
Users of this class will have to #include
whatever files provide the class definitions if they actually call any of X(const A&)
, f(t<int>)
, f()
, or operator <<
.
Templates will almost certainly add to inclusion overhead. This is generally worth their power, in my opinion. When you make your own templates, the complete definition must reside in the header file; it cannot go in a cpp file for separate compilation. Standard templates can't be forward declared, because implementations are allowed to provide additional template parameters (with default arguments) and forward declarations of templates must list all of the template parameters. The iosfwd header forward-declares all of the standard stream templates and classes, among other things. Your own templates can be forward-declared as long as you don't instantiate any specializations.
Precompiled headers can also help, but most compilers limit the quantity that you can include in a source file (Visual Studio limits you to one), so they aren't a panacea.
- Unity builds.
- Precompiled headers.
- Windows 7 builds a lot faster than Windows XP (if that's relevant to you).
- Turn off anti-virus scanners.
- Minimise dependencies (i.e.
#include
's from header files). - Minimise amount of template code.
Precompiled headers can be helpful if you include complex headers (STL, Boost for example) directly in a lot of files.
Make sure your build does not access the network inadvertently, or intentionally.
If you have multicore cpu, use /MP compiler option.
Edit: What techniques can be used to speed up C++ compilation times?
If you have a lot of projects in the solution remove some of them. If they're referenced as projects you can reference the binary output instead (use the browse button in the add reference dialog). This removes a lot of dependency checking in the solution. It's not ideal but it does speed things up.
The solution we've used was IncrediBuild. Just throw more hardware at the problem. In addition to all the developer machines (fairly powerful themselves) we had a number of 4-core servers doing nothing but compiling.
Change your Solution Platform on "Any CPU" option which is given on the top of visual stdio then your program build speed will be definitely increased.
精彩评论