如何加快c ++链接时间

时间:2022-09-02 09:21:17

Is there any way, to optimalize linking time in MS Visual studio C++ (2005) ? We're using Xoreax Incredibuild for compilation speed up, but nothing for link.

有没有办法,在MS Visual Studio C ++(2005)中优化链接时间?我们正在使用Xoreax Incredibuild进行编译加速,但没有任何链接。

Currently every linking takes about 30seconds. When I turn on incremental linking, takes abou 35-40 seconds. ( No matter if i compile project with or without incredibuild )

目前,每个链接大约需要30秒。当我打开增量链接时,需要35-40秒。 (无论我是否使用incredibuild编译项目)

Is there any way, how to profile linker and watch how long what takes ? Or any tool for paralel linking ? Or any tips for code optimalization to speed up linker ?

有什么办法,如何配置链接器并观察需要多长时间?或者任何用于paralel链接的工具?或任何代码优化的提示,以加快链接器?

Thanks for reply Ludek Vodicka

感谢Ludek Vodicka的回复


Edit:

Thanks for first replies, and additional info:

感谢您的第一个回复和其他信息:

  • Whole Program Optimization and link-time code generation is already off.
  • 整个程序优化和链接时代码生成已经关闭。

  • PIMPL idiom is already used when possible
  • 已尽可能使用PIMPL习语

  • other static libraries are already included via #pragma comment(lib, "pathToLib"). (also because of easier maintenance]
  • 其他静态库已经通过#pragma comment(lib,“pathToLib”)包含在内。 (也因为更容易维护]

  • HW : quad core q6600, 8GB ram, 3x WD raptor raid 0. Windows Vista 64bit
  • 硬件:四核q6600,8GB ram,3x WD raptor raid 0. Windows Vista 64bit

4 个解决方案

#1


I'm not aware of any parallel linking tools; I do know that Incredibuild does not allow it.

我不知道任何并行链接工具;我知道Incredibuild不允许这样做。

The biggest tool in your toolbox for avoiding link times is the appropriate level of abstraction. If your link times are long, it may be because objects know too much about other objects. Decoupling them is then the key -- through abstract interfaces (perhaps using the PIMPL paradigm), or though other methods such as event passing.

工具箱中用于避免链接时间的最大工具是适当的抽象级别。如果链接时间很长,可能是因为对象对其他对象了解太多。然后解耦它们是关键 - 通过抽象接口(可能使用PIMPL范例),或者通过其他方法,例如事件传递。

The overhead for linking projects through Project Dependencies is also quite high. If your target platform is Win32 only, or primarily, you may consider using a header to link your dependent libraries via #pragma comment(lib, "pathToLib").

通过Project Dependencies链接项目的开销也很高。如果您的目标平台仅限Win32,或者主要是您,可以考虑使用标头通过#pragma comment(lib,“pathToLib”)链接您的依赖库。

#2


If you can live without the optimization, turn off link-time code generation (remove the /GL switch or in properties c/c++ -> Optimization -> Whole Program Optimization. For the linker remove /ltcg or use the Link Time Code Generation Setting). This will make the compiler slower though, as code generation now happens during compile time.

如果您可以在没有优化的情况下生存,请关闭链接时代码生成(删除/ GL开关或在属性c / c ++ - >优化 - >整个程序优化。对于链接器删除/ ltcg或使用链接时间代码生成设置)。这会使编译器变慢,因为代码生成现在在编译期间发生。

I've seen projects that take hours to build with /GL+/LTCG, mere seconds without (this one for example: http://social.msdn.microsoft.com/Forums/en-US/vcgeneral/thread/750ed2b0-0d51-48a3-bd9a-e8f4b544ded8)

我已经看到用/ GL + / LTCG构建需要几个小时的项目,仅仅几秒钟(例如:http://social.msdn.microsoft.com/Forums/en-US/vcgeneral/thread/750ed2b0-0d51 -48a3-bd9a-e8f4b544ded8)

#3


Have you considered improving hardware?
Do you use a separate physical hard drive for for the build? What kind of drives do you use?

您是否考虑过改进硬件?您是否使用单独的物理硬盘驱动器进行构建?你用什么样的驱动器?

As a general suggestion: throw in some memory, get a Velociraptor, put only sources and build directory there, measure again. If that helps, consider a RAID 0.

作为一般建议:抛出一些内存,获得一个Velociraptor,只放置源并在那里构建目录,再次测量。如果这有帮助,请考虑RAID 0。

I've heard reports that upgrading from an XP core to an W2K3 core improved build times notably, presumably due to better memory management and caching.

我听说过从XP核心升级到W2K3核心的报告明显改善了构建时间,可能是因为更好的内存管理和缓存。

As a suggestion for changing your code, you could move some functionality to a DLL, and link in parallel. But I'd not make such a change just to improve build times.

作为更改代码的建议,您可以将一些功能移动到DLL,并且并行链接。但是我不会为了改善构建时间而做出这样的改变。

#4


There are some general setting suggestions on Improving link time with IncrediBuild

有关改善IncrediBuild链接时间的一般设置建议

You can also skip linking of static libs where you won't distribute them using IncrediLink

您也可以跳过静态库的链接,不使用IncrediLink分发静态库

We found that addition of a signing post build step would stop IncrediBuild from working on following projects, adding a comment to post build was supposed to help

我们发现添加一个签名后构建步骤会阻止IncrediBuild处理以下项目,添加注释到post build应该有帮助

rem IncrediBuild_AllowOverlap

See IncrediBuild_AllowOverlap doc

请参阅IncrediBuild_AllowOverlap doc

#1


I'm not aware of any parallel linking tools; I do know that Incredibuild does not allow it.

我不知道任何并行链接工具;我知道Incredibuild不允许这样做。

The biggest tool in your toolbox for avoiding link times is the appropriate level of abstraction. If your link times are long, it may be because objects know too much about other objects. Decoupling them is then the key -- through abstract interfaces (perhaps using the PIMPL paradigm), or though other methods such as event passing.

工具箱中用于避免链接时间的最大工具是适当的抽象级别。如果链接时间很长,可能是因为对象对其他对象了解太多。然后解耦它们是关键 - 通过抽象接口(可能使用PIMPL范例),或者通过其他方法,例如事件传递。

The overhead for linking projects through Project Dependencies is also quite high. If your target platform is Win32 only, or primarily, you may consider using a header to link your dependent libraries via #pragma comment(lib, "pathToLib").

通过Project Dependencies链接项目的开销也很高。如果您的目标平台仅限Win32,或者主要是您,可以考虑使用标头通过#pragma comment(lib,“pathToLib”)链接您的依赖库。

#2


If you can live without the optimization, turn off link-time code generation (remove the /GL switch or in properties c/c++ -> Optimization -> Whole Program Optimization. For the linker remove /ltcg or use the Link Time Code Generation Setting). This will make the compiler slower though, as code generation now happens during compile time.

如果您可以在没有优化的情况下生存,请关闭链接时代码生成(删除/ GL开关或在属性c / c ++ - >优化 - >整个程序优化。对于链接器删除/ ltcg或使用链接时间代码生成设置)。这会使编译器变慢,因为代码生成现在在编译期间发生。

I've seen projects that take hours to build with /GL+/LTCG, mere seconds without (this one for example: http://social.msdn.microsoft.com/Forums/en-US/vcgeneral/thread/750ed2b0-0d51-48a3-bd9a-e8f4b544ded8)

我已经看到用/ GL + / LTCG构建需要几个小时的项目,仅仅几秒钟(例如:http://social.msdn.microsoft.com/Forums/en-US/vcgeneral/thread/750ed2b0-0d51 -48a3-bd9a-e8f4b544ded8)

#3


Have you considered improving hardware?
Do you use a separate physical hard drive for for the build? What kind of drives do you use?

您是否考虑过改进硬件?您是否使用单独的物理硬盘驱动器进行构建?你用什么样的驱动器?

As a general suggestion: throw in some memory, get a Velociraptor, put only sources and build directory there, measure again. If that helps, consider a RAID 0.

作为一般建议:抛出一些内存,获得一个Velociraptor,只放置源并在那里构建目录,再次测量。如果这有帮助,请考虑RAID 0。

I've heard reports that upgrading from an XP core to an W2K3 core improved build times notably, presumably due to better memory management and caching.

我听说过从XP核心升级到W2K3核心的报告明显改善了构建时间,可能是因为更好的内存管理和缓存。

As a suggestion for changing your code, you could move some functionality to a DLL, and link in parallel. But I'd not make such a change just to improve build times.

作为更改代码的建议,您可以将一些功能移动到DLL,并且并行链接。但是我不会为了改善构建时间而做出这样的改变。

#4


There are some general setting suggestions on Improving link time with IncrediBuild

有关改善IncrediBuild链接时间的一般设置建议

You can also skip linking of static libs where you won't distribute them using IncrediLink

您也可以跳过静态库的链接,不使用IncrediLink分发静态库

We found that addition of a signing post build step would stop IncrediBuild from working on following projects, adding a comment to post build was supposed to help

我们发现添加一个签名后构建步骤会阻止IncrediBuild处理以下项目,添加注释到post build应该有帮助

rem IncrediBuild_AllowOverlap

See IncrediBuild_AllowOverlap doc

请参阅IncrediBuild_AllowOverlap doc