Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Visual C++ 2008: Finding the cause of slow link times

I have a legacy C++ project that takes an annoyingly long time to build (several minutes, even for small incremental changes), and I found most of the time was spent linking.

The project is already using precompiled headers and incremental compilation. I have enabled the "/time" command line parameter in the hope I would get more details about what is slowing the linker, and got the following output:

1>Linking...
1>  MD Merge: Total time = 59.938s
1>  Generate Transitions: Total time = 0.500s
1>  MD Finalize: Total time = 7.328s
1>Pass 1: Interval #1, time = 71.718s
1>Pass 2: Interval #2, time = 8.969s
1>Final: Total time = 80.687s
1>Final: Total time = 80.953s

Is there a way to get more details about each of these steps? For example, I would like to find if they are spending most time linking to a specific .lib or .obj file.

Also, is there any documentation that explains what each of these steps do?

like image 684
ckarras Avatar asked May 04 '10 16:05

ckarras


2 Answers

The "MD Merge" step is looking for and merging duplicate string literals and other duplicated data. Note that the time required to do this is O(n^2) over the number of string literals that you have, so I once had a similar problem where a header file with ~10K string literals would take 5 min to link.

Adding the linker flag /OPT:NOICF may help. Alternately, examine why you have so many literals to fold.

like image 114
JSBձոգչ Avatar answered Oct 16 '22 05:10

JSBձոգչ


Hopefully someone from the vs dev team would see this and be able to comment, maybe post a link to their forum/blog and ope for the best?

First random theory that comes to me would be to investigate how much in-header code is generated, such that "phase 1" would have such a lot of work to do eliminating dupes. I am specifically thinking of template or macro or old-style constant declarations. These would also be aggrevated by inclusion into a common precompiled header as I have seen very often wihh naive setup for windows/mfc/STL using projects.

Good luck, it would be great to hear if you find something particular that was bad.

like image 30
ted_j Avatar answered Oct 16 '22 04:10

ted_j