Jump to page: 1 2
Thread overview
How to stop DMD from exploding the executable file size?
Aug 30, 2022
ryuukk_
Aug 30, 2022
ryuukk_
Sep 01, 2022
solidstate1991
Sep 01, 2022
H. S. Teoh
Sep 02, 2022
Bastiaan Veelo
Aug 30, 2022
H. S. Teoh
Aug 30, 2022
ryuukk_
Aug 31, 2022
H. S. Teoh
Sep 02, 2022
max haughton
Sep 03, 2022
ryuukk_
Sep 03, 2022
ryuukk_
Sep 03, 2022
H. S. Teoh
Sep 03, 2022
Don Allen
Sep 03, 2022
max haughton
Sep 05, 2022
ryuukk_
Sep 05, 2022
ryuukk_
Sep 08, 2022
wjoe
Sep 05, 2022
ryuukk_
August 30, 2022

Having this simple code makes the executable gigantic!

struct Big
{
    int[1024 * 1024] big = 0;
}

Big big;

Only with DMD, LDC produces a tiny executable

Is there a flag available to fix this behavior? it's not sustainable

August 30, 2022
$ ldc2 -m64 app.d
$ ll
total 4545
-rw-r--r-- 1 ryuukk 197121      69 Aug 31 00:57 app.d
-rwxr-xr-x 1 ryuukk 197121  453120 Aug 31 00:57 app.exe*
-rw-r--r-- 1 ryuukk 197121 4195865 Aug 31 00:57 app.obj
$ dmd -m64 app.d
$ ll
total 8617
-rw-r--r-- 1 ryuukk 197121      69 Aug 31 00:57 app.d
-rwxr-xr-x 1 ryuukk 197121 4623872 Aug 31 00:57 app.exe*
-rw-r--r-- 1 ryuukk 197121 4196322 Aug 31 00:57 app.obj
August 30, 2022
On Tue, Aug 30, 2022 at 10:51:46PM +0000, ryuukk_ via Digitalmars-d wrote:
> Having this simple code makes the executable gigantic!
> 
> ```D
> struct Big
> {
>     int[1024 * 1024] big = 0;
> }
> 
> Big big;
> ```
> 
> Only with DMD, LDC produces a tiny executable
> 
> Is there a flag available to fix this behavior? it's not sustainable

Which version of dmd are you using? I tried to compile the above code with 2.098 (old git master) and the total executable size is only 900KB.

I remember about a year or two ago there was a bug where dmd would generate 1024 * 1024 store instructions to initialize the array, but I just checked the disassembly, it's now a rep stos, which is very small.


T

-- 
Life is unfair. Ask too much from it, and it may decide you don't deserve what you have now either.
August 30, 2022
On Tuesday, 30 August 2022 at 23:05:16 UTC, H. S. Teoh wrote:
> On Tue, Aug 30, 2022 at 10:51:46PM +0000, ryuukk_ via Digitalmars-d wrote:
>> Having this simple code makes the executable gigantic!
>> 
>> ```D
>> struct Big
>> {
>>     int[1024 * 1024] big = 0;
>> }
>> 
>> Big big;
>> ```
>> 
>> Only with DMD, LDC produces a tiny executable
>> 
>> Is there a flag available to fix this behavior? it's not sustainable
>
> Which version of dmd are you using? I tried to compile the above code with 2.098 (old git master) and the total executable size is only 900KB.
>
> I remember about a year or two ago there was a bug where dmd would generate 1024 * 1024 store instructions to initialize the array, but I just checked the disassembly, it's now a rep stos, which is very small.
>
>
> T

dmd --version prints: `DMD32 D Compiler v2.100.1`

It's on Windows, maybe that problem is windows specific?
August 30, 2022
On Tue, Aug 30, 2022 at 11:09:55PM +0000, ryuukk_ via Digitalmars-d wrote:
> On Tuesday, 30 August 2022 at 23:05:16 UTC, H. S. Teoh wrote:
[...]
> > Which version of dmd are you using? I tried to compile the above code with 2.098 (old git master) and the total executable size is only 900KB.
> > 
> > I remember about a year or two ago there was a bug where dmd would generate 1024 * 1024 store instructions to initialize the array, but I just checked the disassembly, it's now a rep stos, which is very small.
[...]
> dmd --version prints: `DMD32 D Compiler v2.100.1`
> 
> It's on Windows, maybe that problem is windows specific?

Possibly, Windows uses a different backend path (obviously). Try to look at the disassembly to see if it's the abovementioned problem?


T

-- 
If blunt statements had a point, they wouldn't be blunt...
September 01, 2022

On Tuesday, 30 August 2022 at 22:58:44 UTC, ryuukk_ wrote:

>
$ ldc2 -m64 app.d
$ ll
total 4545
-rw-r--r-- 1 ryuukk 197121      69 Aug 31 00:57 app.d
-rwxr-xr-x 1 ryuukk 197121  453120 Aug 31 00:57 app.exe*
-rw-r--r-- 1 ryuukk 197121 4195865 Aug 31 00:57 app.obj
$ dmd -m64 app.d
$ ll
total 8617
-rw-r--r-- 1 ryuukk 197121      69 Aug 31 00:57 app.d
-rwxr-xr-x 1 ryuukk 197121 4623872 Aug 31 00:57 app.exe*
-rw-r--r-- 1 ryuukk 197121 4196322 Aug 31 00:57 app.obj

LDC has way better optimization features, so it's kinda expected.

September 01, 2022
On Thu, Sep 01, 2022 at 10:15:03PM +0000, solidstate1991 via Digitalmars-d wrote:
> On Tuesday, 30 August 2022 at 22:58:44 UTC, ryuukk_ wrote:
> > ```
> > $ ldc2 -m64 app.d
> > $ ll
> > total 4545
> > -rw-r--r-- 1 ryuukk 197121      69 Aug 31 00:57 app.d
> > -rwxr-xr-x 1 ryuukk 197121  453120 Aug 31 00:57 app.exe*
> > -rw-r--r-- 1 ryuukk 197121 4195865 Aug 31 00:57 app.obj
> > ```
> > 
> > ```
> > $ dmd -m64 app.d
> > $ ll
> > total 8617
> > -rw-r--r-- 1 ryuukk 197121      69 Aug 31 00:57 app.d
> > -rwxr-xr-x 1 ryuukk 197121 4623872 Aug 31 00:57 app.exe*
> > -rw-r--r-- 1 ryuukk 197121 4196322 Aug 31 00:57 app.obj
> > ```
> 
> LDC has way better optimization features, so it's kinda expected.

Yep.  LDC is my go-to compiler for release builds.  I use dmd for development because the turnaround time is faster, but I also don't care about performance/executable size when using dmd.  For release builds when I *do* care about those things, I use LDC; dmd isn't even on my radar for that.


T

-- 
Amateurs built the Ark; professionals built the Titanic.
September 02, 2022
On Thursday, 1 September 2022 at 22:31:50 UTC, H. S. Teoh wrote:
> On Thu, Sep 01, 2022 at 10:15:03PM +0000, solidstate1991 via Digitalmars-d wrote:
>> On Tuesday, 30 August 2022 at 22:58:44 UTC, ryuukk_ wrote:
>> > ```
>> > $ ldc2 -m64 app.d
>> > $ ll
>> > total 4545
>> > -rw-r--r-- 1 ryuukk 197121      69 Aug 31 00:57 app.d
>> > -rwxr-xr-x 1 ryuukk 197121  453120 Aug 31 00:57 app.exe*
>> > -rw-r--r-- 1 ryuukk 197121 4195865 Aug 31 00:57 app.obj
>> > ```
>> > 
>> > ```
>> > $ dmd -m64 app.d
>> > $ ll
>> > total 8617
>> > -rw-r--r-- 1 ryuukk 197121      69 Aug 31 00:57 app.d
>> > -rwxr-xr-x 1 ryuukk 197121 4623872 Aug 31 00:57 app.exe*
>> > -rw-r--r-- 1 ryuukk 197121 4196322 Aug 31 00:57 app.obj
>> > ```
>> 
>> LDC has way better optimization features, so it's kinda expected.
>
> Yep.  LDC is my go-to compiler for release builds.  I use dmd for development because the turnaround time is faster, but I also don't care about performance/executable size when using dmd.  For release builds when I *do* care about those things, I use LDC; dmd isn't even on my radar for that.
>
>
> T

LDC is great, but note that the object files are equally large for both compilers. Apparently it is the linker that should be attributed the size reduction. Which leads me to wonder what the main function looks like, because it might have removed the entire initialisation as dead code…

It would have been better if OP would have posted complete code.

— Bastiaan.
September 02, 2022

On Tuesday, 30 August 2022 at 22:51:46 UTC, ryuukk_ wrote:

>

Having this simple code makes the executable gigantic!

struct Big
{
    int[1024 * 1024] big = 0;
}

Big big;

Only with DMD, LDC produces a tiny executable

Is there a flag available to fix this behavior? it's not sustainable

You really shouldn't have structs this big unless absolutely necessary.

The thing being elided is the initializer and pointer bitmap for the runtime to use.

September 03, 2022

On Friday, 2 September 2022 at 17:53:51 UTC, max haughton wrote:

>

On Tuesday, 30 August 2022 at 22:51:46 UTC, ryuukk_ wrote:

>

Having this simple code makes the executable gigantic!

struct Big
{
    int[1024 * 1024] big = 0;
}

Big big;

Only with DMD, LDC produces a tiny executable

Is there a flag available to fix this behavior? it's not sustainable

You really shouldn't have structs this big unless absolutely necessary.

The thing being elided is the initializer and pointer bitmap for the runtime to use.

My use case should not makes us blind about the issue DMD is having

I tested with both C and Zig, and they both produce small executable

If DMD can do it on linux, there is no reason it can't do it on windows, if LDC can do it for both

I want to promote D, i can't promote D if i tell people "yeah but X, Y, Z, then you should go with X, when Z, and when stars are aligned, maybe"

It just feels bad; and the list of things that feels bad starts to stack up to a point it becomes sad

« First   ‹ Prev
1 2