perf: rewrite RlpNode internals with manual u8 length + MaybeUninit buffer#133
Merged
perf: rewrite RlpNode internals with manual u8 length + MaybeUninit buffer#133
Conversation
…uffer Replace ArrayVec<u8, 33> (u32 length + padding) with a hand-rolled u8 length + [MaybeUninit<u8>; 33] buffer. This makes RlpNode Copy, shrinks it from 40 to 34 bytes, and removes the arrayvec dependency. Also makes from_raw, word_rlp, as_slice, and as_mut_slice const. Amp-Thread-ID: https://ampcode.com/threads/T-019c8eb1-413e-717f-a722-57821ddc543b Co-authored-by: Amp <amp@ampcode.com>
Amp-Thread-ID: https://ampcode.com/threads/T-019c8eb1-413e-717f-a722-57821ddc543b Co-authored-by: Amp <amp@ampcode.com>
Amp-Thread-ID: https://ampcode.com/threads/T-019c8eb1-413e-717f-a722-57821ddc543b Co-authored-by: Amp <amp@ampcode.com>
Amp-Thread-ID: https://ampcode.com/threads/T-019c8eb1-413e-717f-a722-57821ddc543b Co-authored-by: Amp <amp@ampcode.com>
Amp-Thread-ID: https://ampcode.com/threads/T-019c8eb1-413e-717f-a722-57821ddc543b Co-authored-by: Amp <amp@ampcode.com>
DaniPopes
approved these changes
Feb 24, 2026
Amp-Thread-ID: https://ampcode.com/threads/T-019c8eb1-413e-717f-a722-57821ddc543b Co-authored-by: Amp <amp@ampcode.com>
- Add Copy to ExtensionNode (now possible since RlpNode is Copy) - Remove needless borrow in ExtensionNode::Debug - Add const to deprecated word_rlp fn - Remove clone_on_copy in test Amp-Thread-ID: https://ampcode.com/threads/T-019c8eb1-413e-717f-a722-57821ddc543b Co-authored-by: Amp <amp@ampcode.com>
Amp-Thread-ID: https://ampcode.com/threads/T-019c8eb1-413e-717f-a722-57821ddc543b Co-authored-by: Amp <amp@ampcode.com>
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
Rewrite
RlpNodeinternals to use a hand-rolledu8length +[MaybeUninit<u8>; 33]buffer instead ofArrayVec<u8, 33>.Motivation
ArrayVecuses au32length field (4 bytes + padding), wasting space for a type that can hold at most 33 bytes. Switching tou8length shrinksRlpNodefrom 40 to 34 bytes and makes itCopy.Changes
ArrayVec<u8, 33>withu8len +[MaybeUninit<u8>; 33]RlpNodeis nowCopy— clone is a plain memcpyfrom_raw,word_rlp,as_slice,as_mut_sliceare nowconstarrayvecdirect dependency (kept as transitive viaalloy-rlp)FromimplsTesting
All 34 existing tests pass.
Prompted by: danipopes