-
Notifications
You must be signed in to change notification settings - Fork 10.3k
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] Optimize some Set operations #21300
Conversation
@swift-ci benchmark |
@swift-ci test |
Build failed |
Build comment file:Performance: -O
Code size: -O
Performance: -Osize
Code size: -Osize
Performance: -Onone
How 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 test |
This comment has been minimized.
This comment has been minimized.
Build failed |
Swift(linux-x86_64).SIL.parse_stdlib.sil (from Swift(linux-x86_64)):
Hm... 🤨 |
@swift-ci please test linux platform |
Build failed |
76f1ac5
to
64f62f7
Compare
@swift-ci please test |
@swift-ci benchmark |
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
Build comment file:Performance: -O
Code size: -O
Performance: -Osize
Code size: -Osize
Performance: -Onone
How 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 |
Use a temporary bitset to speed up the Sequence variant by roughly a factor of 3.
Use a temporary bitset to speed up the Sequence variant by roughly a factor of 3.
In the Sequence variant, don’t convert the argument to a Set — just check if self contains all elements. This makes isSuperset(of:) roughly 4 times faster.
- Use a temporary bitset to speed up the Sequence variant by roughly a factor of 4. - Fix a logic error causing the a == b case for the set variant to be O(n) instead of O(1).
- In the sequence case, don’t convert the input to a set; simply test its elements one by one. This leads to a cool 4x speedup. - In the set case, prefer to iterate over the smaller set. The leads to a speedup proportional to the ratio of the counts between the two sets if the caller used an unlucky ordering.
Use a temporary bitset to avoid hashing elements more than once, and to prevent rehashings during the creation of the result set. This leads to a speedup of about 0-4x, depending on the number of elements removed.
This works the same way as Set.subtracting<S>(_:), and has similar performance benefits.
Use a temporary bitset to speed up the Sequence variant by roughly a factor of ~4-6, and the set-set variant by a factor of ~1-4, depending on the ratio of overlapping elements.
@swift-ci please benchmark |
Performance: -O
Code size: -O
Performance: -Osize
Code size: -Osize
Performance: -Onone
How 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 test |
Build failed |
Performance: -O
Code size: -O
Performance: -Osize
Code size: -Osize
Performance: -Onone
How 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
|
The runtimes of the extended Similarly, there is a small issue with too low runtime (even before these changes) in a case of |
Closing in favor of #40012. |
This uses temporary bitmaps to considerably speed up some high-level Set operations.
Set.isSubset<S>(of:)
Set.isStrictSubset<S>(of:)
Set.isSuperset<S>(of:)
Set.isStrictSuperset<S>(of:)
Set.isDisjoint<S>(with:)
Set.subtracting(_:)
Set.filter(_:)
Set.intersection<S>(_:)
Set.intersection(_:)
Benchmark results depend on the size of the sets and the element type. The numbers above were measured with integer keys across a range of counts from 1 to 1 million items.