Skip to content
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

Merged
merged 2 commits into from
Oct 30, 2019
Merged

Improve the dealloc and realloc functions to more agressively reuse memory #35

merged 2 commits into from
Oct 30, 2019

Conversation

TethysSvensson
Copy link
Contributor

I found a final issue while looking over the code again.

@@ -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) {
Copy link
Owner

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.

Copy link
Contributor Author

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.
Copy link
Owner

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.

Copy link
Contributor Author

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?

Copy link
Owner

@fitzgen fitzgen left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks!

@fitzgen fitzgen merged commit 35291d6 into fitzgen:master Oct 30, 2019
@TethysSvensson TethysSvensson deleted the better-realloc branch October 30, 2019 20:32
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants