views:

251

answers:

2

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?

+1  A: 

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.

ted_j
+2  A: 

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.

JSBangs
Why is it O(N²)? It seems like it would be O(n log n)?
280Z28