[SR-14491] UnsafeMutableBufferPointer.initialize(from:) is slow with slices #56846
Labels
bug
A deviation from expected or documented behavior. Also: expected but undesirable behavior.
performance
standard library
Area: Standard library umbrella
Environment
Swift 5.4
Additional Detail from JIRA
md5: 993949c9c0f9f481d20f2523e3b0a27a
Issue Description:
This very short, very simple demonstration shows what I mean:
Godbolt.org
Notice that the first function, "copy", gets turned in to an enormous generic specialization which iterates through every position in the slice and copies each byte one-by-one.
The second function, "copy2", uses "withContiguousStorageIfAvailable", and gets turned in to a memcpy.
In my testing, using wCSIA to initialize a destination buffer from slices of a source buffer can be around 8-10% faster than using `initialize(from: )`, depending on the length of the content.
Unfortunately, UMBP does not expose a function which uses wCSIA and otherwise falls-back to naive element-by-element copying. Worse - the current function's signature returns an iterator from the source collection, so the implementation can't be adjusted to make use of it. We need a new function on UMBP.
The text was updated successfully, but these errors were encountered: