Link time optimization in D

Leandro Lucarella llucax at gmail.com
Mon May 31 19:40:35 PDT 2010


Walter Bright, el 31 de mayo a las 15:41 me escribiste:
> retard wrote:
> >Mon, 31 May 2010 18:23:18 +0200, Pelle wrote:
> >
> >>On 05/31/2010 05:43 PM, retard wrote:
> >>>DMD is much slower than Sun Javac/Jvm 7, GNU GCC 4.5, and LLVM.
> >>For very special values of much, I suppose.
> >
> >Polymorphic method calls, auto-vectorization, link-time
> >optimization, floating point performance, etc.
> 
> Link time optimization? Let's examine it:
> 
> https://lwn.net/Articles/387122/
> 
> "When source files are compiled and linked using -flto, GCC applies
> optimizations as if all the source code were in a single file. This
> allows GCC to perform more aggressive optimizations across files,
> such as inlining the body of a function from one file that is called
> from a different file, and propagating constants across files. In
> general, the LTO framework enables all the usual optimizations that
> work at a higher level than a single function to also work across
> files that are independently compiled."
> 
> D has had that for 8 years now, it's just done in the compiler
> instead of the linker. You can specify as many D source modules as
> you want on the command line to the compiler, and it will compile &
> optimizer & inline them all together and generate one object file.
> 
> Essentially, link time optimization is a hack to get around the
> language problem C/C++ have with their separate compilation model.
> 
> To say D code is slower because it lacks link-time optimization is a
> false supposition.

Yeah, but you can't get link-time optimization if you compile each file
separately (to enable partial compilation when you change just one
file). Yes I know that D compiles really fast, but you can never compile
fast enough :)

With really huge projects, compiling the whole project can take, let's
say 10 seconds, while compiling *just* one file takes a fraction of
a seconds (is instantaneous from a human point of view). The difference
is waiting a little time vs not waiting at all.

That said, doing link-time optimization is probably useful only for
builds that you will test a lot or production code, so maybe for that
builds one can afford the extra waiting time, it's just a little
annoying to have to use a different build method for those builds,
though :)

-- 
Leandro Lucarella (AKA luca)                     http://llucax.com.ar/
----------------------------------------------------------------------
GPG Key: 5F5A8D05 (F8CD F9A7 BF00 5431 4145  104C 949E BFB6 5F5A 8D05)
----------------------------------------------------------------------
El techo de mi cuarto lleno de galaxias


More information about the Digitalmars-d mailing list