Repository navigation
feat: support uninitialized output buffers - #19
Merged
Merged
Conversation
tisonkun
approved these changes
Nov 18, 2026
tisonkun
left a comment
Contributor
There was a problem hiding this comment.
Thanks for your information! LGTM.
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
Add safe caller-buffer APIs that write directly into
&mut [MaybeUninit<u8>]:encode_into_uninitreturns the initialized&mut strprefix.decode_into_uninitreturns the initialized&mut [u8]prefix.These methods support uninitialized stack buffers and Vec/BytesMut spare capacity without prior zero-filling. They are available on
Codecand concrete profiles. Existing signatures remain unchanged, and no dependencies are added.Closes #11.
Design Notes
update/finishAPIs on initialized slices. Callers can initialize a chunk buffer once and reuse it. This keeps the API small and avoids extending state and retry behavior across four additional methods. Streaming still cannot target spare capacity directly. This is a scope and maintenance decision; new streaming variants were not benchmarked.Performance Evidence
We compared separate methods with a zero-dependency
Outputwrapper using the same backend, harness, inputs, and lockfile. Positive changes mean the wrapper takes longer.Environment: Intel Core i5-8279U at 2.40 GHz, x86_64, 4 cores / 8 threads, 8 GiB RAM; macOS 15.7.9; rustc 1.100.0 / LLVM 23.1.5. No extra
RUSTFLAGSor CPU affinity.Method: baseline
1b226ab; 32 samples per API per scenario, approximately 300 ms each, fixed matched round counts, alternating ABBA/BAAB blocks, and 10,000 paired bootstrap resamples. Both configurations cover Base16/Base32/Base64 encoding and decoding at 8 bytes using reused uninitialized buffers. Thin LTO adds three 16 KiB cases. Sizes refer to raw messages; timed loops do not allocate.Interpretation: every scenario’s 95% confidence interval includes zero. One interval extends to +1.185%, so strict ±1% equivalence was not established for every case. The results support choosing on API clarity and compatibility rather than a measured speed advantage. This comparison evaluates two APIs supporting uninitialized output; it does not measure initialization savings.
Against the updated base
c815982, both configurations also produce identical workload functions for all 96 matched API pairs and pass 192 output checks each. This is code-generation verification; timings were not repeated on that base. Conclusions remain specific to the tested prototypes, compiler, and machine.Validation
cargo x lint,cargo x check, and nine cross-target compile checks passed. Stable and Rust 1.88.0 each passed 685 test executions; benchmark verification passed 209 checks.c815982covered 46 scenarios and produced matching benchmark executable.textsections. Native ARM and WebAssembly execution were not performed locally.