Skip to content

Conversation

@mattsu2020
Copy link
Contributor

@mattsu2020 mattsu2020 commented Dec 11, 2025

Summary

  • Allocate read buffers with capacity and reuse their spare capacity to avoid zeroing overhead in fast encode/decode paths.
  • Switch fast encode/decode to read into spare capacity via slice::from_raw_parts_mut, keeping safety comments to document the initialization guarantees.
  • Tidy base_common.rs imports for consistency.

related
#9621

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-hq
Copy link

codspeed-hq bot commented Dec 11, 2025

CodSpeed Performance Report

Merging #9632 will not alter performance

Comparing mattsu2020:base32_performance_check (dbeacf7) with main (8a40908)

Summary

✅ 127 untouched
⏩ 6 skipped1

Footnotes

  1. 6 benchmarks were skipped, so the baseline results were used instead. If they were deleted from the codebase, click here and archive them to remove them from the performance reports.

@mattsu2020 mattsu2020 changed the title base(nc|32|64): Optimize performances remove memset base(nc|32|64): Optimize performances reduction memset Dec 11, 2025
@github-actions
Copy link

GNU testsuite comparison:

Skipping an intermittent issue tests/tail/overlay-headers (passes in this run but fails in the 'main' branch) 
@github-actions
Copy link

GNU testsuite comparison:

Skipping an intermittent issue tests/tail/overlay-headers (passes in this run but fails in the 'main' branch) 
@sylvestre
Copy link
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.
@github-actions
Copy link

GNU testsuite comparison:

Congrats! The gnu test tests/cksum/cksum is no longer failing! 
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

2 participants