-
Notifications
You must be signed in to change notification settings - Fork 299
Make rehashing and resizing less generic #282
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
@@ -1312,6 +1224,19 @@ impl<A: Allocator + Clone> RawTableInner<A> { | |||
Bucket::from_base_index(self.data_end(), index) | |||
} | |||
|
|||
#[cfg_attr(feature = "inline-more", inline)] | |||
unsafe fn bucket_ptr(&self, index: usize, size_of: usize) -> *mut u8 { |
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.
This function absolutely needs to be #[inline]
at minimum, it is not generic.
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.
It is generic over A
, so I figured this should match the inlining of fn bucket
. Though I would put #[inline(always)]
on both of them (on release mode).
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.
There's a bunch of small functions which are beneficial to inline. I'll open a PR for those. It seems the compile time benefit of #119 mostly comes from removing inline on get
, insert
, etc.
// that we haven't rehashed yet. We unfortunately can't preserve the | ||
// element since we lost their hash and have no way of recovering it | ||
// without risking another panic. | ||
self.prepare_rehash_in_place(); |
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.
There's no reason for prepare_rehash_in_place
to be a separate function any more now that rehash_in_place
is moved to RawTableInner
.
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 find rehash_in_place
to be sufficiently large and complex already, so I don't mind this being in a separate function for code clarity. I'm less sure about prepare_resize
staying a separate function though.
@bors r+ |
📌 Commit bf8635d has been approved by |
☀️ Test successful - checks-actions |
This makes the code in
rehash_in_place
,resize
andreserve_rehash
less generic onT
. It also improves the performance of rustc. That performance increase in partially attributed to the use of#[inline(always)]
.This is the effect on rustc runtime:
rustc_driver
's code size is increased by 0.02%.This is the effect on compile time this has on my HashMap compile time benchmark:
The
hashmap-instances:debug
compile time could be further improved if there was a way to apply#[inline(always)]
only on release builds.