New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[stdlib] fast path for UMBP.initialize<C>(from: C) when C is a Slice #38677
Conversation
`Sequence._copyContents(initializing:)` is the function relied on by `UnsafeMutableBufferPointer` for performant initialization from Collections. Until now, `Slice<Base: Collection>` has not had its own implementation, and therefore fell back to the default version implemented on `Sequence`. This implementation adds an attempted fast path, using `withContiguousStorageIfAvailable`. If that fails, the `Sequence` algorithm is used, as before. This resolves https://bugs.swift.org/browse/SR-14491
@swift-ci please benchmark |
Performance (x86_64): -O
Code size: -O
Performance (x86_64): -Osize
Code size: -Osize
Performance (x86_64): -Onone
Code size: -swiftlibsHow to read the dataThe tables contain differences in performance which are larger than 8% and differences in code size which are larger than 1%.If you see any unexpected regressions, you should consider fixing the Noise: Sometimes the performance results (not code size!) contain false Hardware Overview
|
@swift-ci Apple Silicon benchmark |
@swift-ci please test |
Performance (arm64): -O
Code size: -O
Performance (arm64): -Osize
Code size: -Osize
Performance (arm64): -Onone
Code size: -swiftlibsHow to read the dataThe tables contain differences in performance which are larger than 8% and differences in code size which are larger than 1%.If you see any unexpected regressions, you should consider fixing the Noise: Sometimes the performance results (not code size!) contain false Hardware Overview
|
Nice! Cc @karwa -- he has been interested in getting these fixed. |
Build failed |
@swift-ci please smoke test |
@swift-ci please test macOS platform |
Thanks a lot for taking this on, @glessard! |
UnsafeMutableBufferPointer.initialize(from:)
initializes a buffer from aSequence
. Many standard library collections have a fast path that implements the multi-element copy in a single call, but that fast path is currently stymied when the collection is wrapped in aSlice
. This PR implementsSlice._copyContents
, which attempts a fast copy via_withContiguousStorageIfAvailable
before reverting to an element-by-element copy.Resolves SR-14491 (rdar://76728166)