-
Notifications
You must be signed in to change notification settings - Fork 10.5k
Improve performance of Collection.removeFirst(_:) where Self == SubSequence #32451
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
Conversation
Co-authored-by: Xiaodi Wu <[email protected]>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry, should have figured out how to highlight the subsequent lines so that they're not duplicated.
@swift-ci Please smoke test |
1 similar comment
@swift-ci Please smoke test |
I wonder, @stephencelis, would it be possible for you to incorporate this benchmark into the test suite in another PR? Then we can merge that first to show the nice shiny improvement with this PR while also ensuring no regressions on other benchmarks. |
@xwu I'm not familiar with that process. Do you have any docs/examples handy? |
Here's a doc you might find handy: https://github.com/apple/swift/blob/master/benchmark/README.md. |
There are a few files in the |
@stephencelis Thanks so much for identifying this issue and working on a fix! There are two more overloads in RangeReplaceableCollection.swift that could use this treatment, the second of which looks like the one that's actually getting used for |
@natecook1000 Done! @xwu Unfortunately I'm having issues getting things to run locally and I'm not sure I have a ton of free time to diagnose, so I'm afraid I won't be able to submit those benchmarks 😞 |
@swift-ci Please smoke benchmark |
Performance: -O
Code size: -OPerformance: -Osize
Code size: -OsizePerformance: -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 Please benchmark |
1 similar comment
@swift-ci Please benchmark |
Performance: -O
Code size: -OPerformance: -Osize
Code size: -OsizePerformance: -OnoneCode 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
|
Strange that SubstringDropFirst1 doesn't show up. Any idea why? |
It's likely because I wrote that benchmark to test |
@swift-ci Please benchmark |
Performance: -O
Code size: -OPerformance: -Osize
Code size: -OsizePerformance: -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 Please smoke test and merge |
This PR updates
Collection.removeFirst(_:) where Self == SubSequence
to do a bounds check usingindex(_:offsetBy:limitedBy:)
instead ofcount
to avoid an O(N) complexity where N is the size of the collection (which is incorrectly documented as O(K) where K is the value passed toremoveFirst
).A benchmark working on a large substring before the change:
After:
Context: https://forums.swift.org/t/performance-of-removefirst-vs-removefirst-1/37712