Jump to page: 1 2 3
Thread overview
hello world in D
May 31, 2013
khurshid
May 31, 2013
Adam D. Ruppe
May 31, 2013
khurshid
May 31, 2013
Adam D. Ruppe
May 31, 2013
Brad Anderson
May 31, 2013
Marco Leise
May 31, 2013
Regan Heath
May 31, 2013
Adam D. Ruppe
May 31, 2013
Regan Heath
May 31, 2013
Adam D. Ruppe
May 31, 2013
Craig Dillabaugh
May 31, 2013
Adam D. Ruppe
May 31, 2013
Regan Heath
May 31, 2013
deadalnix
Jun 01, 2013
Paulo Pinto
Jun 01, 2013
SomeDude
May 31, 2013
Marco Leise
May 31, 2013
Rob T
May 31, 2013
Jonathan M Davis
May 31, 2013
Rob T
Jun 01, 2013
Paulo Pinto
Jun 01, 2013
Rob T
May 31, 2013
I just download dmd 2.063, and compile simple "hello world" program:

// hello.d
import std.stdio;
int main()
{
    writeln("hello world");
    return 0;
}


with -O -release -inline -noboundscheck  flags.

And size of result output file  'hello'  equal to 1004.1 Kbyte !!!
Why size is big?


I'm using  fedora 14, 32-x.


Regards,
 Khurshid.
May 31, 2013
On Friday, 31 May 2013 at 14:33:48 UTC, khurshid wrote:
> And size of result output file  'hello'  equal to 1004.1 Kbyte

Whoa, that's up like several times from the last dmd release.... you can get down to 600 kb or so by not using the flags. Strange, combining all those flags increases the size by 50%. This is probably some kind of bug in the new release.

But even without bugs, writeln actually pulls in a lot of code. If you use printf instead of std.stdio, you'll save about 150 KB in the executable

import core.stdc.stdio;

void main() {
        printf("hello\n");
}

$ dmd test2.d
$ ls -lh test2
-rwxr-xr-x 1 me users 287K 2013-05-31 10:40 test2
$ strip test2
$ ls -lh test2
-rwxr-xr-x 1 me users 195K 2013-05-31 10:41 test2



D programs don't have any dependencies outside the operating system by default, so they carry the parts of the standard library they use with them.

That 195K test2 program is mostly druntime's code. If you pull in std.stdio it also grabs much of the phobos standard library to support printing, conversion of numbers to strings, and much more.


A 1 MB hello world is just strange though, I'm sure that's some kind of bug, but the relatively harmless kind, you can still use it.
May 31, 2013
On Fri, 31 May 2013 15:33:46 +0100, khurshid <khurshid.normuradov@gmail.com> wrote:

> I just download dmd 2.063, and compile simple "hello world" program:
>
> // hello.d
> import std.stdio;
> int main()
> {
>      writeln("hello world");
>      return 0;
> }
>
>
> with -O -release -inline -noboundscheck  flags.
>
> And size of result output file  'hello'  equal to 1004.1 Kbyte !!!
> Why size is big?
>
>
> I'm using  fedora 14, 32-x.

Phobos the std library is statically linked, currently.  You will get a similar size (or greater) if you statically link the stdc library.  Eventually D will support dynamically linking to Phobos.

R

-- 
Using Opera's revolutionary email client: http://www.opera.com/mail/
May 31, 2013

On Friday, 31 May 2013 at 14:48:02 UTC, Adam D. Ruppe wrote:
> If you use printf instead of std.stdio, you'll save about 150 KB in the executable
>
> import core.stdc.stdio;
>
> void main() {
>         printf("hello\n");
> }
>
> $ dmd test2.d
> $ ls -lh test2
> -rwxr-xr-x 1 me users 287K 2013-05-31 10:40 test2
> $ strip test2
> $ ls -lh test2
> -rwxr-xr-x 1 me users 195K 2013-05-31 10:41 test2
>
I was try your code, result:

-rwxrwxr-x. 1 khurshid khurshid 299K May 31 19:53 hello

i.e. 299 Kbyte.


Even, when I type  dmd -v  :
DMD32 D Compiler v2.063
Copyright (c) 1999-2012 by Digital Mars written by Walter Bright
Documentation: http://dlang.org/
-----------------------------------------
Why copyright  2012 not a 2013?
May 31, 2013
On Friday, 31 May 2013 at 14:48:12 UTC, Regan Heath wrote:
> You  will get a similar size (or greater) if you statically link the stdc library.

That's not necessarily true because static linking only pulls functions that are actually used by the program....

even though I just tried gcc hello.c -static, and got a beefy 600 KB binary out of it, so maybe it is more intertwined than I thought!

> Eventually D will support dynamically linking to Phobos.

I think it is worth remembering that this doesn't actually reduce the size. In fact, it will increase it since the dynamic linked library needs all functions. The phobos.dll will be probably two or three megabytes, and if you are distributing a D app, you'll still have to offer that file... and now have the hassle of dependency management.

Dynamic linking might look less scary when your ls sees 20 KB instead of 600 but it doesn't really change anything substantial.
May 31, 2013
On Fri, 31 May 2013 16:00:00 +0100, Adam D. Ruppe <destructionator@gmail.com> wrote:
> On Friday, 31 May 2013 at 14:48:12 UTC, Regan Heath wrote:
>> You  will get a similar size (or greater) if you statically link the stdc library.
>
> That's not necessarily true because static linking only pulls functions that are actually used by the program....
>
> even though I just tried gcc hello.c -static, and got a beefy 600 KB binary out of it, so maybe it is more intertwined than I thought!

It is a bit surprising isn't it.

>> Eventually D will support dynamically linking to Phobos.
>
> I think it is worth remembering that this doesn't actually reduce the size. In fact, it will increase it since the dynamic linked library needs all functions. The phobos.dll will be probably two or three megabytes, and if you are distributing a D app, you'll still have to offer that file... and now have the hassle of dependency management.
>
> Dynamic linking might look less scary when your ls sees 20 KB instead of 600 but it doesn't really change anything substantial.

Agreed 100%.  But newcomers don't often get that far down the chain of thought, they just see a huge exe and wonder WTF! :)  The short answer is "it's statically linked" and the longer answer is.. as you say, there are pros/cons to each and we have issues in D around the GC and how that would work in a dynamically linked situation IIRC.

R

-- 
Using Opera's revolutionary email client: http://www.opera.com/mail/
May 31, 2013
On Friday, 31 May 2013 at 14:56:17 UTC, khurshid wrote:
> i.e. 299 Kbyte.

yeah it varies a bit by computer and 32 bit vs 64 bit etc, but same ballpark.

> Why copyright  2012 not a 2013?

Walter probably just forgot to update the message.
May 31, 2013
On Friday, 31 May 2013 at 15:03:58 UTC, Regan Heath wrote:
> It is a bit surprising isn't it.

Aye.

BTW if you want to get into really small, statically linked D programs, you can do a custom druntime, no phobos, no C lib, with just the code you want. I recently wrote about a toy I've been playing with the last couple days in a reddit comment:

http://www.reddit.com/r/programming/comments/1fc9jt/dmd_2063_the_d_programming_language_reference/ca94mek

Under 40 kilobytes! If you do the bare minimum you can get down to about 1 KB, but at that point, you're actually writing in mostly (inline) assembly rather than D. The code in the link though supports a majority (though certainly not all) of D's features.

> Agreed 100%.  But newcomers don't often get that far down the chain of thought, they just see a huge exe and wonder WTF! :)

Indeed.
May 31, 2013
>
> Under 40 kilobytes! If you do the bare minimum you can get down to about 1 KB, but at that point, you're actually writing in mostly (inline) assembly rather than D. The code in the link though supports a majority (though certainly not all) of D's features.
>
>> Agreed 100%.  But newcomers don't often get that far down the chain of thought, they just see a huge exe and wonder WTF! :)
>
> Indeed.

Do you really think that is such a big issue?  I can't remember
the last time I looked at the size of an executable I generated.
When I am trying to learn a new language it is really not
something I think of as a major issue.

However, I do scientific computing, and I am not distributing
most of the software I am developing.  If it runs fast and
doesn't fill up my terabyte hard drive - I will never notice.  So
I guess that makes me a little different than many posters on
this mailing list.

I would imagine there is fair segment on the programming
population who like me don't care too much about executable size.
  I suppose if you are developing software for embedded systems or
similar, then you probably watch for these things more.

Craig




May 31, 2013
I've seen this happen with 2.062, if you take out -noboundscheck it may reduce the size significantly and compile a lot faster. Makes no sense.

--rt
« First   ‹ Prev
1 2 3