www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.ldc - Object size?

reply Andy Valencia <dont spam.me> writes:
I'm early days on dlang, and found a small HTTP server 
"serverino".  I have it built, linked with a test program, and 
running.  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.

Thanks!
Andy Valencia
Mar 01
parent reply Andy Valencia <dont spam.me> writes:
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
Mar 13
parent reply kinke <noone nowhere.com> writes:
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).
Mar 13
parent Andy Valencia <dont spam.me> writes:
On Wednesday, 13 March 2024 at 18:25:25 UTC, kinke wrote:
 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).
Thank you! A wealth of avenues. It's particularly encouraging that this executable growth doesn't scale with LOC--that would be a little intimidating. I will head off and research the areas you've listed. Andy
Mar 14