December 14, 2011 Re: What can be done to reduce executable size? | ||||
---|---|---|---|---|
| ||||
Posted in reply to Bane | On 10.12.2011 16:39, Bane wrote:
> Short term and long term suggestions ? Anything we can do ? I heard it is some problem with linking dead code?
I don't know about D2, but for D1 it helps to recompile Phobos without -lib (use lib.exe, see win32.mak).
Hello.d - 84k
I'm attaching my makefiles, the smaller one belongs to phobos/internal/gc
Martin
|
December 14, 2011 Re: What can be done to reduce executable size? | ||||
---|---|---|---|---|
| ||||
Posted in reply to Martin Krejcirik | Martin Krejcirik:
> I don't know about D2, but for D1 it helps to recompile Phobos without -lib (use lib.exe, see win32.mak).
What are the effects/disadvantages of doing this?
Bye,
bearophile
|
December 14, 2011 Re: What can be done to reduce executable size? | ||||
---|---|---|---|---|
| ||||
Posted in reply to bearophile | On 2011-12-14 12:47, bearophile wrote: > Martin Krejcirik: > >> I don't know about D2, but for D1 it helps to recompile Phobos without >> -lib (use lib.exe, see win32.mak). > > What are the effects/disadvantages of doing this? > > Bye, > bearophile You need to explicitly invoke the tool that creates libraries on the given system (ar on Posix, lib on Windows) making it platform dependent. -- /Jacob Carlborg |
December 16, 2011 Re: What can be done to reduce executable size? | ||||
---|---|---|---|---|
| ||||
Posted in reply to Bane | On 12/10/11 9:39 AM, Bane wrote: > Short term and long term suggestions ? Anything we can do ? I heard it > is some problem with linking dead code? > > > > import std.stdio; > int main(){ > writefln("Hello Bloat!"); > return 0; > } > > dmd -release -O hello.d > > On Windows: > v1.071 = 339 Kb > v2.056 = 1017 Kb > > It looks very ugly and might distract some people. In fact there was a low-hanging fruit, and I'm sure there are some more. This diff reduces the size of hello, world (compiled with -O -release -inline and after strip) from 700KB to 220 KB: https://github.com/D-Programming-Language/phobos/commit/b7f42ec925fb1d64564d48ea419e201bfc65ed53 Right now an executable starts at around 218KB, which includes druntime (gc, type info, the works). Importing std.stdio and using writeln() only adds a couple of KBs. Andrei |
December 16, 2011 Re: What can be done to reduce executable size? | ||||
---|---|---|---|---|
| ||||
Posted in reply to Andrei Alexandrescu | On Thursday, December 15, 2011 21:40:57 Andrei Alexandrescu wrote:
> On 12/10/11 9:39 AM, Bane wrote:
> > Short term and long term suggestions ? Anything we can do ? I heard it is some problem with linking dead code?
> >
> >
> >
> > import std.stdio;
> > int main(){
> > writefln("Hello Bloat!");
> > return 0;
> > }
> >
> > dmd -release -O hello.d
> >
> > On Windows:
> > v1.071 = 339 Kb
> > v2.056 = 1017 Kb
> >
> > It looks very ugly and might distract some people.
>
> In fact there was a low-hanging fruit, and I'm sure there are some more. This diff reduces the size of hello, world (compiled with -O -release -inline and after strip) from 700KB to 220 KB:
>
> https://github.com/D-Programming-Language/phobos/commit/b7f42ec925fb1d64564d 48ea419e201bfc65ed53
>
> Right now an executable starts at around 218KB, which includes druntime
> (gc, type info, the works). Importing std.stdio and using writeln() only
> adds a couple of KBs.
Simply making it so that std.file is only imported in std.stdio with version(unittest) cut off _that_ much?
- Jonathan M Davis
|
December 16, 2011 Re: What can be done to reduce executable size? | ||||
---|---|---|---|---|
| ||||
Posted in reply to Jonathan M Davis | 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.
Andrei
|
December 16, 2011 Re: What can be done to reduce executable size? | ||||
---|---|---|---|---|
| ||||
Posted in reply to Andrei Alexandrescu | Andrei Alexandrescu:
> Right now an executable starts at around 218KB, which includes druntime (gc, type info, the works). Importing std.stdio and using writeln() only adds a couple of KBs.
Now using ulink the hello world exe becomes 129_564 bytes.
Bye,
bearophile
|
December 16, 2011 Re: What can be done to reduce executable size? | ||||
---|---|---|---|---|
| ||||
Posted in reply to Andrei Alexandrescu | 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
|
December 16, 2011 Re: What can be done to reduce executable size? | ||||
---|---|---|---|---|
| ||||
Posted in reply to bearophile | Am 16.12.2011, 10:15 Uhr, schrieb bearophile <bearophileHUGS@lycos.com>:
> Andrei Alexandrescu:
>
>> Right now an executable starts at around 218KB, which includes druntime
>> (gc, type info, the works). Importing std.stdio and using writeln() only
>> adds a couple of KBs.
>
> Now using ulink the hello world exe becomes 129_564 bytes.
What is its secret?
|
December 16, 2011 Re: What can be done to reduce executable size? | ||||
---|---|---|---|---|
| ||||
Posted in reply to Trass3r | Am 16.12.2011, 14:52 Uhr, schrieb Trass3r <un@known.com>:
> Am 16.12.2011, 10:15 Uhr, schrieb bearophile <bearophileHUGS@lycos.com>:
>
>> Andrei Alexandrescu:
>>
>>> Right now an executable starts at around 218KB, which includes druntime
>>> (gc, type info, the works). Importing std.stdio and using writeln() only
>>> adds a couple of KBs.
>>
>> Now using ulink the hello world exe becomes 129_564 bytes.
>
> What is its secret?
Didn't it also compress the exe?
|
Copyright © 1999-2021 by the D Language Foundation