Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Profiling visual c++ link time

Tags:

visual-c++

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.

like image 510
Alex Shtof Avatar asked Mar 10 '26 23:03

Alex Shtof


1 Answers

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 $_
    }
}
like image 156
Alex Shtof Avatar answered Mar 12 '26 18:03

Alex Shtof



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!