Object size?
kinke
noone at nowhere.com
Wed Mar 13 18:25:25 UTC 2024
On Wednesday, 13 March 2024 at 17:40:52 UTC, Andy Valencia wrote:
> On Saturday, 2 March 2024 at 04:33:02 UTC, Andy Valencia wrote:
>> ...But the executable size is enormous. For 405 statements,
>> it has a text size of 712k bytes. Whoof. Is this normal?
>> I'm using ldc2 version 1.30.0.
>
> I've played with this some more; this code:
>
> import std.stdio : writefln;
>
> void
> main(in string[] argv)
> {
> writefln("%s: %d thingies\n", argv[0], 123);
> }
>
> results in 252k of text size in the executable. It seems like
> there's some sort of combinatoric explosion going on behind the
> scenes?
>
> Andy
This isn't LDC-specific and regularly comes up as beginner's
topic (in general forums, try a search). One thing is that
druntime and Phobos are linked statically by default (with
official LDC packages at least; distro versions might not); with
LDC, use `-link-defaultlib-shared` to link the shared variants.
That's a pretty constant offset though, so for tiny hello-world
programs, it might seem huge, but rest assured, it doesn't go on
like this when the program becomes fleshier.
The 2nd thing is that templates can easily lead to an explosion
of code. Phobos' std.format is a prime and well-known example of
that, sadly. If you use `-vcg-ast` for compiling your little .d,
the compiler will generate a `*.d.cg` file with the instantiated
templates. You'll see that it's almost 20k lines (~430 KB of
source code).
More information about the digitalmars-d-ldc
mailing list