Programs in D are huge

Dennis dkorpel at
Tue Aug 16 08:49:31 UTC 2022

On Tuesday, 16 August 2022 at 08:25:18 UTC, Diego wrote:
> It seams huge in my opinion for an empty program
> What are the best practices to reduce the size?

The problem is that the druntime, the run time library needed to 
support many D features, is large and linked in its entirety by 
default. The linker could strip unused functions, but even in an 
empty program, a lot is done before `main` that pulls in most of 

- initializing floating point settings, signal handlers, stdout 
and stderr
- parsing --DRT command line options for configuring the Garbage 
- running module constructors / unit tests

There is a goal to make druntime more 'pay as you go' so these 
things only happen when they're needed, but progress is slow. In 
the mean time, if you can live without a lot of D features that 
require the runtime, you can use `-betterC`:

With the LDC2 compiler, you can use `--link-defaultlib-shared`, 
so your program dynamically links with the run time library. This 
doesn't help for a single D program, but multiple D programs can 
reuse a single shared library.

Finally, you could look at customized versions of the runtime, 
such as Light Weight D Runtime:

More information about the Digitalmars-d-learn mailing list