Bug 14458 – very slow ubyte[] assignment (dmd doesn't use memset)

Status
RESOLVED
Resolution
FIXED
Severity
normal
Priority
P1
Component
dmd
Product
D
Version
D2
Platform
All
OS
All
Creation time
2015-04-17T20:08:29Z
Last change time
2020-07-21T13:23:03Z
Keywords
performance, pull
Assigned to
No Owner
Creator
Martin Nowak
See also
https://issues.dlang.org/show_bug.cgi?id=21027

Comments

Comment #0 by code — 2015-04-17T20:08:29Z
Tracked down a severe performance issue in my new AA implementation, where it zeroed a freshly allocated entry. DMD generates the following code for the assignment. ---- void zero(ubyte[] ary) { ary[] = 0; } ---- mov rcx, rdi ; 0008 _ 48: 89. F9 xor rax, rax ; 000B _ 48: 31. C0 mov rdi, rsi ; 000E _ 48: 8B. FE rep stosb ; 0011 _ F3: AA ---- This is a bytewise store 0 and is about 4x slower than memset, if sz >= 4. It's slightly faster for sz < 4. Not sure why `rep stosb` suddenly becomes 4x slower when sz increases from 3 to 4 bytes, but in any case the compiler should optimize the small case to direct assignments and the big case to memset, or always use memset.
Comment #1 by code — 2015-04-17T20:37:11Z
Lots of horrible codegen in cod2.c for memset, memcmp, memcpy, strcpy, strcmp. https://github.com/D-Programming-Language/dmd/blob/95ff133b423813a0f4b11c7c1369a22536d002d9/src/backend/cod2.c#L3580
Comment #2 by bugzilla — 2020-07-21T01:09:14Z
Not going to bother with OPstrcpy or OPstrcmp as they are never generated by DMD.
Comment #3 by dlang-bot — 2020-07-21T01:10:28Z
@WalterBright created dlang/dmd pull request #11437 "fix Issue 14458 - very slow ubyte[] assignment (dmd doesn't use memset)" fixing this issue: - fix Issue 14458 - very slow ubyte[] assignment (dmd doesn't use memset) https://github.com/dlang/dmd/pull/11437
Comment #4 by dlang-bot — 2020-07-21T13:23:03Z
dlang/dmd pull request #11437 "fix Issue 14458 - very slow ubyte[] assignment (dmd doesn't use memset)" was merged into master: - b8f31faeb720f25cfa672dcb7ae0d72d8efd2a0c by Walter Bright: fix Issue 14458 - very slow ubyte[] assignment (dmd doesn't use memset) https://github.com/dlang/dmd/pull/11437