Filesize of D binaries?

Leandro Lucarella llucarella at integratech.com.ar
Mon Jan 8 09:57:49 PST 2007


Mike Simons escribió:
> Frits Van Bommel wrote:
> """writef an friends call a function to handle the formatting. Since
> they're variadic functions, that function needs to be able to handle any
> type. So it contains code for every primitive type, structs, classes,
> etc. The compiler can't (currently) determine which of those are unused
> so it includes all of that code, plus any code they in turn need, and so on. """
> 
> Ah; that would explain it. My main concern was that as you started getting larger
> programs the size would be proportional, but given what you've said it shouldn't
> be. Infact, beyond a certain amount of imports the size should stop rising
> drastically as more and more dependencies are met with the code that is already
> linked?
> 
> Anders F Björklund wrote:
> """250K sounds a bit much, like if debugging symbols wasn't stripped ? """
> 
> The exact command I used was "gcd hello.d -o hello". I tried various other flags
> like O3 and frelease and neither made any difference whatsoever.
> However, when I compiled the exact same code using gdc on win32 (under mingw) it
> was only ~100k.
> 
> I guess this is due to size differences between the static libs on each platform .

Try to strip both binaries (C and D), and compile them with similar 
flags too:
$ strip my_c_hello_world
$ strip my_d_hello_world

Then you can compare the sizes more accurately. But surely, D small 
programs are much larger than C ones, because D have a bigger runtime 
(there is a lot of module initialization code, GC, etc). And std.stdio 
doesn't look like the cause of the size, since there is no appreciable 
difference in the size of import std.stdio; int main() { 
writefln("Hello"); return 0; } and int main() { return 0; }, at least 
with DMD.

Anyways, 150K (this is the difference in size between a stripped "null" 
D program compiled with DMD and the same program compiled in C) of extra 
code for initialization looks like too much (it's dynamically linked, 
the big part of the extra code should be on phobos). When linked 
statically, DMD is 640KB and C is 430KB (both stripped), which looks 
like a fair difference since D version have all the GC code on it, for 
example.
The test programs are:
luca at azazel:/tmp$ cat null.d
int main()
{
	return 0;
}
luca at azazel:/tmp$ cat null.c
int main()
{
	return 0;
}

Compiled with (dynamically linked):
dmd null.d
gcc -o null_c null.c

And statically linked:
dmd -c null.d
gcc null.o -o null -m32 -lphobos -lpthread -lm -static
gcc -o null_c -static null.c

And again, all stripped before comparing sizes.

-- 
Leandro Lucarella
Integratech S.A.
4571-5252



More information about the Digitalmars-d mailing list