-
Notifications
You must be signed in to change notification settings - Fork 288
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
Implement XxxAssign operations on HashSets #529
Conversation
I have one more optimization idea, which I will try tomorrow. |
I honestly don't think any optimizations I will think of will cause a significant improvement at this point, so I'll stop trying around now :) |
Actually it should be the other way around: these traits should be implemented for I checked the standard library and it has the same issue. This should be fixed once hashbrown is updated in the standard library.
I don't think it makes sense to add this just for convenience. It would introduce confusion since now you have 2 operators that do the same thing. |
Whoops, I forgot default generics are a thing and thought "No specified bound == No bound".
I'll add the Allocator bound everywhere and remove `Add` and `AddAssign` then.
I might not get around to that today, but if not I'll do it tomorrow.
Would adding "Add" as an alias to "BitOr" be fine, if libraries that aren't STD are allowed to do that?
|
I would prefer if |
I meant a doc alias, but thats fine too, then I just wont.
|
A doc alias wouldn't work well since it would only trigger if you specifically search for "add". It is unlikely you are specifically looking for set union in that case: you would most likely be searching for arithmetic addition. |
Fair enough, if one purposefully searches the docs one will probably notice that for a set |
Oh btw the non-assign performance would have changed due to #530 being merged, do I have to re-test them all or is it fine to leave the PR description as is? |
It's fine to leave the benchmark results as they are, but the rest of the description will need updating. |
Yes, of course, once I implemented the changes I will go over everything in the description and adjust it to the changes in the PR. |
BitXor and Sub already don't have them, and its not like we guarantee returning a set with the same A type anyway. I would be fine with adding it to BitXor and Sub instead, but I think it should be consistent.
This is functionally the same as BitOr, but imo its more intuitive if it exists because of the Sub impl
Also add a set of benchmarks for set operations
Also remove S: Default bound on Assign ops
The performance benefit is honestly within margin of error, so it might be better to undo this in favor of the previous simpler implementation.
To make testing with different elements easier
I implemented the changes I said I would, and rebased because of the recent CI fixes. Though now I wonder: Would it be better to change the |
I believe that now would be the best time to add a restriction to Another question would be whether set operations between sets with different allocators should be allowed. One other thing is that while I generally intend to port my recent hashbrown PR's to STD(atleast those which result in behavior changes), I wont have the time to do so in the next 3-4 weeks. |
I don't think we should do this because then the operation becomes too generic and the compiler can't infer the correct allocator type to use.
|
This requires for the allocator to implement Default
Ok, done, I implemented the |
@bors r+ |
☀️ Test successful - checks-actions |
This PR primarily implements the XxxAssign operation traits for
HashSet
.My primary motivation to do so is for convenience, but depending on the situation they can provide a significant performance improvement as well.*
In my tests, which may not be ideal because I don't have much benchmarking experience, the assigning operations are, with the exception of
Sub
, a minimum of 25% faster.*Note that when swapping the large and the small set around, some of these are significantly slower than the non-assigning variant.
Therefore using them is likely only worth it performance wise, if you already know which set is larger, and the right one of the sets just so happens to be the one you don't need to keep.
* Results may have changed due to #530 being merged
Here my exact benchmark results, done with the newly added benchmark suit:
In addition to the Assigning operators this PR changes a few more things:
A: Allocator + Default
.