-
Notifications
You must be signed in to change notification settings - Fork 110
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
Improve the dealloc and realloc functions to more agressively reuse memory #35
Conversation
@@ -834,7 +834,19 @@ unsafe impl<'a> alloc::Alloc for &'a Bump { | |||
} | |||
|
|||
#[inline(always)] | |||
unsafe fn dealloc(&mut self, _ptr: NonNull<u8>, _layout: Layout) {} | |||
unsafe fn dealloc(&mut self, ptr: NonNull<u8>, layout: Layout) { |
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.
Can you replace the #[inline(always)]
to just #[inline]
now that this isn't a no-op? Thanks.
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.
Done
src/lib.rs
Outdated
if footer_usize.checked_sub(old_size) == Some(ptr.as_ptr() as usize) { | ||
// Our strategy is to deallocate the old allocation and then do a new | ||
// allocation of the required size hoping for it to fit in the same | ||
// location. |
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'd prefer to keep the old strategy of trying to allocate the delta in place in this chunk.
Relying on the fact that we currently never touch any of the bytes we de-allocate is a little too subtle for my tastes, and it cuts off introducing poison patterns or other things like that in the future. This is also a bit more code than the original, and it isn't clear to me that it has any perf benefit, is better at reusing memory, or anything like that.
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.
That makes a lot of sense. I have pushed a new version which still passes the same test as before. Could you take a look and see if you find it acceptable?
…er to reason about
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.
Thanks!
I found a final issue while looking over the code again.