Skip to content

perf: rewrite RlpNode internals with manual u8 length + MaybeUninit buffer#133

Merged
gakonst merged 8 commits intomainfrom
danipopes/rlpnode-internals
Feb 24, 2026
Merged

perf: rewrite RlpNode internals with manual u8 length + MaybeUninit buffer#133
gakonst merged 8 commits intomainfrom
danipopes/rlpnode-internals

Conversation

@gakonst
Copy link
Copy Markdown
Member

@gakonst gakonst commented Feb 24, 2026

Summary

Rewrite RlpNode internals to use a hand-rolled u8 length + [MaybeUninit<u8>; 33] buffer instead of ArrayVec<u8, 33>.

Motivation

ArrayVec uses a u32 length field (4 bytes + padding), wasting space for a type that can hold at most 33 bytes. Switching to u8 length shrinks RlpNode from 40 to 34 bytes and makes it Copy.

Changes

  • Replaced ArrayVec<u8, 33> with u8 len + [MaybeUninit<u8>; 33]
  • RlpNode is now Copy — clone is a plain memcpy
  • from_raw, word_rlp, as_slice, as_mut_slice are now const
  • Removed arrayvec direct dependency (kept as transitive via alloy-rlp)
  • Added serde bridge via From impls

Testing

All 34 existing tests pass.

Prompted by: danipopes

…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>
@codspeed-hq
Copy link
Copy Markdown

codspeed-hq Bot commented Feb 24, 2026

Merging this PR will improve performance by 14.35%

⚡ 1 improved benchmark
✅ 3 untouched benchmarks

Performance Changes

Benchmark BASE HEAD Efficiency
trie[64] 464.7 ns 406.4 ns +14.35%

Comparing danipopes/rlpnode-internals (b0bf712) with main (6e42e13)

Open in CodSpeed

gakonst and others added 3 commits February 24, 2026 08:35
- 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>
@gakonst gakonst merged commit e906098 into main Feb 24, 2026
23 checks passed
@gakonst gakonst deleted the danipopes/rlpnode-internals branch February 24, 2026 10:49
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.

2 participants