Skip to content

[stdlib] Deprecate MutableCollection._withUnsafeMutableBufferPointerIfSupported #36003

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

Merged

Conversation

lorentey
Copy link
Member

In Swift 5.0, SE-0237 introduced the public MutableCollection.withContiguousMutableStorageIfAvailable method. It’s time we migrated off the old, underscored variant and deprecated it.

The default MutableCollection.sort and .partition(by:) implementations are currently calling this hidden method rather than the documented interface, preventing custom Collection implementations from achieving good performance, even if they have contiguous storage.

…fSupported

In Swift 5.0, [SE-0237] introduced the public `MutableCollection.withContiguousMutableStorageIfAvailable` method. It’s time we migrated off the old, underscored variant and deprecated it.

The default `MutableCollection.sort` and `.partition(by:)` implementations are currently calling this hidden method rather than the documented interface, preventing custom Collection implementations from achieving good performance, even if they have contiguous storage.

[SE-0237]: https://github.com/apple/swift-evolution/blob/master/proposals/0237-contiguous-collection.md
@lorentey
Copy link
Member Author

@swift-ci test

@lorentey
Copy link
Member Author

@swift-ci benchmark

@swift-ci
Copy link
Contributor

Build failed
Swift Test Linux Platform
Git Sha - ba3c403

@lorentey
Copy link
Member Author

Oh, nice, we have test coverage! ❤️

[ RUN      ] ArraySliceWithNonZeroStartIndex_MutableRandomAccessCollectionRef.ArraySliceWithNonZeroStartIndex.ArraySlice<LifetimeTracked>.Type.partition/DispatchesThrough_withUnsafeMutableBufferPointerIfSupported
stdout>>> check failed at /home/buildnode/jenkins/workspace/swift-PR-Linux/branch-main/swift/stdlib/private/StdlibCollectionUnittest/CheckMutableCollectionType.swift, line 968
stdout>>> expected: 1 (of type Swift.Int)
stdout>>> actual: 0 (of type Swift.Int)
stdout>>> check failed at /home/buildnode/jenkins/workspace/swift-PR-Linux/branch-main/swift/stdlib/private/StdlibCollectionUnittest/CheckMutableCollectionType.swift, line 970
stdout>>> expected: 1 (of type Swift.Int)
stdout>>> actual: 0 (of type Swift.Int)
[     FAIL ] ArraySliceWithNonZeroStartIndex_MutableRandomAccessCollectionRef.ArraySliceWithNonZeroStartIndex.ArraySlice<LifetimeTracked>.Type.partition/DispatchesThrough_withUnsafeMutableBufferPointerIfSupported

@lorentey
Copy link
Member Author

@swift-ci test

@lorentey
Copy link
Member Author

@swift-ci benchmark

@swift-ci
Copy link
Contributor

Build failed
Swift Test Linux Platform
Git Sha - 1ebbfabe7c48c866262cb6e59e420552501f017c

@swift-ci
Copy link
Contributor

Build failed
Swift Test OS X Platform
Git Sha - 1ebbfabe7c48c866262cb6e59e420552501f017c

@swift-ci
Copy link
Contributor

Performance: -O

Regression OLD NEW DELTA RATIO
FlattenListLoop 1453 2185 +50.4% 0.66x (?)
FlattenListFlatMap 4277 5233 +22.4% 0.82x (?)

Code size: -O

Performance: -Osize

Regression OLD NEW DELTA RATIO
FlattenListFlatMap 5215 5811 +11.4% 0.90x (?)

Code size: -Osize

Performance: -Onone

Regression OLD NEW DELTA RATIO
DictionaryBridgeToObjC_Access 882 996 +12.9% 0.89x (?)

Code size: -swiftlibs

How to read the data The 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
regressions before you merge the PR.

Noise: Sometimes the performance results (not code size!) contain false
alarms. Unexpected regressions which are marked with '(?)' are probably noise.
If you see regressions which you cannot explain you can try to run the
benchmarks again. If regressions still show up, please consult with the
performance team (@eeckstein).

Hardware Overview
  Model Name: Mac Pro
  Model Identifier: MacPro6,1
  Processor Name: 8-Core Intel Xeon E5
  Processor Speed: 3 GHz
  Number of Processors: 1
  Total Number of Cores: 8
  L2 Cache (per Core): 256 KB
  L3 Cache: 25 MB
  Memory: 64 GB

@lorentey
Copy link
Member Author

16:33:26 
/home/buildnode/jenkins/workspace/swift-PR-Linux/branch-main/swift/stdlib/private/StdlibCollectionUnittest/CheckMutableCollectionType.swift:517:1: 
error: expressions are not allowed at the top level

<shameful facepalm>

@lorentey lorentey force-pushed the deprecate-underscored-storage-access branch from 1ebbfab to b50db27 Compare February 17, 2021 04:39
@lorentey
Copy link
Member Author

@swift-ci test

@swift-ci
Copy link
Contributor

Build failed
Swift Test Linux Platform
Git Sha - b50db27

@swift-ci
Copy link
Contributor

Build failed
Swift Test OS X Platform
Git Sha - b50db27

Copy link
Member

@natecook1000 natecook1000 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is great! 👏

@lorentey
Copy link
Member Author

@swift-ci test

@swift-ci
Copy link
Contributor

Build failed
Swift Test Linux Platform
Git Sha - 379a27d

@swift-ci
Copy link
Contributor

Build failed
Swift Test OS X Platform
Git Sha - 379a27d

@lorentey
Copy link
Member Author

@swift-ci test

@swift-ci
Copy link
Contributor

Build failed
Swift Test Linux Platform
Git Sha - aadca9c

@lorentey
Copy link
Member Author

lorentey commented Feb 24, 2021

'WorkspaceTests.testArtifactDownloadHappyPath' started at 2021-02-24 06:35:06.861
/home/buildnode/jenkins/workspace/swift-PR-Linux/branch-main/swiftpm/Tests/WorkspaceTests/WorkspaceTests.swift:4402: error: WorkspaceTests.testArtifactDownloadHappyPath : XCTAssertEqual failed: ("[<AbsolutePath:"/tmp/ws/.build/artifacts/A">, <AbsolutePath:"/tmp/ws/.build/artifacts/B">]") is not equal to ("[<AbsolutePath:"/tmp/ws/.build/artifacts/A">, <AbsolutePath:"/tmp/ws/.build/artifacts/A">, <AbsolutePath:"/tmp/ws/.build/artifacts/B">]") 

Hm.

@lorentey
Copy link
Member Author

@swift-ci test linux platform

@lorentey
Copy link
Member Author

@swift-ci test

@lorentey lorentey merged commit 0836707 into swiftlang:main Feb 26, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants