[Issue 2356] array literal as non static initializer generates horribly inefficient code.
https://issues.dlang.org/show_bug.cgi?id=2356 Andrei Alexandrescu and...@erdani.com changed: What|Removed |Added Version|D1 D2 |D2 --
[Issue 2356] array literal as non static initializer generates horribly inefficient code.
http://d.puremagic.com/issues/show_bug.cgi?id=2356 --- Comment #23 from Denis Shelomovskij verylonglogin@gmail.com 2013-10-25 00:45:30 MSD --- (In reply to comment #22) Also some duplicates of current issue and duplicates of duplicates of current issue are now really duplicates of Issue 11345. Looks like Issue 4881 was the only one. Changed its DUPLICATE of. -- Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email --- You are receiving this mail because: ---
[Issue 2356] array literal as non static initializer generates horribly inefficient code.
http://d.puremagic.com/issues/show_bug.cgi?id=2356 Benjamin Thaut c...@benjamin-thaut.de changed: What|Removed |Added CC||c...@benjamin-thaut.de --- Comment #21 from Benjamin Thaut c...@benjamin-thaut.de 2013-06-06 00:04:57 PDT --- Awesome, thanks for fixing this. This was my number 1 most annoying bug in D. Because when not using a GC the old behavior always leaked memory. -- Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email --- You are receiving this mail because: ---
[Issue 2356] array literal as non static initializer generates horribly inefficient code.
http://d.puremagic.com/issues/show_bug.cgi?id=2356 --- Comment #18 from github-bugzi...@puremagic.com 2013-04-11 01:36:48 PDT --- Commits pushed to master at https://github.com/D-Programming-Language/dmd https://github.com/D-Programming-Language/dmd/commit/8cd5f790a78e7514e46618d0325e92cbd6e00e48 fix Issue 2356 - array literal as non static initializer generates horribly inefficient code. https://github.com/D-Programming-Language/dmd/commit/d4b20baee7a1c9ee8a9271724feb5d1031e773d4 Merge pull request #1883 from 9rnsr/fix2356 Issue 2356 - array literal as non static initializer generates horribly inefficient code. -- Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email --- You are receiving this mail because: ---
[Issue 2356] array literal as non static initializer generates horribly inefficient code.
http://d.puremagic.com/issues/show_bug.cgi?id=2356 --- Comment #19 from bearophile_h...@eml.cc 2013-04-11 05:26:29 PDT --- The patch seems to work. With it I have removed five optimizations from my code. Very good. -- Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email --- You are receiving this mail because: ---
[Issue 2356] array literal as non static initializer generates horribly inefficient code.
http://d.puremagic.com/issues/show_bug.cgi?id=2356 Andrei Alexandrescu and...@erdani.com changed: What|Removed |Added Status|NEW |RESOLVED CC||and...@erdani.com Resolution||FIXED --- Comment #20 from Andrei Alexandrescu and...@erdani.com 2013-04-11 06:12:47 PDT --- Thanks, Kenji! -- Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email --- You are receiving this mail because: ---
[Issue 2356] array literal as non static initializer generates horribly inefficient code.
http://d.puremagic.com/issues/show_bug.cgi?id=2356 Kenji Hara k.hara...@gmail.com changed: What|Removed |Added Keywords||pull --- Comment #14 from Kenji Hara k.hara...@gmail.com 2013-04-10 10:31:22 PDT --- New D2 fix: https://github.com/D-Programming-Language/dmd/pull/1883 -- Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email --- You are receiving this mail because: ---
[Issue 2356] array literal as non static initializer generates horribly inefficient code.
http://d.puremagic.com/issues/show_bug.cgi?id=2356 --- Comment #15 from bearophile_h...@eml.cc 2013-04-10 19:20:51 PDT --- (In reply to comment #14) New D2 fix: https://github.com/D-Programming-Language/dmd/pull/1883 From the pull request (dmd -O -inline -g test after): c:\d\test.d:18 int[3] y = [n, n, n]; 004020aa: 6a03push 0x3 004020ac: 6a05push 0x5 004020ae: 8d4c241clea ecx, [esp+0x1c] 004020b2: 51 push ecx 004020b3: e88002 call 0x402338 __memset32 Isn't calling memset for just 3 integers slower than inlining their assignments? I suggest to not call memset if the number of bytes to be copied is so small (I think LDC is already doing similar optimizations). Maybe a benchmark is also useful here. c:\d\test.d:20 S[3] z = [s2, s2, s2]; 004020b8: 8d542418lea edx, [esp+0x18] 004020bc: 52 push edx 004020bd: 8d442430lea eax, [esp+0x30] 004020c1: e86aff call 0x402030 test.S.__cpctor c:\d\test.d:3 004020c6: 8d5c2418lea ebx, [esp+0x18] 004020ca: 53 push ebx 004020cb: 8d442434lea eax, [esp+0x34] 004020cf: e85cff call 0x402030 test.S.__cpctor c:\d\test.d:3 004020d4: 53 push ebx 004020d5: 8d442438lea eax, [esp+0x38] 004020d9: e852ff call 0x402030 test.S.__cpctor c:\d\test.d:3 004020de: 83c40c add esp, 0xc 004020e1: 31c0xor eax, eax If the s2 variable already contains the struct, then what's the purpose of those calls to 0x402030? In the before there are no calls to struct constructors: c:\d\test.d:20 S[3] z = [s2, s2, s2]; 00403913: 8d542474lea edx, [esp+0x74] 00403917: b960014200 mov ecx, 0x420160 0040391c: 52 push edx 0040391d: 6a03push 0x3 0040391f: 6a03push 0x3 00403921: 51 push ecx 00403922: e8fd0a call 0x404424 __d_arrayliteralTX 00403927: 83c408 add esp, 0x8 0040392a: 8d542470lea edx, [esp+0x70] 0040392e: 52 push edx 0040392f: 89c6mov esi, eax -- Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email --- You are receiving this mail because: ---
[Issue 2356] array literal as non static initializer generates horribly inefficient code.
http://d.puremagic.com/issues/show_bug.cgi?id=2356 --- Comment #16 from Kenji Hara k.hara...@gmail.com 2013-04-10 19:34:08 PDT --- (In reply to comment #15) (In reply to comment #14) New D2 fix: https://github.com/D-Programming-Language/dmd/pull/1883 From the pull request (dmd -O -inline -g test after): c:\d\test.d:18 int[3] y = [n, n, n]; 004020aa: 6a03push 0x3 004020ac: 6a05push 0x5 004020ae: 8d4c241clea ecx, [esp+0x1c] 004020b2: 51 push ecx 004020b3: e88002 call 0x402338 __memset32 Isn't calling memset for just 3 integers slower than inlining their assignments? I suggest to not call memset if the number of bytes to be copied is so small (I think LDC is already doing similar optimizations). Maybe a benchmark is also useful here. It is lowered to: int[3] y = void; y[] = n; And currently dmd uses memset for `y[] = n;`. It is another optimization issue. c:\d\test.d:20 S[3] z = [s2, s2, s2]; 004020b8: 8d542418lea edx, [esp+0x18] 004020bc: 52 push edx 004020bd: 8d442430lea eax, [esp+0x30] 004020c1: e86aff call 0x402030 test.S.__cpctor c:\d\test.d:3 004020c6: 8d5c2418lea ebx, [esp+0x18] 004020ca: 53 push ebx 004020cb: 8d442434lea eax, [esp+0x34] 004020cf: e85cff call 0x402030 test.S.__cpctor c:\d\test.d:3 004020d4: 53 push ebx 004020d5: 8d442438lea eax, [esp+0x38] 004020d9: e852ff call 0x402030 test.S.__cpctor c:\d\test.d:3 004020de: 83c40c add esp, 0xc 004020e1: 31c0xor eax, eax If the s2 variable already contains the struct, then what's the purpose of those calls to 0x402030? In the before there are no calls to struct constructors: c:\d\test.d:20 S[3] z = [s2, s2, s2]; 00403913: 8d542474lea edx, [esp+0x74] 00403917: b960014200 mov ecx, 0x420160 0040391c: 52 push edx 0040391d: 6a03push 0x3 0040391f: 6a03push 0x3 00403921: 51 push ecx 00403922: e8fd0a call 0x404424 __d_arrayliteralTX 00403927: 83c408 add esp, 0x8 0040392a: 8d542470lea edx, [esp+0x70] 0040392e: 52 push edx 0040392f: 89c6mov esi, eax Before, cpctor(==postblit) calls are done in __d_arrayliteralTX, so they are hidden. Now they are directly called on the stack memory z[0..3]. -- Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email --- You are receiving this mail because: ---
[Issue 2356] array literal as non static initializer generates horribly inefficient code.
http://d.puremagic.com/issues/show_bug.cgi?id=2356 --- Comment #17 from bearophile_h...@eml.cc 2013-04-10 19:44:37 PDT --- (In reply to comment #16) It is lowered to: int[3] y = void; y[] = n; And currently dmd uses memset for `y[] = n;`. It is another optimization issue. OK. Before, cpctor(==postblit) calls are done in __d_arrayliteralTX, so they are hidden. Now they are directly called on the stack memory z[0..3]. Sorry I have missed it was the postblit, thank you. -- Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email --- You are receiving this mail because: ---
[Issue 2356] array literal as non static initializer generates horribly inefficient code.
http://d.puremagic.com/issues/show_bug.cgi?id=2356 Denis Shelomovskij verylonglogin@gmail.com changed: What|Removed |Added CC||verylonglogin@gmail.com --- Comment #13 from Denis Shelomovskij verylonglogin@gmail.com 2012-10-30 17:17:29 MSK --- Workaround for those who like a, b, c initialization but need more performance (not: it still calls `_d_arraycopy`): --- T[n] makeStaticArray(T, size_t n)(T[n] data...) // { return data; } { T[n] res; res = data; return res; } // Issue 8914 workaround void setStaticArray(T, size_t n)(ref T[n] array, T[n] data...) { array = data; } void main() { auto x = makeStaticArray(1, 2, 3); static assert(is(typeof(x) == int[3])); assert(x == [1, 2, 3]); int[3] y; y.setStaticArray(1, 2, 3); assert(y == [1, 2, 3]); } --- -- Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email --- You are receiving this mail because: ---
[Issue 2356] array literal as non static initializer generates horribly inefficient code.
http://d.puremagic.com/issues/show_bug.cgi?id=2356 yebblies yebbl...@gmail.com changed: What|Removed |Added CC||siegelords_ab...@yahoo.com --- Comment #12 from yebblies yebbl...@gmail.com 2012-10-29 05:14:56 EST --- *** Issue 8903 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: ---
[Issue 2356] array literal as non static initializer generates horribly inefficient code.
http://d.puremagic.com/issues/show_bug.cgi?id=2356 Jonathan M Davis jmdavisp...@gmx.com changed: What|Removed |Added CC||malteskaru...@web.de --- Comment #11 from Jonathan M Davis jmdavisp...@gmx.com 2012-10-14 11:36:34 PDT --- *** Issue 8820 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: ---
[Issue 2356] array literal as non static initializer generates horribly inefficient code.
http://d.puremagic.com/issues/show_bug.cgi?id=2356 Kenji Hara k.hara...@gmail.com changed: What|Removed |Added Keywords|patch | --- Comment #10 from Kenji Hara k.hara...@gmail.com 2012-05-05 00:42:06 PDT --- Pull #375 was not sufficient, so removed 'patch' keyword. -- Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email --- You are receiving this mail because: ---
[Issue 2356] array literal as non static initializer generates horribly inefficient code.
http://d.puremagic.com/issues/show_bug.cgi?id=2356 yebblies yebbl...@gmail.com changed: What|Removed |Added CC||jarrett.billingsley@gmail.c ||om --- Comment #9 from yebblies yebbl...@gmail.com 2012-02-02 20:49:34 EST --- *** Issue 2237 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: ---
[Issue 2356] array literal as non static initializer generates horribly inefficient code.
http://d.puremagic.com/issues/show_bug.cgi?id=2356 yebblies yebbl...@gmail.com changed: What|Removed |Added CC||rsi...@gmail.com --- Comment #7 from yebblies yebbl...@gmail.com 2012-02-02 14:27:49 EST --- *** Issue 4298 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: ---
[Issue 2356] array literal as non static initializer generates horribly inefficient code.
http://d.puremagic.com/issues/show_bug.cgi?id=2356 yebblies yebbl...@gmail.com changed: What|Removed |Added CC||s...@invisibleduck.org --- Comment #8 from yebblies yebbl...@gmail.com 2012-02-02 15:34:11 EST --- *** Issue 4881 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: ---
[Issue 2356] array literal as non static initializer generates horribly inefficient code.
http://d.puremagic.com/issues/show_bug.cgi?id=2356 d...@dawgfoto.de changed: What|Removed |Added CC||d...@dawgfoto.de --- Comment #6 from d...@dawgfoto.de 2011-10-07 19:09:44 PDT --- This is also a huge issue when assigning .init to a static array. ubyte[1024] v; v = typeof(v).init; This will generate a dynamically allocated [0, 0, 0 ... ] Arrayliteral for the rhs expression before calling _d_arraycopy. Even worse the allocated ArrayLiteral is initialized using 1024 comma expressions. Using -O the compiler will subsequently almost starve from O(N^2) behavior during comsub eliminations. -- Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email --- You are receiving this mail because: ---
[Issue 2356] array literal as non static initializer generates horribly inefficient code.
http://d.puremagic.com/issues/show_bug.cgi?id=2356 Kenji Hara k.hara...@gmail.com changed: What|Removed |Added Keywords||patch --- Comment #4 from Kenji Hara k.hara...@gmail.com 2011-09-09 09:35:07 PDT --- https://github.com/D-Programming-Language/dmd/pull/375 -- Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email --- You are receiving this mail because: ---
[Issue 2356] array literal as non static initializer generates horribly inefficient code.
http://d.puremagic.com/issues/show_bug.cgi?id=2356 --- Comment #5 from Kenji Hara k.hara...@gmail.com 2011-09-09 09:36:49 PDT --- After applying my patch, the sample code generates like follows: (output of ddbg in 64-bit Windows 7) c:\d\test.d:1 void main() 00402010: c80center 0xc, 0x0 c:\d\test.d:3 int[3] x = [1,2,3]; 00402014: c745f40100 mov dword [ebp-0xc], 0x1 0040201b: c745f80200 mov dword [ebp-0x8], 0x2 00402022: c745fc0300 mov dword [ebp-0x4], 0x3 00402029: 31c0xor eax, eax test.obj 0040202b: c9 leave 0040202c: c3 ret -- Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email --- You are receiving this mail because: ---
[Issue 2356] array literal as non static initializer generates horribly inefficient code.
http://d.puremagic.com/issues/show_bug.cgi?id=2356 clugd...@yahoo.com.au changed: What|Removed |Added Keywords|wrong-code |performance --- Comment #2 from clugd...@yahoo.com.au 2009-04-08 08:01 --- This is a performance issue, not wrong-code. --