www.digitalmars.com         C & C++   DMDScript  

digitalmars.D - Big executable?

reply Andre Tampubolon <andre lc.vlsm.org> writes:
Hi,

I just started learning D (my background is C, anyway).

I compiled this simple code using DMD 2.049 (dmd -O -release test1.d) :
import std.stdio;

void main()
{
     writefln("%s World", "Hello");
}

The final executable size is about 300 KB. Isn't that a bit huge, 
considering the same code compiled using C or Pascal compiler will give 
smaller executable? So I tried to look at the *.map, and apparently the 
D runtime pulls a lot of stuff. I am just wondering, anyway.
Oct 05 2010
next sibling parent reply Kagamin <spam here.lot> writes:
Andre Tampubolon Wrote:

 import std.stdio;
 
 void main()
 {
      writefln("%s World", "Hello");
 }
 
 The final executable size is about 300 KB. Isn't that a bit huge, 

300kb is the lower limit if you use phobos and druntime.
Oct 05 2010
next sibling parent reply so <so so.do> writes:
On Wed, 06 Oct 2010 09:36:00 +0300, Kagamin <spam here.lot> wrote:

 Andre Tampubolon Wrote:

 import std.stdio;

 void main()
 {
      writefln("%s World", "Hello");
 }

 The final executable size is about 300 KB. Isn't that a bit huge,

300kb is the lower limit if you use phobos and druntime.

First response (and yet not actually an answer) to a newcomer is from a phobos hater, isn't it grand! Anyways, there are not much of reasons that should make D produce bigger executables than other system languages. I remember, just recently Andrei fixed something in phobos that affects exe size. It is getting better but as far as i can gather from this newsgroup it is a low priority (bug?). -- Using Opera's revolutionary e-mail client: http://www.opera.com/mail/
Oct 06 2010
parent bearophile <bearophileHUGS lycos.com> writes:
Jonathan M Davis:

 I'm not sure if there have been any bugs reported on large executable sizes or
not.

http://d.puremagic.com/issues/show_bug.cgi?id=2254 Bye, bearophile
Oct 06 2010
prev sibling parent Jonathan M Davis <jmdavisProg gmx.com> writes:
On Wednesday 06 October 2010 00:11:05 so wrote:
 On Wed, 06 Oct 2010 09:36:00 +0300, Kagamin <spam here.lot> wrote:
 Andre Tampubolon Wrote:
 import std.stdio;
 
 void main()
 {
 
      writefln("%s World", "Hello");
 
 }
 
 The final executable size is about 300 KB. Isn't that a bit huge,

300kb is the lower limit if you use phobos and druntime.

First response (and yet not actually an answer) to a newcomer is from a phobos hater, isn't it grand! Anyways, there are not much of reasons that should make D produce bigger executables than other system languages. I remember, just recently Andrei fixed something in phobos that affects exe size. It is getting better but as far as i can gather from this newsgroup it is a low priority (bug?).

I'm not sure if there have been any bugs reported on large executable sizes or not. But I believe that the Phobos developers are far more interested in improving the functionality of Phobos than they are in reducing the resulting executable size. They may very well want to do some work to reduce it, but it's bound to be a lower priority than functionality unless it's really bad. - Jonathan M Davis
Oct 06 2010
prev sibling next sibling parent reply Jonathan M Davis <jmdavisProg gmx.com> writes:
On Tuesday 05 October 2010 23:12:08 Andre Tampubolon wrote:
 Hi,
 
 I just started learning D (my background is C, anyway).
 
 I compiled this simple code using DMD 2.049 (dmd -O -release test1.d) :
 import std.stdio;
 
 void main()
 {
      writefln("%s World", "Hello");
 }
 
 The final executable size is about 300 KB. Isn't that a bit huge,
 considering the same code compiled using C or Pascal compiler will give
 smaller executable? So I tried to look at the *.map, and apparently the
 D runtime pulls a lot of stuff. I am just wondering, anyway.

People complain about that from time to time, and I believe that some work has been done to reduce the executable size, but the reality of the manner is that the plumbing that comes with druntime and the GC is going to take up some space, even if you don't use much of it. However, it will likely get dwarfed by the rest of your code if you write a decent size program, so it really won't matter much with real programs. It's just that the minimum size is a bit larger than some would like. - Jonathan M Davis
Oct 06 2010
parent Andre Tampubolon <andre lc.vlsm.org> writes:
On 10/6/2010 2:14 PM, Jonathan M Davis wrote:
 On Tuesday 05 October 2010 23:12:08 Andre Tampubolon wrote:
 Hi,

 I just started learning D (my background is C, anyway).

 I compiled this simple code using DMD 2.049 (dmd -O -release test1.d) :
 import std.stdio;

 void main()
 {
       writefln("%s World", "Hello");
 }

 The final executable size is about 300 KB. Isn't that a bit huge,
 considering the same code compiled using C or Pascal compiler will give
 smaller executable? So I tried to look at the *.map, and apparently the
 D runtime pulls a lot of stuff. I am just wondering, anyway.

People complain about that from time to time, and I believe that some work has been done to reduce the executable size, but the reality of the manner is that the plumbing that comes with druntime and the GC is going to take up some space, even if you don't use much of it. However, it will likely get dwarfed by the rest of your code if you write a decent size program, so it really won't matter much with real programs. It's just that the minimum size is a bit larger than some would like. - Jonathan M Davis

OK. Thanks for the input. I can live with that :)
Oct 06 2010
prev sibling next sibling parent reply Jacob Carlborg <doob me.com> writes:
On 2010-10-06 08:12, Andre Tampubolon wrote:
 Hi,

 I just started learning D (my background is C, anyway).

 I compiled this simple code using DMD 2.049 (dmd -O -release test1.d) :
 import std.stdio;

 void main()
 {
 writefln("%s World", "Hello");
 }

 The final executable size is about 300 KB. Isn't that a bit huge,
 considering the same code compiled using C or Pascal compiler will give
 smaller executable? So I tried to look at the *.map, and apparently the
 D runtime pulls a lot of stuff. I am just wondering, anyway.

You are aware of that C is (almost always) dynamically linked with the standard and runtime library but D (usually) is not? Using D1 and Tango on Mac OS X (which supports dynamic linking of the standard library) gives an executable of the size 16 KB if I recall correctly. -- /Jacob Carlborg
Oct 06 2010
next sibling parent reply so <so so.do> writes:
On Wed, 06 Oct 2010 10:40:11 +0300, Jacob Carlborg <doob me.com> wrote:

 On 2010-10-06 08:12, Andre Tampubolon wrote:
 Hi,

 I just started learning D (my background is C, anyway).

 I compiled this simple code using DMD 2.049 (dmd -O -release test1.d) :
 import std.stdio;

 void main()
 {
 writefln("%s World", "Hello");
 }

 The final executable size is about 300 KB. Isn't that a bit huge,
 considering the same code compiled using C or Pascal compiler will give
 smaller executable? So I tried to look at the *.map, and apparently the
 D runtime pulls a lot of stuff. I am just wondering, anyway.

You are aware of that C is (almost always) dynamically linked with the standard and runtime library but D (usually) is not? Using D1 and Tango on Mac OS X (which supports dynamic linking of the standard library) gives an executable of the size 16 KB if I recall correctly.

Which is the next thing Walter will be working on after this 64bit business. -- Using Opera's revolutionary e-mail client: http://www.opera.com/mail/
Oct 06 2010
parent reply Walter Bright <newshound2 digitalmars.com> writes:
so wrote:
 On Wed, 06 Oct 2010 10:40:11 +0300, Jacob Carlborg <doob me.com> wrote:
 You are aware of that C is (almost always) dynamically linked with the 
 standard and runtime library but D (usually) is not? Using D1 and 
 Tango on Mac OS X (which supports dynamic linking of the standard 
 library) gives an executable of the size 16 KB if I recall correctly.

Which is the next thing Walter will be working on after this 64bit business.

Yes, making Phobos a shared library rather than statically linking it will pretty much resolve this problem.
Oct 06 2010
parent Jacob Carlborg <doob me.com> writes:
On 2010-10-06 20:01, Walter Bright wrote:
 so wrote:
 On Wed, 06 Oct 2010 10:40:11 +0300, Jacob Carlborg <doob me.com> wrote:
 You are aware of that C is (almost always) dynamically linked with
 the standard and runtime library but D (usually) is not? Using D1 and
 Tango on Mac OS X (which supports dynamic linking of the standard
 library) gives an executable of the size 16 KB if I recall correctly.

Which is the next thing Walter will be working on after this 64bit business.

Yes, making Phobos a shared library rather than statically linking it will pretty much resolve this problem.

Of course when Phobos is a dynamic library you would probably need to distributed it as well and then you will have same size again or even larger. -- /Jacob Carlborg
Oct 07 2010
prev sibling next sibling parent so <so so.do> writes:
On Thu, 07 Oct 2010 11:39:41 +0300, Jacob Carlborg <doob me.com> wrote:

 On 2010-10-06 20:01, Walter Bright wrote:
 so wrote:
 On Wed, 06 Oct 2010 10:40:11 +0300, Jacob Carlborg <doob me.com> wrote:
 You are aware of that C is (almost always) dynamically linked with
 the standard and runtime library but D (usually) is not? Using D1 and
 Tango on Mac OS X (which supports dynamic linking of the standard
 library) gives an executable of the size 16 KB if I recall correctly.

Which is the next thing Walter will be working on after this 64bit business.

Yes, making Phobos a shared library rather than statically linking it will pretty much resolve this problem.

Of course when Phobos is a dynamic library you would probably need to distributed it as well and then you will have same size again or even larger.

Eh? -- Using Opera's revolutionary e-mail client: http://www.opera.com/mail/
Oct 07 2010
prev sibling next sibling parent retard <re tard.com.invalid> writes:
Thu, 07 Oct 2010 13:27:23 +0300, so wrote:

 On Thu, 07 Oct 2010 11:39:41 +0300, Jacob Carlborg <doob me.com> wrote:
 
 On 2010-10-06 20:01, Walter Bright wrote:
 so wrote:
 On Wed, 06 Oct 2010 10:40:11 +0300, Jacob Carlborg <doob me.com>
 wrote:
 You are aware of that C is (almost always) dynamically linked with
 the standard and runtime library but D (usually) is not? Using D1
 and Tango on Mac OS X (which supports dynamic linking of the
 standard library) gives an executable of the size 16 KB if I recall
 correctly.

business.

Yes, making Phobos a shared library rather than statically linking it will pretty much resolve this problem.

Of course when Phobos is a dynamic library you would probably need to distributed it as well and then you will have same size again or even larger.


If the DMD/Phobos distribution doesn't provide compatible API/ABI between DMD/Phobos versions, the dynamic library has very little use since all libraries need to be distributed with the 3rd party application.
Oct 07 2010
prev sibling next sibling parent so <so so.do> writes:
On Thu, 07 Oct 2010 13:41:26 +0300, retard <re tard.com.invalid> wrote:

 Thu, 07 Oct 2010 13:27:23 +0300, so wrote:

 On Thu, 07 Oct 2010 11:39:41 +0300, Jacob Carlborg <doob me.com> wrote:

 On 2010-10-06 20:01, Walter Bright wrote:
 so wrote:
 On Wed, 06 Oct 2010 10:40:11 +0300, Jacob Carlborg <doob me.com>
 wrote:
 You are aware of that C is (almost always) dynamically linked with
 the standard and runtime library but D (usually) is not? Using D1
 and Tango on Mac OS X (which supports dynamic linking of the
 standard library) gives an executable of the size 16 KB if I recall
 correctly.

business.

Yes, making Phobos a shared library rather than statically linking it will pretty much resolve this problem.

Of course when Phobos is a dynamic library you would probably need to distributed it as well and then you will have same size again or even larger.


If the DMD/Phobos distribution doesn't provide compatible API/ABI between DMD/Phobos versions, the dynamic library has very little use since all libraries need to be distributed with the 3rd party application.

If we want to distribute a single shared library, until things get settled there is nothing we can do. Also we are not talking about a single exec per project right? If this is what you mean, yes i agree it has no use, but if in your project you got more than one executable or shared library it is a gain. We all know how shared libraries work right? -- Using Opera's revolutionary e-mail client: http://www.opera.com/mail/
Oct 07 2010
prev sibling parent retard <re tard.com.invalid> writes:
Thu, 07 Oct 2010 14:08:17 +0300, so wrote:

 On Thu, 07 Oct 2010 13:41:26 +0300, retard <re tard.com.invalid> wrote:
 
 Thu, 07 Oct 2010 13:27:23 +0300, so wrote:

 On Thu, 07 Oct 2010 11:39:41 +0300, Jacob Carlborg <doob me.com>
 wrote:

 On 2010-10-06 20:01, Walter Bright wrote:
 so wrote:
 On Wed, 06 Oct 2010 10:40:11 +0300, Jacob Carlborg <doob me.com>
 wrote:
 You are aware of that C is (almost always) dynamically linked with
 the standard and runtime library but D (usually) is not? Using D1
 and Tango on Mac OS X (which supports dynamic linking of the
 standard library) gives an executable of the size 16 KB if I
 recall correctly.

business.

Yes, making Phobos a shared library rather than statically linking it will pretty much resolve this problem.

Of course when Phobos is a dynamic library you would probably need to distributed it as well and then you will have same size again or even larger.


If the DMD/Phobos distribution doesn't provide compatible API/ABI between DMD/Phobos versions, the dynamic library has very little use since all libraries need to be distributed with the 3rd party application.

If we want to distribute a single shared library, until things get settled there is nothing we can do. Also we are not talking about a single exec per project right? If this is what you mean, yes i agree it has no use, but if in your project you got more than one executable or shared library it is a gain.

Yes, that's a fair point.
 
 We all know how shared libraries work right?

Sorry for that. The answer was directed more towards the original poster.
Oct 07 2010
prev sibling next sibling parent =?ISO-8859-1?Q?Anders_F_Bj=F6rklund?= <afb algonet.se> writes:
Andre Tampubolon wrote:
 I compiled this simple code using DMD 2.049 (dmd -O -release test1.d) :
 import std.stdio;
 
 void main()
 {
     writefln("%s World", "Hello");
 }
 
 The final executable size is about 300 KB. Isn't that a bit huge, 
 considering the same code compiled using C or Pascal compiler will give 
 smaller executable? So I tried to look at the *.map, and apparently the 
 D runtime pulls a lot of stuff. I am just wondering, anyway.

A better size comparison would be with C++ and a static libstdc++: ln -s `g++ -print-file-name=libstdc++.a` g++ -O2 -o hello-cxx -static-libgcc -L. hello.cpp Using GDC instead, no 64-bit DMD (avoiding libgcc_s.so, to compare): # gdmd -O -release -ofhello-d hello.d gdc -O2 -frelease -o hello-d -static-libgcc hello.d 540K hello-cxx 312K hello-d And yes it is big, for the trivial example. gcc -O2 -o hello-c hello.c 12K hello-c 4,0K hello.sh --anders PS. Static libgcc isn't really a good idea as it breaks exceptions. It was more for the size comparisons. A dynamic Phobos would "fix". And yes, those were the sizes without the debugging symbols. Except that the shell script really was 30 bytes... "strip -S", "du -h".
Oct 06 2010
prev sibling next sibling parent reply Justin Johansson <3.1415926536 bingmail.com> writes:
On 6/10/2010 5:12 PM, Andre Tampubolon wrote:
 Hi,

 I just started learning D (my background is C, anyway).

 I compiled this simple code using DMD 2.049 (dmd -O -release test1.d) :
 import std.stdio;

 void main()
 {
 writefln("%s World", "Hello");
 }

 The final executable size is about 300 KB. Isn't that a bit huge,
 considering the same code compiled using C or Pascal compiler will give
 smaller executable? So I tried to look at the *.map, and apparently the
 D runtime pulls a lot of stuff. I am just wondering, anyway.

Try assembly language. Your executable will be less than 256 bytes (perhaps on legacy operating systems, and, of course, using the O/S to make a call to write to stdout). Naturally YMMV depending on the language translator that you use, and, as you have appropriately noted, your mileage experience is not climate-change friendly. -- Justin
Oct 07 2010
parent Juanjo Alvarez <juanjux gmail.com> writes:
Justin Johansson Wrote:


 Naturally YMMV depending on the language translator that you use,
 and, as you have appropriately noted, your mileage experience is
 not climate-change friendly.

46 bytes on Linux, using serious hackery; interesting & funny read: http://www.muppetlabs.com/~breadbox/software/tiny/teensy.html
Oct 07 2010
prev sibling parent Andrej Mitrovic <andrej.mitrovich gmail.com> writes:
I had an odd thing going while coding a D app. It only had a few
thousand lines of code, but at some point the more code I added the
executable would get smaller, until I would add even more code and
then it would finally expand again. I guess this has something to do
with DMD optimizations.


On 10/6/10, Andre Tampubolon <andre lc.vlsm.org> wrote:
 Hi,

 I just started learning D (my background is C, anyway).

 I compiled this simple code using DMD 2.049 (dmd -O -release test1.d) :
 import std.stdio;

 void main()
 {
      writefln("%s World", "Hello");
 }

 The final executable size is about 300 KB. Isn't that a bit huge,
 considering the same code compiled using C or Pascal compiler will give
 smaller executable? So I tried to look at the *.map, and apparently the
 D runtime pulls a lot of stuff. I am just wondering, anyway.

Oct 14 2010