-
Notifications
You must be signed in to change notification settings - Fork 10.6k
[stdlib] Set.intersection iterate over smaller set #36678
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
When intersecting two sets, it is beneficial to iterate over the smaller sized set of the two, and check membership on the other. This speeds up runtime dramatically for cases where the current set is significantly larger than the set you are intersecting against.
|
@swift-ci test |
|
@swift-ci benchmark |
lorentey
left a comment
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.
Thank you! This looks like a very nice win to me.
I have a long standing PR to optimize these high-level operations using temporary bit sets -- this reminds me it's time we dusted that off and landed it. (It needs some not-entirely-trivial work to be able to call into a newly available type from an inlinable method.)
|
@swift-ci Please test Windows Platform |
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 |
|
Build failed |
|
@swift-ci test |
|
Build failed |
|
@swift-ci test Linux platform |
|
@swift-ci 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 |
|
Build failed |
|
@swift-ci Please test Linux platform |
|
Build failed |
|
@swift-ci Please test Linux platform |
When intersecting two sets, it is beneficial to iterate over the smaller sized set of the two, and check membership on the other. This speeds up runtime dramatically for cases where the current set is significantly larger than the set being intersected against.
The following is a small comparison of the current intersection vs the proposed version. As input size increases, the current intersection takes significantly longer.
Note that this change only reduces time for cases where the sizes of the inputs differ significantly.