Huge output size for simple programs

Jonathan M Davis via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Fri Sep 11 05:36:27 PDT 2015


On Friday, September 11, 2015 11:15:31 NX via Digitalmars-d-learn wrote:
> I compile a simple hello world program in C and the results:
>
> hello_world.o -> 1.5 KB
> hello_world (linux executable) -> 8.5 KB
>
>
> Then I compile a simple hello world program in D (using DMD) and
> the results:
>
> hello_world.o -> 9.3 KB
> hello_world (linux executable) -> 575.9 KB
>
>
> Then I compile a simple hello world program in D (using GDC) and
> the results:
>
> hello_world.o -> 24.6 KB
> hello_world (linux executable) -> 13 MB !!!
>
> What's the reason for that? What makes D applications so much
> bloated?
> Is this because whole GC implementation code is injected into
> executable or maybe libphobos.a being statically linked or is
> this because TypeInfo* ModuleInfo* stuff?

It's primarily because the d runtime and standard library are statically
linked, whereas the C runtime and standard library are dynamically linked.
Some of the stuff related to TypeInfo and other D-specific features does
make it worse than it would be otherwise, but fundamentally, if you're
statically linking in the D runtime and standard library, you're always
going to get larger programs than when you dynamically link. However, a lot
of that won't increase in size as a program's source code increases in size,
because the runtime and standard library don't increase in size just because
you have more code. I expect that there will be improvements to the size of
D binaries in the future though, since there is some desire among the
compiler devs to figure out how to reduce it, and you can use libphobos.so
if you'd like. It's just that its ABI changes from release to release, so
your D programs risk breaking every time you upgrade and thus likely will
have to be rebuilt, whereas you wouldn't have the same problem with
libphobos.a, since in that case, it all ends up in the executable.

Now, as to why the gdc binary is so large, I don't know. My guess is that it
has something to do with the debug symbols. You could try building with -g
or -gc to see how that affects the dmd-generated binary.

Regardless, this is the sort of thing that looks really bad with hello
world, because your code is really small, and the D runtime and standard
library dwarf it, whereas if you have a much larger program, the difference
between D and C/C++ is likely to be a lot less noticeable.

- Jonathan M Davis



More information about the Digitalmars-d-learn mailing list