Skip to content

Use [MaybeUninit<u8>] throughout decode and encode paths#48

Open
elichai wants to merge 1 commit intoDaniPopes:masterfrom
elichai:maybeuninit
Open

Use [MaybeUninit<u8>] throughout decode and encode paths#48
elichai wants to merge 1 commit intoDaniPopes:masterfrom
elichai:maybeuninit

Conversation

@elichai
Copy link
Copy Markdown
Contributor

@elichai elichai commented Mar 19, 2026

  • Replace the Vec::set_len before write in decode() and encode_inner() with Vec:spare_capacity_mut(), deferring Vec::set_len until after data is written
  • Change all internal decode functions (decode_checked, decode_unchecked, decode_to_slice_inner) to accept &mut [MaybeUninit<u8>] instead of &mut [u8], across all arch backends
  • Add Output trait impl for &mut [MaybeUninit<u8>] so SIMD and generic decode paths work with uninit buffers
  • decode_to_array now passes its MaybeUninit array directly without casting to &mut [u8] first

  Replace `set_len` before write pattern with `spare_capacity_mut` and `MaybeUninit` slices.
  Add `Output` impl for `&mut [MaybeUninit<u8>]` and `slice_as_uninit_mut` helper.
@codspeed-hq
Copy link
Copy Markdown

codspeed-hq bot commented Mar 19, 2026

Merging this PR will degrade performance by 19.02%

⚡ 1 improved benchmark
❌ 2 regressed benchmarks
✅ 33 untouched benchmarks

⚠️ Please fix the performance issues or acknowledge them on CodSpeed.

Performance Changes

Benchmark BASE HEAD Efficiency
bench1_32b 372.5 ns 460 ns -19.02%
bench2_256b 631.1 ns 747.8 ns -15.6%
bench1_32b 580.6 ns 522.2 ns +11.17%

Comparing elichai:maybeuninit (63b1bbe) with master (1143588)

Open in CodSpeed

@elichai
Copy link
Copy Markdown
Contributor Author

elichai commented Mar 19, 2026

The CI failures seem unrelated (unused portable_simd) and I'm not sure how to interpert the codspeed results, this should not affect performance (by moving the location of .set_len we will probably influence codegen a bit),

I also ran it locally with miri and fuzzed it via cargo +nightly fuzz run fuzz_const_hex --careful for a while on my macOS

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.

1 participant