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

Stop zeroing buffers in the local file storage. #4712

Merged
merged 2 commits into from
Mar 12, 2024

Conversation

fulmicoton
Copy link
Contributor

No description provided.

@fulmicoton fulmicoton requested a review from rdettai March 11, 2024 10:14
@fulmicoton fulmicoton marked this pull request as ready for review March 11, 2024 10:15
Copy link
Contributor

@rdettai rdettai left a comment

Choose a reason for hiding this comment

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

If you want to avoid using unsafe, I think you can use .take(num_bytes).read_to_end(&mut vec)

@fulmicoton
Copy link
Contributor Author

Oh? @rdettai does that do only one alloc?

@fulmicoton
Copy link
Contributor Author

@rdettai this is a neat trick. Digging a little deeper.
Take does not pass a size hint to read_to_end(..).

This is not a problem per se. That means we would have to preallocate the vector, with with_capacity(..).
We would just have to be careful to allocate with a capacity of max(len, 8000), because read_to_end allocate such a buffer.

I however did not dig too deep into the implementation of default_read_to_end. I think we can stick with the unsafe code considering how contains it is.

@fulmicoton fulmicoton merged commit 0d54cf0 into main Mar 12, 2024
4 checks passed
@fulmicoton fulmicoton deleted the removing-zeroing-buffer branch March 12, 2024 02:27
@PSeitz
Copy link
Contributor

PSeitz commented Mar 12, 2024

@rdettai this is a neat trick. Digging a little deeper. Take does not pass a size hint to read_to_end(..).

This is not a problem per se. That means we would have to preallocate the vector, with with_capacity(..). We would just have to be careful to allocate with a capacity of max(len, 8000), because read_to_end allocate such a buffer.

I however did not dig too deep into the implementation of default_read_to_end. I think we can stick with the unsafe code considering how contains it is.

I think with take we end up in the non specialized read version for the Vec, which is much slower usually.

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.

3 participants