Skip to content

Comments

perf: U256 representation#17

Merged
DaniPopes merged 103 commits intomainfrom
alexey/uint-repr
Jun 19, 2025
Merged

perf: U256 representation#17
DaniPopes merged 103 commits intomainfrom
alexey/uint-repr

Conversation

@shekhirin
Copy link
Contributor

@shekhirin shekhirin commented Jun 10, 2025

Summary

This PR refactors the internal representation of Nibbles from SmallVec<[u8; 64]> (storing one nibble per byte) to U256 (storing two nibbles per byte). This gives 2x savings in memory and performance improvements in most of the methods.

Details

Representation Change

  • Before: Used SmallVec<[u8; 64]> storing one nibble per byte (4 bits used, 4 bits wasted). Nibbles [1, 2] are stored as 0x0102.
  • After: Uses U256 storing nibbles packed in their natural 4-bit representation. Nibbles [1, 2] are stored as 0x12.
  • Nibbles are stored with most significant bits first. Nibbles [1, 2] are stored as 0x12...0, not 0x0...12.

Breaking Changes

This is a breaking change due to:

  • Removed support for nibble sequences longer than 64
  • Removal of Deref implementation and direct slice access
  • Changed memory layout
  • Changed serde serialization format

Benchmarking

See benchmark results on CodSpeed.

When integrated in Reth, newPayload latency is decreased by 5-10%

image

Copy link
Member

@DaniPopes DaniPopes left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm

@DaniPopes DaniPopes merged commit 47ee5c7 into main Jun 19, 2025
19 of 20 checks passed
@ZanCorDX ZanCorDX mentioned this pull request Sep 1, 2025
3 tasks
ZanCorDX added a commit to flashbots/rbuilder that referenced this pull request Sep 3, 2025
## 📝 Summary

Changes for Fusaka fork:
- Had to upgrade to rust 1.88: lint hell.
- alloy/nybbles: alloy-rs/nybbles#17 updates the
internal representation of Nibble from a SmallVec<[u8; 64]> to a U256.
This breaks code in the merkle eth sparse tree as the code indexes a lot
into the SmallVec representation.
For this version we kept the sparse tree internals and adapted the on
the interface (we have deps in both nibble versions).
- New Eip7594 blobs: This blobs have more profs so now we use
BlobTransactionSidecarVariant instead of BlobTransactionSidecar.
BlobTransactionSidecarVariant can model the old blob
(BlobTransactionSidecar) and the new one
(BlobTransactionSidecarEip7594).
- revm changed BlockNumber and Timestamp from U256 instead of u64. We
convert internally to 64 since it's more compatible with the rest.
- Minor traits changes on reth.
- New relay SignedBidSubmissionV5 with new BlobsBundleV2.
- New rlp block encoding limiting as specified by EIP-7934.
- Order filter to avoid mix of blob types before and after the fork.

Thanks @bharath-123 for the help!

## ✅ I have completed the following steps:

* [X] Run `make lint`
* [X] Run `make test`
* [ ] Added tests (if applicable)
@DaniPopes DaniPopes deleted the alexey/uint-repr branch February 3, 2026 03:43
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