Jump to page: 1 24  
Page
Thread overview
Generated binary size
Sep 13, 2013
Dicebot
Sep 13, 2013
Dicebot
Sep 13, 2013
Dicebot
Sep 13, 2013
Dicebot
Sep 13, 2013
Dicebot
Sep 13, 2013
Iain Buclaw
Sep 13, 2013
Iain Buclaw
Sep 13, 2013
Johannes Pfau
Sep 13, 2013
Johannes Pfau
Sep 13, 2013
Iain Buclaw
Sep 13, 2013
Iain Buclaw
Sep 15, 2013
Dicebot
Sep 15, 2013
Iain Buclaw
Sep 15, 2013
Dicebot
Sep 15, 2013
Iain Buclaw
Sep 15, 2013
Dicebot
Sep 15, 2013
Iain Buclaw
Sep 15, 2013
Dicebot
Sep 15, 2013
Iain Buclaw
Sep 15, 2013
Dicebot
Sep 15, 2013
Iain Buclaw
Sep 15, 2013
Iain Buclaw
Sep 15, 2013
Iain Buclaw
Sep 15, 2013
David Nadlinger
Sep 15, 2013
David Nadlinger
Sep 15, 2013
Iain Buclaw
Sep 13, 2013
Johannes Pfau
Sep 13, 2013
Dicebot
September 13, 2013
I was experimenting with `--gc-sections` effect on D code (with great results) and have noticed that GDC binaries are much bigger than DMD ones. I do understand that it is not a priority goal right now but still curious, does anyone know what makes such notable (~50%) difference?
(64-bit OS)

--------
import std.stdio, std.algorithm;

void main()
{
    auto arr = [ 1, 2, 3 ];
    writeln( arr.map!( a => a*2 )() );
}
--------
$ gdc -ofhello-gdc -O3 hello.d
$ dmd -ofhello-dmd -release -inline -O hello.d
$ ls -la
# ...
-rwxr-xr-x 1 dicebot users  819647 Sep 13 13:38 hello-dmd
-rwxr-xr-x 1 dicebot users 1386355 Sep 13 13:39 hello-gdc
-------
September 13, 2013
On 13/09/13 13:45, Dicebot wrote:
> I was experimenting with `--gc-sections` effect on D code (with great results)

Can you expand on this?  Never heard of it before and can't find it in gdc --help or manpages.
September 13, 2013
On Friday, 13 September 2013 at 11:58:53 UTC, Joseph Rushton Wakeling wrote:
> On 13/09/13 13:45, Dicebot wrote:
>> I was experimenting with `--gc-sections` effect on D code (with great results)
>
> Can you expand on this?  Never heard of it before and can't find it in gdc --help or manpages.

`--gc-sections` is ld flag that enabled garbage collection of unreferenced sections in resulting binary. For it to work gcc/gdc need to be run with `-fdata-sections`and `-ffunction-sections` placing each symbol into own section. That will, for example, remove template function bodies that got inlined for all calls. For template-heavy code with good inliner it can reduce binary sizes tremendously (running it on snippet from this topic will reduce gdc binary size to almost match dmd one).
September 13, 2013
Am Fri, 13 Sep 2013 13:45:58 +0200
schrieb "Dicebot" <public@dicebot.lv>:

> I was experimenting with `--gc-sections` effect on D code (with
> great results) and have noticed that GDC binaries are much bigger
> than DMD ones. I do understand that it is not a priority goal
> right now but still curious, does anyone know what makes such
> notable (~50%) difference?
> (64-bit OS)
> 
> --------
> import std.stdio, std.algorithm;
> 
> void main()
> {
>      auto arr = [ 1, 2, 3 ];
>      writeln( arr.map!( a => a*2 )() );
> }
> --------
> $ gdc -ofhello-gdc -O3 hello.d
> $ dmd -ofhello-dmd -release -inline -O hello.d
> $ ls -la
> # ...
> -rwxr-xr-x 1 dicebot users  819647 Sep 13 13:38 hello-dmd
> -rwxr-xr-x 1 dicebot users 1386355 Sep 13 13:39 hello-gdc
> -------

It seems like the gdc compiled program has more symbols for some reason:

----------
nm hello-dmd --defined-only | wc -l
3834
nm hello-gdc --defined-only | wc -l
5451
----------

Here's a "diff" of the defined symbols: https://gist.github.com/jpf91/6550247
September 13, 2013
On Friday, 13 September 2013 at 12:51:13 UTC, Johannes Pfau wrote:
> It seems like the gdc compiled program has more symbols for some
> reason:
>
> ----------
> nm hello-dmd --defined-only | wc -l
> 3834
> nm hello-gdc --defined-only | wc -l
> 5451
> ----------
>
> Here's a "diff" of the defined symbols:
> https://gist.github.com/jpf91/6550247

Yep and `--gc-sections` gets it down to:

```
$ nm hello-gdc --defined-only | wc -l
3894
```

I was curious though what kind of code gen optimization dmd uses here (as opposed to gdc) as simple experiments show that it does not remove unused template instances.
September 13, 2013
On 13/09/13 14:02, Dicebot wrote:
> `--gc-sections` is ld flag that enabled garbage collection of unreferenced
> sections in resulting binary. For it to work gcc/gdc need to be run with
> `-fdata-sections`and `-ffunction-sections` placing each symbol into own section.
> That will, for example, remove template function bodies that got inlined for all
> calls. For template-heavy code with good inliner it can reduce binary sizes
> tremendously (running it on snippet from this topic will reduce gdc binary size
> to almost match dmd one).

Ahh, OK.

Related query -- is there any way of telling the compiler (gdc/gdmd or preferably any of the D compilers) to strip out unused symbols/functions/data from the binary?

I have a module that includes a quite large array of immutable data (used for test purposes), but when this is compiled in with other code it adds about 10MB (!) to the executable size, even when the executable never uses it.  It'd be nice to be able to strip that out automatically rather than having to tweak the build script manually to leave out that module -- it's so much simpler to have the Makefile simply build using the whole library source. [*]

[* Yes, yes, I know, I should abandon Make and sort out a decent built system at long last ...]
September 13, 2013
On 13/09/13 15:14, Joseph Rushton Wakeling wrote:
> Related query -- is there any way of telling the compiler (gdc/gdmd or
> preferably any of the D compilers) to strip out unused symbols/functions/data
> from the binary?

I ask because I just tried compiling with the -fdata-sections and -ffunction-sections options enabled, and the binaries I got were still including that lovely 10MB bonus ... :-P

September 13, 2013
On Friday, 13 September 2013 at 13:14:49 UTC, Joseph Rushton Wakeling wrote:
> Ahh, OK.
>
> Related query -- is there any way of telling the compiler (gdc/gdmd or preferably any of the D compilers) to strip out unused symbols/functions/data from the binary?
>
> I have a module that includes a quite large array of immutable data (used for test purposes), but when this is compiled in with other code it adds about 10MB (!) to the executable size, even when the executable never uses it.

It is exactly what `gdc -fdata-sections -Xlinker --gc-sections app.d` will do.

Be careful though, if you use dynamic loading of shared libraries (or build your app as library) that may result in weird stuff when applied to all sources :)
September 13, 2013
On Friday, 13 September 2013 at 13:25:03 UTC, Dicebot wrote:
> It is exactly what `gdc -fdata-sections -Xlinker --gc-sections app.d` will do.
>
> Be careful though, if you use dynamic loading of shared libraries (or build your app as library) that may result in weird stuff when applied to all sources :)

On my machine:

-----
$ cat a.d
immutable long[100_000] arr = 1;

void main()
{
}
----
$ gdc -O3 a.d
$ ls -la
# ...
-rwxr-xr-x 1 dicebot users 1276934 Sep 13 15:21 a.out
----
$ gdc -O3 -fdata-sections a.d -Xlinker --gc-sections
$ ls -la
# ...
-rwxr-xr-x 1 dicebot users 434859 Sep 13 15:21 a.out
----
September 13, 2013
On 13/09/13 15:25, Dicebot wrote:
> On Friday, 13 September 2013 at 13:14:49 UTC, Joseph Rushton Wakeling wrote:
>> Related query -- is there any way of telling the compiler (gdc/gdmd or
>> preferably any of the D compilers) to strip out unused symbols/functions/data
>> from the binary?
>>
>> I have a module that includes a quite large array of immutable data (used for
>> test purposes), but when this is compiled in with other code it adds about
>> 10MB (!) to the executable size, even when the executable never uses it.
>
> It is exactly what `gdc -fdata-sections -Xlinker --gc-sections app.d` will do.

Tried it.  It reduces 12 MB executables to 11 MB -- but if I manually exclude the module responsible for the big data, executable sizes fall to 2 MB.
« First   ‹ Prev
1 2 3 4