提升vc编译,链接速度
2009-11-09 19:53
183 查看
提升vc的链接速度在庞大的工程是很有用的。
以下要点:
1.设计的时候要注意抽象层次,比如一个对象不应该知道太多的其他对象,如果这里面很复杂混乱,那就应该分解他们,或者使用另外的机制,类似事件传递来达到类似的目的。
2.把工程分解成dll,这样能显著提高链接速度。
3.使用预编译头文件,把不常修改的文件放到预编译头文件中显然是很有用的,但是经常改变的就算了,否则更慢....
4.使用增量链接选项。
5.项目间依赖项的设置也会大大降低链接速度,可以多使用这样的手段:#pragma comment(lib, "pathToLib").
6.link time code generationg ,/LTCG,这个选项在debug时一定关掉。
7.快的硬盘,或memory,显然,这是有用的。
8.使用联合编译器。
以下是一篇老外的讲的非常好的文章:
, and here
.
Also known as an Opaque Pointer or Handle. Not only does it speed up
compilation, it also increases exception safety when combined with a non-throwing swap
function. The pimpl idiom lets you reduce the dependencies between
headers, and reduces the amount of recompilation that needs to be done.
. If the compiler only needs to know that
is a struct or a pointer or whatever, don't include the entire
definition, forcing the compiler to do more work than it needs to. This
can have a cascading effect, making this way slower than they need to
be.
The IO streams are particularly known for slowing down builds. If you need them in a header file, try #including
instead of
and #include the
header in the implementation file only. The
header holds forward declarations only. Unfortunately the other standard headers don't have a respective declarations header.
Prefer pass-by-reference to pass-by-value in function signatures.
This will eliminate the need to #include the respective type
definitions in the header file and you will only need to
forward-declare the type. Of course, prefer const references to
non-const references to avoid obscure bugs, but this is an issue for
another question.
[/code]
By using both the pragma and the ifndef, you get the portability of
the plain macro solution, as well as the compilation speed optimization
that some compilers can do in the presence of the
directive.
general, the less often you will have to recompile everything. You can
also end up reducing the amount of work the compiler has to do on any
individual block of at the same time, by virtue of the fact that it has
less to keep track of.
for many translation units. The compiler compiles it once, and saves
its internal state. That state can then be loaded quickly to get a head
start in compiling another file with that same set of headers.
Be careful that you only include rarely changed stuff in the
precompiled headers, or you could end up doing full rebuilds more often
than necessary. This is a good place for stl headers and other library
include files.
ccache
is another utility that takes advantage of caching techniques to speed things up.
option. In Visual Studio, there's an option under preferences to allow
it to build multiple projects in parallel. You can also use the
option
for file-level paralellism, instead of just project-level paralellism.
Other parallel utilities:
Incredibuild
Unity Build
distcc
or
), you can reduce linking time as well.
以下要点:
1.设计的时候要注意抽象层次,比如一个对象不应该知道太多的其他对象,如果这里面很复杂混乱,那就应该分解他们,或者使用另外的机制,类似事件传递来达到类似的目的。
2.把工程分解成dll,这样能显著提高链接速度。
3.使用预编译头文件,把不常修改的文件放到预编译头文件中显然是很有用的,但是经常改变的就算了,否则更慢....
4.使用增量链接选项。
5.项目间依赖项的设置也会大大降低链接速度,可以多使用这样的手段:#pragma comment(lib, "pathToLib").
6.link time code generationg ,/LTCG,这个选项在debug时一定关掉。
7.快的硬盘,或memory,显然,这是有用的。
8.使用联合编译器。
以下是一篇老外的讲的非常好的文章:
Language techniques
Pimpl Idiom
Take a look at the pimpl idiom here, and here
.
Also known as an Opaque Pointer or Handle. Not only does it speed up
compilation, it also increases exception safety when combined with a non-throwing swap
function. The pimpl idiom lets you reduce the dependencies between
headers, and reduces the amount of recompilation that needs to be done.
Forward Declarations
Wherever possible, use forward declarations. If the compiler only needs to know that
SomeIdentifier
is a struct or a pointer or whatever, don't include the entire
definition, forcing the compiler to do more work than it needs to. This
can have a cascading effect, making this way slower than they need to
be.
The IO streams are particularly known for slowing down builds. If you need them in a header file, try #including
<iosfwd>
instead of
<iostream>
and #include the
<iostream>
header in the implementation file only. The
<iosfwd>
header holds forward declarations only. Unfortunately the other standard headers don't have a respective declarations header.
Prefer pass-by-reference to pass-by-value in function signatures.
This will eliminate the need to #include the respective type
definitions in the header file and you will only need to
forward-declare the type. Of course, prefer const references to
non-const references to avoid obscure bugs, but this is an issue for
another question.
Guard Conditions
Use guard conditions to keep header files from being included more than once in a single translation unit.#pragma once #ifndef filename_h #define filename_h // Header declarations / definitions #endif
[/code]
By using both the pragma and the ifndef, you get the portability of
the plain macro solution, as well as the compilation speed optimization
that some compilers can do in the presence of the
pragma once
directive.
Reduce interdependancy
The more modular and less interdependant your code design is ingeneral, the less often you will have to recompile everything. You can
also end up reducing the amount of work the compiler has to do on any
individual block of at the same time, by virtue of the fact that it has
less to keep track of.
Compiler options
Precompiled Headers
These are used to compile a common section of included headers oncefor many translation units. The compiler compiles it once, and saves
its internal state. That state can then be loaded quickly to get a head
start in compiling another file with that same set of headers.
Be careful that you only include rarely changed stuff in the
precompiled headers, or you could end up doing full rebuilds more often
than necessary. This is a good place for stl headers and other library
include files.
ccache
is another utility that takes advantage of caching techniques to speed things up.
Use Parallelism
Many compilers / IDEs support using multiple cores/CPUs to do compilation simultaneously. In GCC, use the-j
option. In Visual Studio, there's an option under preferences to allow
it to build multiple projects in parallel. You can also use the
/MP
option
for file-level paralellism, instead of just project-level paralellism.
Other parallel utilities:
Incredibuild
Unity Build
distcc
Use a Lower Optimization Level
The more the compiler tries to optimize, the harder it has to work.Shared Libraries
Moving your less frequently modified code into libraries can reduce compile time. By using shared libraries (.so
or
.dll
), you can reduce linking time as well.
Get a Faster Computer
More RAM, faster hard drives, more CPUs/cores will all make a difference in compilation speed.相关文章推荐
- ndk-build编译速度提升
- VC++程序编译链接的原理与过程
- VC 和 GCC(CYGWIN) 编译和链接简单使用
- VC中常见的一些编译链接错误的解决
- VC下编译和链接常出现的问题汇总
- VC编译链接openssl
- VC调试版本与发布版本编译链接选项差异和区别
- paip.提升用户体验----gcc c++ 编译速度提升by预编译头技术 .doc
- 使用mingw编译可以让VC使用的动态链接库的ffmpeg
- 设置java 内存提升maven编译速度
- vc.net中MFC静态与动态链接问题与release方式编译
- VC++程序编译链接原理与过程
- VC++ 2005编译链接错误汇总
- VC++中忽略所有默认库纯Win32 API编译及链接
- vc6.0编译c++程序后在vc2008中调试的技巧(符号信息和链接)
- VC 编译链接错误 LNK1123: 转换到 COFF 期间失败: 文件无效或损坏
- 显示调用基类构造函数,迟绑定,VC++编译链接过程
- Eclipse 中的多线程编译——如何成倍提升Gcc编译器的编译速度
- 加快XCode的编译链接速度(200%+)——XCode编译速度慢的解决方案
- VC++ 2005编译链接错误汇总