Bug 8828 – Long compilation time of a destroy() on a large fixed-sized matrix
Status
RESOLVED
Resolution
FIXED
Severity
normal
Priority
P2
Component
dmd
Product
D
Version
D2
Platform
x86
OS
Windows
Creation time
2012-10-15T19:07:00Z
Last change time
2013-03-12T10:59:57Z
Assigned to
nobody
Creator
bearophile_hugs
Comments
Comment #0 by bearophile_hugs — 2012-10-15T19:07:14Z
Problem found by Damian on D.learn:
http://forum.dlang.org/thread/[email protected]
This program takes a lot of time to compile:
void main() {
int[500][500] arr;
destroy(arr);
}
It generates an assembly like:
mov EAX,offset FLAT:_D13TypeInfo_G50i6__initZ
push EAX
call near ptr __d_arrayliteralTX
mov [EAX],EBX
mov 4[EAX],EBX
mov 8[EAX],EBX
mov 0Ch[EAX],EBX
mov 010h[EAX],EBX
mov 014h[EAX],EBX
mov 018h[EAX],EBX
mov 01Ch[EAX],EBX
mov 020h[EAX],EBX
mov 024h[EAX],EBX
mov 028h[EAX],EBX
mov 02Ch[EAX],EBX
mov 030h[EAX],EBX
mov 034h[EAX],EBX
mov 038h[EAX],EBX
mov 03Ch[EAX],EBX
mov 040h[EAX],EBX
mov 044h[EAX],EBX
mov 048h[EAX],EBX
mov 04Ch[EAX],EBX
mov 050h[EAX],EBX
mov 054h[EAX],EBX
mov 058h[EAX],EBX
mov 05Ch[EAX],EBX
mov 060h[EAX],EBX
mov 064h[EAX],EBX
mov 068h[EAX],EBX
mov 06Ch[EAX],EBX
mov 070h[EAX],EBX
mov 074h[EAX],EBX
mov 078h[EAX],EBX
mov 07Ch[EAX],EBX
mov 080h[EAX],EBX
mov 084h[EAX],EBX
mov 088h[EAX],EBX
mov 08Ch[EAX],EBX
mov 090h[EAX],EBX
mov 094h[EAX],EBX
mov 098h[EAX],EBX
mov 09Ch[EAX],EBX
mov 0A0h[EAX],EBX
mov 0A4h[EAX],EBX
mov 0A8h[EAX],EBX
mov 0ACh[EAX],EBX
mov 0B0h[EAX],EBX
mov 0B4h[EAX],EBX
mov 0B8h[EAX],EBX
...
I don't think that's good for a large 2D fixed-sized matrix.
Workaround: use something like:
foreach (ref row; arr)
row[] = typeof(row[0]).init;
Comment #1 by Marco.Leise — 2012-10-15T20:43:02Z
Nice bug. Is the program behaving correctly otherwise ? Are the mov's from the destroy() call or are they trying to initialize a couple of ints on the stack to 0 ?
Comment #2 by bearophile_hugs — 2012-10-16T13:30:48Z
(In reply to comment #1)
> Is the program behaving correctly otherwise ?
The program seems to work correctly.
> Are the mov's from the destroy() call or
This is the main:
__Dmain comdat
L0: push EBP
mov EBP,ESP
mov EDX,9
L8: sub ESP,01000h
test [ESP],ESP
dec EDX
jne L8
sub ESP,0C40h
push EDI
mov ECX,02710h
xor EAX,EAX
lea EDI,-09C40h[EBP]
rep
stosd
lea EAX,-09C40h[EBP]
call near ptr _D6object31__T5clearTG100G100iTG100iVk100Z5clearFKG100G100iZv
xor EAX,EAX
pop EDI
leave
ret
The movs are inside the _D6object31__T5clear[...].
> are they trying to initialize a couple of ints on the stack to 0 ?
They seem to initialize a matrix literal.
Comment #3 by github-bugzilla — 2013-03-12T09:46:45Z