Thread overview
how to make D program footprint smaller ?
Jul 08, 2021
dangbinghoo
Jul 08, 2021
russhy
Jul 09, 2021
dangbinghoo
Jul 09, 2021
dangbinghoo
Jul 10, 2021
Bastiaan Veelo
Jul 13, 2021
dangbinghoo
July 08, 2021

I have tried to add

  "dflags": ["--link-defaultlib-shared"],
  "lflags": ["--as-needed"],

to dub.json, and my compiler is ldc2, with 800 loc program used hibernated and asdf package. it compiled to 27MB binary not stripped and even 4MB size after stripped. (When compiled to ARM, the binary is 3.6MB which is a little bit smaller, but link flags won't opt. this either!)

I tried the link flags above, but it seems that the stripped binary is in some size.

any suggestions for optimizing this?

thanks!

dbh

July 08, 2021

On Thursday, 8 July 2021 at 10:01:33 UTC, dangbinghoo wrote:

>

I have tried to add

  "dflags": ["--link-defaultlib-shared"],
  "lflags": ["--as-needed"],

to dub.json, and my compiler is ldc2, with 800 loc program used hibernated and asdf package. it compiled to 27MB binary not stripped and even 4MB size after stripped. (When compiled to ARM, the binary is 3.6MB which is a little bit smaller, but link flags won't opt. this either!)

I tried the link flags above, but it seems that the stripped binary is in some size.

any suggestions for optimizing this?

thanks!

dbh

try:

"dflags-ldc": [
    "-linkonce-templates",
    "--Oz"
],

but yeah
Are you using lot of templates in your code? buffer as global?

my 20k LOC game's exe is only just 1.46mb (on windows), but that's because i don't use std at all

July 09, 2021

On Thursday, 8 July 2021 at 11:18:26 UTC, russhy wrote:

>

On Thursday, 8 July 2021 at 10:01:33 UTC, dangbinghoo wrote:

>

I have tried to add

  "dflags": ["--link-defaultlib-shared"],
  "lflags": ["--as-needed"],

to dub.json, and my compiler is ldc2, with 800 loc program used hibernated and asdf package. it compiled to 27MB binary not stripped and even 4MB size after stripped. (When compiled to ARM, the binary is 3.6MB which is a little bit smaller, but link flags won't opt. this either!)

I tried the link flags above, but it seems that the stripped binary is in some size.

any suggestions for optimizing this?

thanks!

dbh

try:

"dflags-ldc": [
    "-linkonce-templates",
    "--Oz"
],

but yeah
Are you using lot of templates in your code? buffer as global?

my 20k LOC game's exe is only just 1.46mb (on windows), but that's because i don't use std at all

thanks for your suggestion. I just tried that flags but it seems not working for me.

and I just use the nm tool with x86_64-pc-linux-gnu-gcc-nm --size-sort myprg to get all symbols in the binary, it showed up that. the executable linked with tons of vibe.d symbols.

the situation is that: my program relies on another source library which depends on vibe.d, the problem is that the source library is just a set of various tools, my program is using a little sub of that library, which has nothing imported with vibe.d.

BUT: the final program compiled with dub seems simply linked all symbols of the sourcelibrary to the executable.

So, it there any flags that opt. this like gcc? just to link only needed symbols?

thanks!

dbh.

July 09, 2021

On Friday, 9 July 2021 at 01:51:55 UTC, dangbinghoo wrote:

>

On Thursday, 8 July 2021 at 11:18:26 UTC, russhy wrote:

>

On Thursday, 8 July 2021 at 10:01:33 UTC, dangbinghoo wrote:

>

I have tried to add

  "dflags": ["--link-defaultlib-shared"],
  "lflags": ["--as-needed"],

to dub.json, and my compiler is ldc2, with 800 loc program used hibernated and asdf package. it compiled to 27MB binary not stripped and even 4MB size after stripped. (When compiled to ARM, the binary is 3.6MB which is a little bit smaller, but link flags won't opt. this either!)

I tried the link flags above, but it seems that the stripped binary is in some size.

any suggestions for optimizing this?

thanks!

dbh

try:

"dflags-ldc": [
    "-linkonce-templates",
    "--Oz"
],

but yeah
Are you using lot of templates in your code? buffer as global?

my 20k LOC game's exe is only just 1.46mb (on windows), but that's because i don't use std at all

thanks for your suggestion. I just tried that flags but it seems not working for me.

and I just use the nm tool with x86_64-pc-linux-gnu-gcc-nm --size-sort myprg to get all symbols in the binary, it showed up that. the executable linked with tons of vibe.d symbols.

the situation is that: my program relies on another source library which depends on vibe.d, the problem is that the source library is just a set of various tools, my program is using a little sub of that library, which has nothing imported with vibe.d.

BUT: the final program compiled with dub seems simply linked all symbols of the sourcelibrary to the executable.

So, it there any flags that opt. this like gcc? just to link only needed symbols?

thanks!

dbh.

I tried to delete the dependency of vibe.d and hibernated package(just an experiment, I finally need them in other process-executables). it shows up that deleting vibe.d decreases the size to 1.8MB (stripped) and deleting vibe.d and hibernated result-in a size of only 530KB(stripped), this is the size it should be.

I don't know this is related to dub or LDC itself, but obviously, THIS IS A REAL PROBLEM about D compiling.

as questioned in the previous thread, I need to find out something like --as-needed options available for D.

thanks!

July 10, 2021

On Friday, 9 July 2021 at 03:07:04 UTC, dangbinghoo wrote:

>

as questioned in the previous thread, I need to find out something like --as-needed options available for D.

You are probably looking for the -i compiler option. As far as I know dub is not devised to work with that, so making use of it can be finicky. I have managed to get it to work on a sourceLibrary that we control, not sure how applicable it is on a third party package.

— Bastiaan.

July 13, 2021

On Saturday, 10 July 2021 at 21:40:54 UTC, Bastiaan Veelo wrote:

>

On Friday, 9 July 2021 at 03:07:04 UTC, dangbinghoo wrote:

>

as questioned in the previous thread, I need to find out something like --as-needed options available for D.

You are probably looking for the -i compiler option. As far as I know dub is not devised to work with that, so making use of it can be finicky. I have managed to get it to work on a sourceLibrary that we control, not sure how applicable it is on a third party package.

— Bastiaan.

thanks! but I still think that THIS IS A REAL BUG with D compiling.

now, my solution will be remove rpc with vibe.d dependency and replace hibernated using json file storage.