Optimize Set is_disjoint#531
Merged
bors merged 2 commits intorust-lang:masterfrom Jun 11, 2024
Merged
Conversation
Member
|
@bors r+ |
Contributor
bors
added a commit
that referenced
this pull request
Jun 10, 2024
Optimize Set is_disjoint By using the `Intersection` iterator in `HashSet::is_Disjoint` its performance can be significantly improved in some cases. This is because `intersection()` always uses the shorter set as its iterator. It would also be possible to replicate this "Iterate over the smaller set and check in the larger set" logic in the is_disjoint method. However in my benchmarks the approach I chose is faster than that. This change only causes a significant improvement when called on the larger of two disjoint sets. My benchmark results: Name | Before | After | Diff (%) -- | -- | -- | -- disjoint_is_disjoint_large_small | 1,147.43 | 535.25 | -53,35 % disjoint_is_disjoint_small_large | 535.66 | 527.59 | -1,51 % subset_is_disjoint | 9.90 | 10.44 | 5,45 % superset_is_disjoint | 9.80 | 10.43 | 6,43 %
Contributor
Contributor
|
💔 Test failed - checks-actions |
Contributor
Author
|
That error seems to be a Dead Code error which I'm pretty sure this PR couldn't have caused, is there anything I can/should do about this? |
Member
|
Just add |
Contributor
Author
|
Ok, I'll do that tomorrow.
|
This will hopefully fix the CI error.
Contributor
Author
|
Hooray that actually fixed CI. |
Member
|
@bors r+ |
Contributor
Contributor
Contributor
|
☀️ Test successful - checks-actions |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
By using the
Intersectioniterator inHashSet::is_Disjointits performance can be significantly improved in some cases.This is because
intersection()always uses the shorter set as its iterator.It would also be possible to replicate this "Iterate over the smaller set and check in the larger set" logic in the is_disjoint method.
However in my benchmarks the approach I chose is faster than that.
This change only causes a significant improvement when called on the larger of two disjoint sets.
My benchmark results: