Skip to content

Commit 8a7d1ff

Browse files
committed
add detail regarding performance goals and memory
1 parent 8944cfa commit 8a7d1ff

File tree

1 file changed

+2
-0
lines changed

1 file changed

+2
-0
lines changed

proposals/AAAA-stdlib-span-properties.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -211,6 +211,8 @@ extension Foundation.Data {
211211

212212
The `storage` and `bytes` properties should be performant and return their `Span` or `RawSpan` with very little work, in O(1) time. This is the case for all native standard library types. There is a performance wrinkle for bridged `Array` and `String` instances on Darwin-based platforms, where they can be bridged to Objective-C types that do not guarantee contiguous storage. In such cases the implementation will eagerly copy the underlying data to the native Swift form, and return a `Span` or `RawSpan` pointing to that copy.
213213

214+
This eager copy behaviour will be specific to the `storage` and `bytes` properties, and therefore the memory usage behaviour of existing unchanged code will remain the same. New code that adopts the `storage` and `bytes` properties will occasionally have higher memory usage due to the eager copies, but we believe this performance compromise is the right approach for the standard library. The alternative is to compromise the design for all platforms supported by Swift.
215+
214216
## Source compatibility
215217

216218
This proposal is additive and source-compatible with existing code.

0 commit comments

Comments
 (0)