-
Notifications
You must be signed in to change notification settings - Fork 120
perf(l1): improve rlp encoding #5350
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
Lines of code reportTotal lines added: Detailed view |
Benchmark Block Execution Results Comparison Against Main
|
Benchmark for ad3c222Click to view benchmark
|
Benchmark for 4ad8835Click to view benchmark
|
Benchmark for c43b4ffClick to view benchmark
|
Benchmark for 28969a4Click to view benchmark
|
Benchmark for 2383de2Click to view benchmark
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
This PR improves RLP encoding performance by eliminating extra allocations and loops during encoding. The key changes include:
- Refactored integer encoding to use a single-pass loop instead of multiple passes
- Added specialized
length()methods to all RLP-encodable types to avoid re-encoding when calculating lengths - Removed unnecessary
ArrayVecusage in favor of direct byte array manipulation - Introduced helper functions
list_length()andbytes_length()for calculating encoded lengths without allocation
Reviewed Changes
Copilot reviewed 12 out of 13 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
| crates/common/rlp/encode.rs | Core RLP encoding improvements: refactored impl_encode, added list_length/bytes_length helpers, implemented specialized length() methods for all primitive types, removed ArrayVec usage |
| crates/common/types/transaction.rs | Added length() implementations for all transaction types and helper tx_type_byte() methods; contains critical bugs with incorrect transaction type bytes |
| crates/common/types/tx_fields.rs | Added length() and redundant encode_to_vec() methods to AuthorizationTuple |
| crates/common/types/receipt.rs | Added length() implementations for Receipt, ReceiptWithBloom, and Log |
| crates/common/types/block.rs | Added length() implementations for Block, BlockHeader, BlockBody, and Withdrawal |
| crates/common/types/account.rs | Added length() implementations for AccountInfo and AccountState |
| crates/common/types/blobs_bundle.rs | Added length() implementation for BlobsBundle |
| crates/common/types/fork_id.rs | Added length() implementation for ForkId |
| crates/common/types/requests.rs | Added length() implementation for EncodedRequests |
| crates/common/trie/rlp.rs | Added length() implementations for trie nodes (BranchNode, ExtensionNode, LeafNode, Node) |
| crates/common/trie/nibbles.rs | Added compact_length() and compact_first_byte() helper methods, and length() implementation for Nibbles |
| tooling/Cargo.lock | Added lz4-sys dependency (transitive from librocksdb-sys) and removed unused hex dependency from ethrex-vm |
| CHANGELOG.md | Documented the RLP encoding performance improvements |
Comments suppressed due to low confidence (1)
crates/common/types/tx_fields.rs:82
- This
encode_to_vecoverride is redundant. The default implementation in theRLPEncodetrait (lines 65-69 inencode.rs) already does exactly this. Consider removing this method unless there's a specific reason for the override (such as pre-allocating buffer capacity as done inBranchNode).
impl RLPDecode for AuthorizationTuple {
fn decode_unfinished(rlp: &[u8]) -> Result<(Self, &[u8]), RLPDecodeError> {
let decoder = Decoder::new(rlp)?;
let (chain_id, decoder) = decoder.decode_field("chain_id")?;
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Benchmark for 6d8f5b0Click to view benchmark
|
Benchmark for 38d4e9dClick to view benchmark
|
Co-authored-by: Tomás Grüner <47506558+MegaRedHand@users.noreply.github.com>
Co-authored-by: Tomás Grüner <47506558+MegaRedHand@users.noreply.github.com>
Motivation
Each missing length impl in the trait impl meant an extra allocation, this should remove them entirely when encoding
Helps with #4956