Bug 1556 – Inefficient array concatenation (especially for 3+ arrays)

Status
RESOLVED
Resolution
FIXED
Severity
normal
Priority
P2
Component
dmd
Product
D
Version
D2
Platform
x86
OS
All
Creation time
2007-10-08T03:51:00Z
Last change time
2015-06-09T05:14:43Z
Assigned to
dvdfrdmn
Creator
fvbommel

Comments

Comment #0 by fvbommel — 2007-10-08T03:51:19Z
GDC (0.24) compiles "a~b~c~d~e~f~g~h" (where all variables are arrays) to multiple invocations of _d_arraycatnT, a function which can handle any number of arrays but only seems to get called for two at a time. This causes N-1 function calls (each of which performs an allocation) instead of only one. This is inefficient and causes extra garbage on the heap. GDC also generates calls to this multi-array function for a simple 2-array case, even though gphobos has _d_arraycatT especially for this purpose, without the overhead of vararg handling. DMD (both 1.022 and 1.020 on which GDC 0.24 was based) does this right, calling _d_arraycatT for a 2-array concat and _d_arraycatnT to concatenate 3+ arrays. Note: I'm tempted to add keyword "wrong-code" to this report, but the code *does* return the right result (an array filled with the concatenation of the initial arrays) so I'm not sure if it applies.
Comment #1 by dvdfrdmn — 2007-10-13T21:13:36Z
Fixed in svn 185 / release 0.25