-
Notifications
You must be signed in to change notification settings - Fork 13.4k
Reduce size overhead of adaptative hashmap #40237
New issue
Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? # to your account
Conversation
r? @BurntSushi (rust_highfive has picked a reviewer for you, use r? to override) |
src/libstd/collections/hash/table.rs
Outdated
|
||
impl<T> TaggedUnique<T> { | ||
unsafe fn new(ptr: *mut T) -> Self { | ||
assert!(mem::align_of::<T>() > 1); |
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.
1 is the smallest alignment possible, so this assertion is always triggered, no?
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.
I was under the impression that hashes in raw table is always aligned to at least four. I'll double check.
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.
Oh wait, never mind me.
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.
So, a few comments here.
While I don’t think that happens in practice, it is certainly possible for HashUint
get an alignment of 1
in theory. For example a custom data-layout could be used to achieve that. This is one minor portability concern.
I’m somewhat doubting the need to have this as a generic pointer, rather than just a TaggedHashUintPtr
type. This is so unusual a thing to do, that having a generic version is unlikely to ever have any benefit.
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.
Good point, I'll get rid of the generic.
I screwed the diff, will fix shortly. |
@arthurprs I remember you having some nice benchmarks for previous PR. Could you rerun those and make a comparison between having separate bool, embedding bool into tagged pointer and the state before adaptive hashing was implemented? |
3010727
to
347180f
Compare
I did some benchmarks and discovered some weird inline failures There's things like
really... same for the small functions of the tagged ptr. I added some inline annotations and it was enough to bring the performance diff down to noise.
|
Exposes a boolean flag in RawTable and use it instead of a bool field in HashMap. Fixes: rust-lang#40042
These happened because All in all implementation of this looks very good to me, but since I’m not a T-libs person, I cannot take the liberty to r+ this. |
@bors: r+ Thanks @arthurprs! |
📌 Commit 3273003 has been approved by |
Reduce size overhead of adaptative hashmap Exposes a boolean flag in RawTable and use it instead of a bool field in HashMap. Taking a bit from capacity or length would make overflow handling tricky. Fixes: rust-lang#40042
Exposes a boolean flag in RawTable and use it instead of a bool field in HashMap.
Taking a bit from capacity or length would make overflow handling tricky.
Fixes: #40042