base(nc|32|64): Optimize performances reduction memset - #9632
Merged
Conversation
Refactor buffer creation from zero-initialized vectors to pre-allocated Vec with_capacity, using unsafe set_len to avoid unnecessary zeroing, improving performance without affecting correctness, as only initialized bytes from Read::read are accessed.
…decode Replaced manual unsafe `set_len` calls and direct reads into uninitialized vectors with `MaybeUninit::slice_assume_init_mut` to prevent potential memory safety issues and improve code reliability in `fast_encode` and `fast_decode` modules. Added buffer clearing to ensure proper reuse.
…ce::from_raw_parts_mut Replace unsafe usage of `MaybeUninit::slice_assume_init_mut` with `slice::from_raw_parts_mut` in the fast_encode and fast_decode modules for reading data into the spare capacity of buffers. This change maintains safety guarantees through updated comments while potentially improving code clarity and performance by avoiding MaybeUninit initialization assumptions. The modification ensures the buffer's uninitialized tail is correctly handled as raw bytes during I/O operations.
Moved the `slice` import from after `collections::VecDeque` to after `num::NonZeroUsize` to better align with the module's import grouping style.
CodSpeed Performance ReportMerging #9632 will improve performances by 3.15%Comparing Summary
Benchmarks breakdown
Footnotes
|
|
GNU testsuite comparison: |
|
GNU testsuite comparison: |
Contributor
|
i am not a fan of adding unsafe. would it be possible to find another way? thanks |
Replace unsafe spare_capacity_mut and from_raw_parts_mut usage with safe Vec initialization and direct read calls in fast_encode and fast_decode. This eliminates potential safety risks while preserving buffer functionality.
|
GNU testsuite comparison: |
mattsu2020
marked this pull request as draft
December 16, 2025 08:39
Contributor
|
is it ready for review? |
…icient buffering Switch from unbuffered Read to BufRead in get_input, handle_input, and fast_encode_stream functions. This reduces syscalls by leveraging buffered reads, improving performance for base32 encoding/decoding operations. Refactor fast_encode_stream to use fill_buf() and manage leftover buffers more efficiently.
|
GNU testsuite comparison: |
mattsu2020
marked this pull request as ready for review
December 17, 2025 10:50
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
slice::from_raw_parts_mut, keeping safety comments to document the initialization guarantees.related
#9621