Thread overview
[Issue 11009] New: Regression (2.064 git-head): DMD consumes huge memory when it compiles enum containing many items
Sep 12, 2013
Andrej Mitrovic
September 11, 2013
http://d.puremagic.com/issues/show_bug.cgi?id=11009

           Summary: Regression (2.064 git-head): DMD consumes huge memory
                    when it compiles enum containing many items
           Product: D
           Version: D2
          Platform: x86_64
        OS/Version: Windows
            Status: NEW
          Keywords: ice
          Severity: regression
          Priority: P1
         Component: DMD
        AssignedTo: nobody@puremagic.com
        ReportedBy: kekeniro2@yahoo.co.jp


--- Comment #0 from kekeniro2@yahoo.co.jp 2013-09-11 02:14:31 PDT ---
DMD consumes over 1GB memory and runs slow when compiling the code below.
And it won't compile my project by out-of-memory.
I have just got it from git head.
This should be a recent regression.

CODE:
import std.conv;
void main() {
    Items t;
    t.to!string();
}

enum Items {
// 200 items contained
ID001,ID002,ID003,ID004,ID005,ID006,ID007,ID008,ID009,ID010,
ID011,ID012,ID013,ID014,ID015,ID016,ID017,ID018,ID019,ID020,
ID021,ID022,ID023,ID024,ID025,ID026,ID027,ID028,ID029,ID030,
ID031,ID032,ID033,ID034,ID035,ID036,ID037,ID038,ID039,ID040,
ID041,ID042,ID043,ID044,ID045,ID046,ID047,ID048,ID049,ID050,
ID051,ID052,ID053,ID054,ID055,ID056,ID057,ID058,ID059,ID060,
ID061,ID062,ID063,ID064,ID065,ID066,ID067,ID068,ID069,ID070,
ID071,ID072,ID073,ID074,ID075,ID076,ID077,ID078,ID079,ID080,
ID081,ID082,ID083,ID084,ID085,ID086,ID087,ID088,ID089,ID090,
ID091,ID092,ID093,ID094,ID095,ID096,ID097,ID098,ID099,ID100,
ID101,ID102,ID103,ID104,ID105,ID106,ID107,ID108,ID109,ID110,
ID111,ID112,ID113,ID114,ID115,ID116,ID117,ID118,ID119,ID120,
ID121,ID122,ID123,ID124,ID125,ID126,ID127,ID128,ID129,ID130,
ID131,ID132,ID133,ID134,ID135,ID136,ID137,ID138,ID139,ID140,
ID141,ID142,ID143,ID144,ID145,ID146,ID147,ID148,ID149,ID150,
ID151,ID152,ID153,ID154,ID155,ID156,ID157,ID158,ID159,ID160,
ID161,ID162,ID163,ID164,ID165,ID166,ID167,ID168,ID169,ID170,
ID171,ID172,ID173,ID174,ID175,ID176,ID177,ID178,ID179,ID180,
ID181,ID182,ID183,ID184,ID185,ID186,ID187,ID188,ID189,ID190,
ID191,ID192,ID193,ID194,ID195,ID196,ID197,ID198,ID199,ID200,
}

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
September 11, 2013
http://d.puremagic.com/issues/show_bug.cgi?id=11009


monarchdodra@gmail.com changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |monarchdodra@gmail.com


--- Comment #1 from monarchdodra@gmail.com 2013-09-11 02:20:44 PDT ---
This smells like https://github.com/D-Programming-Language/phobos/pull/1540

Could you try it without that change?

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
September 11, 2013
http://d.puremagic.com/issues/show_bug.cgi?id=11009


kekeniro2@yahoo.co.jp changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
          Component|DMD                         |Phobos


--- Comment #2 from kekeniro2@yahoo.co.jp 2013-09-11 02:45:06 PDT ---
(In reply to comment #1)
> This smells like https://github.com/D-Programming-Language/phobos/pull/1540
> 
> Could you try it without that change?

I tried it, and you are right.

Changed [Component] to Phobos.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
September 11, 2013
http://d.puremagic.com/issues/show_bug.cgi?id=11009


monarchdodra@gmail.com changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
          Component|Phobos                      |DMD


--- Comment #3 from monarchdodra@gmail.com 2013-09-11 03:25:53 PDT ---
(In reply to comment #2)
> (In reply to comment #1)
> > This smells like https://github.com/D-Programming-Language/phobos/pull/1540
> > 
> > Could you try it without that change?
> 
> I tried it, and you are right.

Cool.

I think I know what might be the culprit. May I request you try it with HEAD
again, but this time, replace:
line 829-832:
// generate a switch statement with string literals instead of allocating
memory
// @@@BUG@@@ 10950 workaround: [CTFE] enum "char[]" not correctly duplicated
when used.
enum rep(S val) = mixin(format(`"%s"%s`,
    toStr!string(val), charLiteralSuffix!(ElementEncodingType!T)));

With:
template rep(S val)
{
    static immutable(T) rep = toStr!(immutable(T))(val);
}

I have a hunch that should greatly improve the situation.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
September 11, 2013
http://d.puremagic.com/issues/show_bug.cgi?id=11009



--- Comment #4 from kekeniro2@yahoo.co.jp 2013-09-11 03:53:37 PDT ---
(In reply to comment #3)
> I think I know what might be the culprit. May I request you try it with HEAD
> again, but this time, replace:
> line 829-832:
> // generate a switch statement with string literals instead of allocating
> memory
> // @@@BUG@@@ 10950 workaround: [CTFE] enum "char[]" not correctly duplicated
> when used.
> enum rep(S val) = mixin(format(`"%s"%s`,
>     toStr!string(val), charLiteralSuffix!(ElementEncodingType!T)));
> 
> With:
> template rep(S val)
> {
>     static immutable(T) rep = toStr!(immutable(T))(val);
> }

I tried it, but you are wrong.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
September 11, 2013
http://d.puremagic.com/issues/show_bug.cgi?id=11009



--- Comment #5 from monarchdodra@gmail.com 2013-09-11 04:57:36 PDT ---
(In reply to comment #4)
> 
> I tried it, but you are wrong.

Ah. OK. Thanks.

I think I know what else is wrong, but I'll investigate myself.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
September 11, 2013
http://d.puremagic.com/issues/show_bug.cgi?id=11009



--- Comment #6 from monarchdodra@gmail.com 2013-09-11 05:28:48 PDT ---
(In reply to comment #5)
> (In reply to comment #4)
> > 
> > I tried it, but you are wrong.
> 
> Ah. OK. Thanks.
> 
> I think I know what else is wrong, but I'll investigate myself.

OK. I found out exactly what was wrong. I'll fix it ASAP.

Thanks for reporting, and sorry for the inconvenience.

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



--- Comment #7 from github-bugzilla@puremagic.com 2013-09-12 06:55:37 PDT ---
Commits pushed to master at https://github.com/D-Programming-Language/phobos

https://github.com/D-Programming-Language/phobos/commit/31afedbc5c21ed4eef864568c2e1c92a72a0c504
fix Issue 11009 - Regression (2.064 git-head): DMD consumes huge memory when it
compiles enum containing many items

This is a fixup of pull #1540.

Turns out NoDuplicates is scary inefficient for large input.

This cleans up and simplifies the pull somewhat.

https://github.com/D-Programming-Language/phobos/commit/cf882249701cf879f60ae4a5742c4d59937f932f Merge pull request #1565 from monarchdodra/fix11009

fix Issue 11009 - Regression (2.064 git-head): DMD consumes huge memory ...

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


Andrej Mitrovic <andrej.mitrovich@gmail.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|NEW                         |RESOLVED
         Resolution|                            |FIXED


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