digitalmars.D - hello world in D
- khurshid (15/15) May 31 2013 I just download dmd 2.063, and compile simple "hello world"
- Adam D. Ruppe (27/28) May 31 2013 Whoa, that's up like several times from the last dmd release....
- khurshid (10/22) May 31 2013 I was try your code, result:
- Adam D. Ruppe (4/6) May 31 2013 yeah it varies a bit by computer and 32 bit vs 64 bit etc, but
- Brad Anderson (2/9) May 31 2013 Fixed in git.
- Joseph Rushton Wakeling (3/7) May 31 2013 Is this not something where some clever CTFE could be used to swipe the ...
- Andrei Alexandrescu (3/10) May 31 2013 Yah, rdmd does that.
- Marco Leise (6/20) May 31 2013 A copyright year is not the date of compilation, but the date
- Regan Heath (8/20) May 31 2013 Phobos the std library is statically linked, currently. You will get a ...
- Adam D. Ruppe (14/17) May 31 2013 That's not necessarily true because static linking only pulls
- Regan Heath (11/26) May 31 2013 It is a bit surprising isn't it.
- Adam D. Ruppe (13/16) May 31 2013 Aye.
- Craig Dillabaugh (14/22) May 31 2013 Do you really think that is such a big issue? I can't remember
- Adam D. Ruppe (16/18) May 31 2013 There's three cases where I sometimes care:
- Regan Heath (8/19) May 31 2013 Not really an issue, no. But newcomers keep creating threads like this ...
- deadalnix (3/23) May 31 2013 A hello wold in java, statically compiled, was 52Mb last time I
- Paulo Pinto (8/32) Jun 01 2013 It is the same thing in the Go mailing list, new developers just aren't
- SomeDude (3/9) Jun 01 2013 Maybe it's a question that could be addressed through the wiki
- Marco Leise (14/31) May 31 2013 Fair enough. I've seen Haskell executables for small programs
- Rob T (4/4) May 31 2013 I've seen this happen with 2.062, if you take out -noboundscheck
- Jonathan M Davis (4/7) May 31 2013 My first guess would be that more ends up being inlined with -noboundsch...
- Rob T (10/20) May 31 2013 I discovered this last night while playing around with the
- Paulo Pinto (9/29) Jun 01 2013 dmd is not alone in this regard.
- Rob T (4/20) Jun 01 2013 Without -noboundscheck hello executable is only 340.6 kbyte.
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 KbyteWhoa, 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 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 test2I 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: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 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
On 05/31/2013 06:34 PM, Brad Anderson wrote:On Friday, 31 May 2013 at 14:56:17 UTC, khurshid wrote:Is this not something where some clever CTFE could be used to swipe the date of build and insert the correct year? :-PWhy copyright 2012 not a 2013?Fixed in git.
May 31 2013
On 5/31/13 12:48 PM, Joseph Rushton Wakeling wrote:On 05/31/2013 06:34 PM, Brad Anderson wrote:Yah, rdmd does that. AndreiOn Friday, 31 May 2013 at 14:56:17 UTC, khurshid wrote:Is this not something where some clever CTFE could be used to swipe the date of build and insert the correct year? :-PWhy copyright 2012 not a 2013?Fixed in git.
May 31 2013
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:A copyright year is not the date of compilation, but the date of last edit. Just saying. :) -- MarcoOn 05/31/2013 06:34 PM, Brad Anderson wrote:Yah, rdmd does that. AndreiOn Friday, 31 May 2013 at 14:56:17 UTC, khurshid wrote:Is this not something where some clever CTFE could be used to swipe the date of build and insert the correct year? :-PWhy copyright 2012 not a 2013?Fixed in git.
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: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:It is a bit surprising isn't it.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!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/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 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.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. CraigAgreed 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
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
On Fri, 31 May 2013 16:58:11 +0100, Craig Dillabaugh <cdillaba cg.scs.carleton.ca> wrote: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/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.Do you really think that is such a big issue?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
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:A hello wold in java, statically compiled, was 52Mb last time I tried.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. RUnder 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.Do you really think that is such a big issue?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
Am 31.05.2013 19:19, schrieb deadalnix:On Friday, 31 May 2013 at 16:31:42 UTC, Regan Heath wrote: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. -- PauloOn Fri, 31 May 2013 16:58:11 +0100, Craig Dillabaugh <cdillaba cg.scs.carleton.ca> wrote:A hello wold in java, statically compiled, was 52Mb last time I tried.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. RUnder 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.Do you really think that is such a big issue?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.
Jun 01 2013
On Friday, 31 May 2013 at 16:31:42 UTC, Regan Heath wrote:Maybe it's a question that could be addressed through the wiki then ?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
Jun 01 2013
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. CraigFair 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
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
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
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 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. --rtI'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
Am 31.05.2013 19:21, schrieb Rob T:On Friday, 31 May 2013 at 16:52:53 UTC, Jonathan M Davis wrote: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. -- PauloOn Friday, May 31, 2013 18:05:16 Rob T wrote: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. --rtI'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
Jun 01 2013
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