3

I would like to reduce the link-time of my project, and to do that I want to understand, exactly, why it takes so long - is it a specific library? is it something else? How can I know what to change in order to improve the link time?

Update

There are many "generic" advices such as "reduce library dependencies" but they seem impractical in our case. Our code-base is large, there are many library dependencies, and finding out, by experimenting, which dependency affects the link time the most will take an enormous amount of time. A large portion of the code base was developed years ago without thinking that much about dependencies. We are looking for a way to find a concrete direction, such as "dependency of X on Y will benefit the link time", without exhaustively trying all possible directions..

Note that we are not using LTCG at all.

Alex Shtoff
  • 2,520
  • 1
  • 25
  • 53
  • 1
    There's some good advice [here](http://blogs.msdn.com/b/vcblog/archive/2013/10/30/the-visual-c-linker-best-practices-developer-iteration.aspx) and similar previously asked questions [here](http://stackoverflow.com/questions/143808/how-to-improve-link-performance-for-a-large-c-application-in-vs2005/9733242#9733242) and [here](http://stackoverflow.com/questions/921693/how-to-speed-up-c-linking-time). – acraig5075 May 21 '14 at 13:40
  • See update. I wrote more specifically what I am looking for. – Alex Shtoff May 22 '14 at 07:26
  • 1
    You could start assess your link operation by enabling the verbose level log output linker option. http://stackoverflow.com/questions/2850620/how-to-read-verbose-vc-linker-output – 9dan May 22 '14 at 07:34
  • The only thing I am missing is a way to print the time of each log entry.. so I can understand which operations take a long time. – Alex Shtoff May 22 '14 at 07:48

2 Answers2

3

First, I modified the project properties for my executable that takes a long time to link and added /VERBOSE to the linker command line. That way, the linker produces a detailed log of what it is doing.

Then, I wrote a small powershell script to timestamp each line that my build produces. That way I can see how much time passes between the lines the linker prints. Assuming the linker is not lying about what it is doing, this gives me quite a good hint about how much time it spends doing which operation.

Here is the powershell code:

msbuild /p:Configuration=Debug /p:Platform=X64 /m MY_SOLUTION.sln *>&1 | & {
    process {
        $date = get-date -DisplayHint Time -Format hh:mm:ss.fff
        Write-Host $date -NoNewLine
        Write-Host $_
    }
}
Alex Shtoff
  • 2,520
  • 1
  • 25
  • 53
0

For Visual C++, I think the first step in the linking time optimization is to turn off the 'Whole-Program Optimization (/GL)' option.

I would like to recommend a book on this subject: Large-Scale C++ Software Design, by John Lakos. This book gives many good points on the large scale C++ development, but I think the main theme is 'how to design package relationship to minimize linking time'.

It is about module(lib, dll) dependency minimization techniques. Because, linking a project consists of many small modules is tend to run faster than one big (many files) project.

Also, check out this blog post: The “Large-Scale C++ Software Design” rules in practice

9dan
  • 4,222
  • 2
  • 29
  • 44