www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.learn - how to make D program footprint smaller ?

reply dangbinghoo <dangbinghoo gmail.com> writes:
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
Jul 08 2021
parent reply russhy <russhy gmail.com> writes:
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
Jul 08 2021
parent reply dangbinghoo <dangbinghoo gmail.com> writes:
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.
Jul 08 2021
parent reply dangbinghoo <dangbinghoo gmail.com> writes:
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!
Jul 08 2021
parent reply Bastiaan Veelo <Bastiaan Veelo.net> writes:
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](https://dlang.org/dmd-osx.html#switch-i%5B) 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.
Jul 10 2021
parent dangbinghoo <dangbinghoo gmail.com> writes:
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](https://dlang.org/dmd-osx.html#switch-i%5B) 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.
Jul 12 2021