2

I'm compiling the KiCad EDA suite, using MSVC 9 (15.0.30729.1).

This is a fairly complex piece of software, so a total compilation time of 3.5 hours for an /O2 Release build on an i3 is completely acceptable. To further optimize the code, I have enabled /GL and /LTCG to use the link time code generation feature.

Looking at the largest component: on x86, this slowed down the link process somewhat (as expected), but gave no reduction in code size (7.3 MB); on x64, a single linker invocation now takes 1.5 hours on its own, and still does not reduce code size (10.1 MB) in the slightest.

For comparison, gcc on x64 generates 11 MB without -flto, and 9.5 MB with -flto (taking 10 minutes for the linker step) -- while I'm aware that this MSVC version is significantly older, I'm certainly not used to gcc generating smaller code in less time than MSVC.

As my experience with the MSVC toolchain is superficial at best: is it typical for link-time code generation to not yield a reduction in code size? Is there a compiler option I might have missed?

Sam Protsenko
  • 14,045
  • 4
  • 59
  • 75
Simon Richter
  • 28,572
  • 1
  • 42
  • 64
  • Do you have any PIC flag on? – Marco A. May 27 '15 at 13:33
  • LTO does not necessarily reduce code size. With the possibility of inlining small functions from other compilation units, one should expect a performance increase. Also debugging symbols might be present even in a release build. – rpress May 27 '15 at 14:28
  • The problem is MSVC, which doesn't have a PIC flag -- all code is always generated position-dependent, with full relocation information. Debug information lives in the PDB file next to it. – Simon Richter May 27 '15 at 14:38
  • Did you look at the [`/opt:icf=iterations`](https://msdn.microsoft.com/en-us/library/bxwfs976%28v=vs.90%29.aspx) linker option? Maybe that can squeeze some more out of it, but consider the note about function addresses first. To speed up compilation, did you look at [`/MP`](https://msdn.microsoft.com/en-us/library/bb385193%28v=vs.90%29.aspx)? Also, MSVC 12 has [multithreaded link-time code generation](https://msdn.microsoft.com/en-us/library/dn655038.aspx), which should speed up your build process quite a bit. – bogdan May 28 '15 at 11:58
  • More ICF passes would probably only give miniscule savings, I think (I already have two passes). `/MP` would probably invalidate the compile time statistics (I'm not opposed to long build times, I'm just investigating the reason for them). – Simon Richter May 28 '15 at 15:25
  • My impression of LTCG is that it's geared toward speed at the cost of size. It's good at finding cross module inlining opportunities. More inlining often means more code and possibly reduces the likelihood of two comdats being identical. So larger code doesn't surprise me. – Adrian McCarthy Jan 27 '17 at 17:43

0 Answers0