[SR-11759] Redundant copies of array buffers when using ArraySlice #54166
Labels
ARC
Feature: automatic reference counting
bug
A deviation from expected or documented behavior. Also: expected but undesirable behavior.
performance
standard library
Area: Standard library umbrella
Attachment: Download
Environment
Swift 5.1.2 in Xcode 11.2.1 (11B53)
Additional Detail from JIRA
md5: 833b0855fed40f2adef4f523ab320bfd
Issue Description:
When using `ArraySlice`, underlying buffer gets copied when elements of an array (not the array itself) are modified.
Documentation for `ArraySlice` says:
Based on that, I assumed there should be no copies of the array buffer, is the assumption correct or am I misunderstanding purpose of the type?
I've attached benchmark sample code and results from `Instruments`.
But the code boils down to two cases:
On my machine in the attached benchmark sample first case takes `1.8sec` and second takes `32ms`, the difference is caused by array buffer copies. In the second case the slice is used in its own scope so there will be no need for copies.
The sample is only for the need of benchmark, I wouldn't have though there will be buffer copies happening in the first case.
The text was updated successfully, but these errors were encountered: