www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 8828] New: Long compilation time of a destroy() on a large fixed-sized matrix

reply d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=8828

           Summary: Long compilation time of a destroy() on a large
                    fixed-sized matrix
           Product: D
           Version: D2
          Platform: x86
        OS/Version: Windows
            Status: NEW
          Severity: normal
          Priority: P2
         Component: DMD
        AssignedTo: nobody puremagic.com
        ReportedBy: bearophile_hugs eml.cc


--- Comment #0 from bearophile_hugs eml.cc 2012-10-15 19:07:14 PDT ---
Problem found by Damian on D.learn:
http://forum.dlang.org/thread/duzbdlfgtmqxtrztfpdi forum.dlang.org


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;

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Oct 15 2012
next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=8828


Marco Leise <Marco.Leise gmx.de> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |Marco.Leise gmx.de


--- Comment #1 from Marco Leise <Marco.Leise gmx.de> 2012-10-15 20:43:02 PDT ---
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 ?

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Oct 15 2012
prev sibling next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=8828



--- Comment #2 from bearophile_hugs eml.cc 2012-10-16 13:30:48 PDT ---
(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. -- Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email ------- You are receiving this mail because: -------
Oct 16 2012
prev sibling next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=8828



--- Comment #3 from github-bugzilla puremagic.com 2013-03-12 09:46:45 PDT ---
Commit pushed to master at https://github.com/D-Programming-Language/druntime

https://github.com/D-Programming-Language/druntime/commit/53480d9182efce9cd617eeaa207f6bd83c909ea1
Merge pull request #442 from damianday/patch-1

Fix issue 8828

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Mar 12 2013
prev sibling next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=8828


Martin Nowak <code dawg.eu> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|NEW                         |RESOLVED
                 CC|                            |code dawg.eu
         Resolution|                            |FIXED


--- Comment #4 from Martin Nowak <code dawg.eu> 2013-03-12 09:53:13 PDT ---
This particular bug has been partly fixed the real cause is Bug 2396.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Mar 12 2013
prev sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=8828


Damian <damianday hotmail.co.uk> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |damianday hotmail.co.uk


--- Comment #5 from Damian <damianday hotmail.co.uk> 2013-03-12 10:59:57 PDT ---
*** Issue 6771 has been marked as a duplicate of this issue. ***

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Mar 12 2013