What can be done to reduce executable size?
Jonathan M Davis
jmdavisProg at gmx.com
Fri Dec 16 01:49:33 PST 2011
On Friday, December 16, 2011 02:38:09 Andrei Alexandrescu wrote:
> On 12/16/11 1:12 AM, Jonathan M Davis wrote:
> > Simply making it so that std.file is only imported in std.stdio with
> > version(unittest) cut off _that_ much?
>
> Yah, but the matter is more complex. The issue is that std.file pulls
> std.datetime, which (a) has static this() code, and (b) pulls core.time,
> which in turn has static this() code.
>
> The issue with that is as follows. Any file that transitively imports a
> module with constructors will have its own module info generated. When
> that happens, all vtables in that module will be instantiated, so all
> methods will be linked in. That in turn causes all functions they call
> to also be linked in.
>
> That's why many programs using std are large.
>
> We can attack this in two ways:
>
> 1. Revise and reduce all static this() uses in phobos and druntime;
>
> 2. Improve the compiler to do minimal linking when static this() does
> come about.
Well, both std.datetime and core.time need static this() and can't not have
it. There may be other places in Phobos where module and class constructors
can be avoided or removed, but aside from unit tests, when they're used,
they're generally required. If some _can_ be removed though, that would be
great, since their presence also risks circular dependencies, which is a far
worse issue than the executable's size IMHO. But we can't get rid of them all.
Any work that can be done in the compiler to reduce the executable's size due
to static this would be great though.
- Jonathan M Davis
More information about the Digitalmars-d
mailing list