Programs in D are huge

Steven Schveighoffer schveiguy at gmail.com
Tue Aug 16 11:48:02 UTC 2022


On 8/16/22 4:25 AM, Diego wrote:
> Hello everyone,
> 
> I'm a Java programmer at work but i'm learning D for pleasure. I'm 
> reading _The D Programming Language by Ali Çehreli_.
> 
> I noticed that DMD creates very huge executable, for example an empty 
> program:
> 
> ```
> empty.d:
> 
> void main() {
> 
> }
> ```
> 
> after a compilation with these flags `dmd -de -w empty.d` i have an 
> executable of 869KiB
> It seams huge in my opinion for an empty program
> 
> What are the best practices to reduce the size?

By default (but changing in some cases), D links the standard library in 
statically. This means that every D executable has a copy of the library 
(at least the used functions).

If you use C for a comparison, you have to include the C library size as 
well when comparing. On my system, libc is 2MB.

You can reduce size by using dynamic linking, but the drawback is that 
then you have to ensure the library exists on the target system in order 
to run.

If you are shipping a package with lots of D binaries it might make 
sense to do this, but for one-offs, probably not.

-Steve


More information about the Digitalmars-d-learn mailing list