On 29/11/11 2:12 AM, Marco Leise wrote:
Am 28.11.2011, 14:42 Uhr, schrieb Maxim Fomin <[email protected]>:

2011/11/28 Marco Leise <[email protected]>:
Am 28.11.2011, 11:02 Uhr, schrieb Jude <[email protected]>:

I tried to write a lib and a project, which used that lib
separately, but came to conclusion that the best choice it to pull
lib code to project one. And it is not a biggest problem, because
dmd produces 700 kb executable for hello word program.

what..?

I don't know how you are managing to get 700kb for hello world...
mine clocks in a 283.7kb with dmd with no optmizations, and holy crap
1.6MB for same file with gdmd.

WTF is going on there I wonder...?

*drum roll*

148,2 kB (dmd 2.054, Linux)

*tadaa*

- 8< - - - - - - - - - - - - - - - - - - -
import std.stdio;

void main() {
writeln("Hello, world!");
}
- 8< - - - - - - - - - - - - - - - - - - -


------
import std.stdio;

class dummy
{
this() { writeln("ctor");}
~this() { writeln("dtor"); }
}

void main()
{
auto dm = new dummy();
}
-------

dmd main.d -o
377,9 kb
It is not 700 as i told, but yesterday i upgraded to 2.056. But
definitely i saw that it produces 700 kb elf for a small program.
Anyway, is 400 kb for dummy program too much?

Be aware that classes and structs have .init blocks that can grow huge
if you declare large static arrays in them. So the source code may be
small, but the executable bloats. And every template instantiation adds
to it as well. I think even just using writeln with different parameters
all over the place adds up, but thats a vague guess.

A couple of other things I noticed that can massively bloat your code using DMD:

Range case statements:

switch(c)
{
    case 0: .. case 255:
        foo();
        break;
}

Expands to

if(c == 0) goto L1;
if(c == 1) goto L1;
if(c == 2) goto L1;
...
if(c == 255) goto L1;
etc.

Which means you also get a horrible O(n) algorithm for something that should be a couple of compares. Why DMD does this is beyond me. There's a few function in Phobos that are massively bloated due to this (I've filed a bug report before anyone asks).

----

Global float arrays can bloat executables as well:

__gshared int[1_000_000] thisGoesInBss; // barely adds anything
__gshared float[1_000_000] thisGoesInData; // adds 4MB to exec

float arrays are initialised to NaN in D (in C they init to 0.0f), so they can't go in the .bss section (unless you explicitly init to 0.0f).

Reply via email to