Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to speed up c++ linking time

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.

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 )

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 ?

Thanks for reply 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
  • other static libraries are already included via #pragma comment(lib, "pathToLib"). (also because of easier maintenance]
  • HW : quad core q6600, 8GB ram, 3x WD raptor raid 0. Windows Vista 64bit
like image 273
Ludek Vodicka Avatar asked May 28 '09 16:05

Ludek Vodicka


People also ask

How do I reduce linking time?

create a ramdisk ,compile to that and link to harddisk. since you're using a lot of static libraries ,you can create a giant library containing all thos libraries so you end up with one libray.

Why does linking take so long?

Linkers have to copy large amount of data from object files to an output file, and that is inevitably slow.


2 Answers

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

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.

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").

like image 148
Brett Douville Avatar answered Sep 23 '22 16:09

Brett Douville


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.

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)

like image 45
Ben Schwehn Avatar answered Sep 21 '22 16:09

Ben Schwehn