www.digitalmars.com         C & C++   DMDScript  

digitalmars.D - hello world in D

reply "khurshid" <khurshid.normuradov gmail.com> writes:
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
next sibling parent reply "Adam D. Ruppe" <destructionator gmail.com> writes:
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
parent reply "khurshid" <khurshid.normuradov gmail.com> writes:
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
next sibling parent "Adam D. Ruppe" <destructionator gmail.com> writes:
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
prev sibling parent reply "Brad Anderson" <eco gnuk.net> writes:
On Friday, 31 May 2013 at 14:56:17 UTC, khurshid wrote:
 [snip]

 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?
Fixed in git.
May 31 2013
parent reply Joseph Rushton Wakeling <joseph.wakeling webdrake.net> writes:
On 05/31/2013 06:34 PM, Brad Anderson wrote:
 On Friday, 31 May 2013 at 14:56:17 UTC, khurshid wrote:
 Why copyright  2012 not a 2013?
Fixed in git.
Is this not something where some clever CTFE could be used to swipe the date of build and insert the correct year? :-P
May 31 2013
parent reply Andrei Alexandrescu <SeeWebsiteForEmail erdani.org> writes:
On 5/31/13 12:48 PM, Joseph Rushton Wakeling wrote:
 On 05/31/2013 06:34 PM, Brad Anderson wrote:
 On Friday, 31 May 2013 at 14:56:17 UTC, khurshid wrote:
 Why copyright  2012 not a 2013?
Fixed in git.
Is this not something where some clever CTFE could be used to swipe the date of build and insert the correct year? :-P
Yah, rdmd does that. Andrei
May 31 2013
parent Marco Leise <Marco.Leise gmx.de> writes:
Am Fri, 31 May 2013 13:14:48 -0400
schrieb Andrei Alexandrescu <SeeWebsiteForEmail erdani.org>:

 On 5/31/13 12:48 PM, Joseph Rushton Wakeling wrote:
 On 05/31/2013 06:34 PM, Brad Anderson wrote:
 On Friday, 31 May 2013 at 14:56:17 UTC, khurshid wrote:
 Why copyright  2012 not a 2013?
Fixed in git.
Is this not something where some clever CTFE could be used to swipe the date of build and insert the correct year? :-P
Yah, rdmd does that. Andrei
A copyright year is not the date of compilation, but the date of last edit. Just saying. :) -- Marco
May 31 2013
prev sibling next sibling parent reply "Regan Heath" <regan netmail.co.nz> writes:
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
parent reply "Adam D. Ruppe" <destructionator gmail.com> writes:
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
parent reply "Regan Heath" <regan netmail.co.nz> writes:
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
parent reply "Adam D. Ruppe" <destructionator gmail.com> writes:
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
parent reply "Craig Dillabaugh" <cdillaba cg.scs.carleton.ca> writes:
 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
next sibling parent "Adam D. Ruppe" <destructionator gmail.com> writes:
On Friday, 31 May 2013 at 15:58:12 UTC, Craig Dillabaugh wrote:
 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.
There's three cases where I sometimes care: 1) if I build the program on my computer, then push it to a test/live server over a slow internet link. It is edit/run/debug but with a sloooooow wait in the middle for the file to transfer. 2) I make little programs and send people Windows binaries over my (kinda slow) home internet sometimes. So upload speed again, especially if they play with it, send me comments, and I want to send them a new version to try. 3) wanting minimism for its own sake :) Using dlls can sometimes help, but the initial download is still slow and it is a pain to have users manage that stuff, I prefer to say "here's a .zip, just unzip it and run the program" so smaller total package is a nice benefit. That said though 95% of the time, a few megabytes isn't a big deal.
May 31 2013
prev sibling next sibling parent reply "Regan Heath" <regan netmail.co.nz> writes:
On Fri, 31 May 2013 16:58:11 +0100, Craig Dillabaugh  
<cdillaba cg.scs.carleton.ca> wrote:

 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?
Not really an issue, no. But newcomers keep creating threads like this one time and again and who knows how many have been turned away without finding out the whys and wherefores. R -- Using Opera's revolutionary email client: http://www.opera.com/mail/
May 31 2013
next sibling parent reply "deadalnix" <deadalnix gmail.com> writes:
On Friday, 31 May 2013 at 16:31:42 UTC, Regan Heath wrote:
 On Fri, 31 May 2013 16:58:11 +0100, Craig Dillabaugh 
 <cdillaba cg.scs.carleton.ca> wrote:

 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?
Not really an issue, no. But newcomers keep creating threads like this one time and again and who knows how many have been turned away without finding out the whys and wherefores. R
A hello wold in java, statically compiled, was 52Mb last time I tried.
May 31 2013
parent Paulo Pinto <pjmlp progtools.org> writes:
Am 31.05.2013 19:19, schrieb deadalnix:
 On Friday, 31 May 2013 at 16:31:42 UTC, Regan Heath wrote:
 On Fri, 31 May 2013 16:58:11 +0100, Craig Dillabaugh
 <cdillaba cg.scs.carleton.ca> wrote:

 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?
Not really an issue, no. But newcomers keep creating threads like this one time and again and who knows how many have been turned away without finding out the whys and wherefores. R
A hello wold in java, statically compiled, was 52Mb last time I tried.
It is the same thing in the Go mailing list, new developers just aren't used to static binaries. Additionally when they look at the size of modern languages, which tend to have JIT based canonical implementations, the size of the already installed runtime tends to be forgotten. -- Paulo
Jun 01 2013
prev sibling parent "SomeDude" <lovelydear mailmetrash.com> writes:
On Friday, 31 May 2013 at 16:31:42 UTC, Regan Heath wrote:

 Do you really think that is such a big issue?
Not really an issue, no. But newcomers keep creating threads like this one time and again and who knows how many have been turned away without finding out the whys and wherefores. R
Maybe it's a question that could be addressed through the wiki then ?
Jun 01 2013
prev sibling parent Marco Leise <Marco.Leise gmx.de> writes:
Am Fri, 31 May 2013 17:58:11 +0200
schrieb "Craig Dillabaugh" <cdillaba cg.scs.carleton.ca>:

 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
Fair enough. I've seen Haskell executables for small programs of about 10 MB. But don't forget that D is used in many areas and if for a moment you imagine Unix being written in D with static linking and your standard set of tools like ls, grep, cat, ... would all be 600-1000 KiB, it would certainly increase boot times, disk cache thrashing and program loading times in general despite being just too much for some minimal devices. D can do better. There are low hanging fruit like: http://d.puremagic.com/issues/show_bug.cgi?id=7319 -- Marco
May 31 2013
prev sibling next sibling parent reply "Rob T" <alanb ucora.com> writes:
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
May 31 2013
parent reply "Jonathan M Davis" <jmdavisProg gmx.com> writes:
On Friday, May 31, 2013 18:05:16 Rob T wrote:
 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.
My first guess would be that more ends up being inlined with -noboundscheck due to the differences in the code that's being generated, but I really don't knw. - Jonathan M Davis
May 31 2013
parent reply "Rob T" <alanb ucora.com> writes:
On Friday, 31 May 2013 at 16:52:53 UTC, Jonathan M Davis wrote:
 On Friday, May 31, 2013 18:05:16 Rob T wrote:
 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.
My first guess would be that more ends up being inlined with -noboundscheck due to the differences in the code that's being generated, but I really don't knw. - Jonathan M Davis
I discovered this last night while playing around with the raytrace performance issue a few threads back. I noticed that Derelict was being built without -noboundscheck so I put the flag in to see what if anything would happen. The difference is from a few kilobytes per lib to a few megabytes per lib, so it's a drastic increase and it takes a lot more time to build. This may be something that should be investigated further. --rt
May 31 2013
parent Paulo Pinto <pjmlp progtools.org> writes:
Am 31.05.2013 19:21, schrieb Rob T:
 On Friday, 31 May 2013 at 16:52:53 UTC, Jonathan M Davis wrote:
 On Friday, May 31, 2013 18:05:16 Rob T wrote:
 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.
My first guess would be that more ends up being inlined with -noboundscheck due to the differences in the code that's being generated, but I really don't knw. - Jonathan M Davis
I discovered this last night while playing around with the raytrace performance issue a few threads back. I noticed that Derelict was being built without -noboundscheck so I put the flag in to see what if anything would happen. The difference is from a few kilobytes per lib to a few megabytes per lib, so it's a drastic increase and it takes a lot more time to build. This may be something that should be investigated further. --rt
dmd is not alone in this regard. There is a presentation from Chandler Carruth on the last LLVM conference, http://llvm.org/devmtg/2013-04/ where he rants about that in C++ code. Basically there are some use cases in C++ where the optimizer currently does the wrong thing and the generated code increases exponentially. -- Paulo
Jun 01 2013
prev sibling parent "Rob T" <alanb ucora.com> writes:
On Friday, 31 May 2013 at 14:33:48 UTC, khurshid 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.


 Regards,
  Khurshid.
Without -noboundscheck hello executable is only 340.6 kbyte. Compiled using dmd 2.062 on Debian 6. --rt
Jun 01 2013