Optimize hex serialization#4667
Merged
Merged
Conversation
Contributor
|
Claude finished @MartinquaXD's task in 1m 43s —— View job PR Review: Optimize hex serialization
Verdict: LGTM ✅ — no issues found, no inline comments needed. This is a clean, behavior-preserving optimization. Verified:
The stack-allocated fixed-size buffers avoid the heap for the hot fixed-size serialization paths — a solid improvement, and at worst on-par as the description notes.
|
jmg-duarte
enabled auto-merge
July 24, 2026 08:45
jmg-duarte
approved these changes
Jul 24, 2026
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 subscribe to this conversation on GitHub.
Already have an account?
Sign in.
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.
Description
const_hexoffers a way to serialize bytes into a fixed size stack allocated buffer.The new version is twice as fast (in benchmarks):
Benefits comes from avoiding the heap, avoiding the
.unwrapand avoiding the utf8 check as it uses the unchecked version internally; finally, it should also result in a smaller binary size (though it will not be noticeable).Changes
Use
const_hex::Buffer::<N, PREFIX>::new()for all code serializing fixed sized bytes.Also cleans up 2 implementations for variable length bytes serialization.
How to test
all tests should still pass as this should not introduce any behavior changes.