[cfe-dev] Link-time optimization versus header-only

Per Bull Holmen via cfe-dev cfe-dev at lists.llvm.org
Tue Aug 4 08:15:41 PDT 2020


Hi

I hope it's OK that I post here even though I'm not a developer on the
clang compiler itself. Googling turns up a bunch of answers that appear to
be pure speculation (even on StackOverflow), so I thought maybe the clang
developers had more informed opinions about it.

Common wisdom says that one should keep c++ implementations in separate
files (not in header files), to reduce recompilation times. However, that
brings out the fear that it might hurt runtime performance, as the compiler
might have less information available for inlining. But then again, clang
does whole module optimization, so maybe there would be no difference
performance-wise? On the other hand, there's the concept of precompiled
headers, so maybe it wouldn't make any difference for compile times either.

So the questions are:
1) With link-time optimization set to monolithic, will a project split into
separate compilation units be equally well optimized as with the
header-only approach?
2) Will it make a difference to compilation times, compared to the
header-only approach, using precompiled headers?

The longer link times with lto does not matter, because most of the time
you'll be doing debug builds, without lto.

Per
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-dev/attachments/20200804/92090961/attachment.html>


More information about the cfe-dev mailing list