Skip to content

chore(l1): add rlp encode benches #5413

Closed
edg-l wants to merge 26 commits into
mainfrom
rlp_benches_encode
Closed

chore(l1): add rlp encode benches #5413
edg-l wants to merge 26 commits into
mainfrom
rlp_benches_encode

Conversation

@edg-l

@edg-l edg-l commented Nov 25, 2025

Copy link
Copy Markdown
Contributor

Adds the encoding benches for rlp

Part of #5411

@github-actions github-actions Bot added the L1 Ethereum client label Nov 25, 2025
@github-actions

github-actions Bot commented Nov 25, 2025

Copy link
Copy Markdown

Lines of code report

Total lines added: 1288
Total lines removed: 0
Total lines changed: 1288

Detailed view
+--------------------------------------------+-------+-------+
| File                                       | Lines | Diff  |
+--------------------------------------------+-------+-------+
| ethrex/crates/common/rlp/benches/decode.rs | 30    | +30   |
+--------------------------------------------+-------+-------+
| ethrex/crates/common/rlp/benches/encode.rs | 1258  | +1258 |
+--------------------------------------------+-------+-------+

@edg-l edg-l marked this pull request as ready for review November 26, 2025 08:43
@edg-l edg-l requested a review from a team as a code owner November 26, 2025 08:43
@ethrex-project-sync ethrex-project-sync Bot moved this to In Review in ethrex_l1 Nov 26, 2025
Comment thread crates/common/rlp/benches/encode.rs Outdated
Comment thread crates/common/rlp/benches/encode.rs
Comment thread crates/common/rlp/benches/encode.rs
@edg-l edg-l changed the base branch from rlp_benches_base to main November 28, 2025 07:21
@github-actions

github-actions Bot commented Dec 1, 2025

Copy link
Copy Markdown

RLP Bench Results

Bench output
basic_types/encode_int_list_len_10
----------------------------------
base     1.00      58.6±1.43ns  162.8 MElem/sec
new      1.00      58.6±1.43ns  162.8 MElem/sec

basic_types/encode_int_list_len_100
-----------------------------------
base     1.00     566.4±8.04ns  168.4 MElem/sec
new      1.00     566.4±8.04ns  168.4 MElem/sec

basic_types/encode_int_list_len_1000
------------------------------------
base     1.00       5.5±0.05µs  173.3 MElem/sec
new      1.00       5.5±0.05µs  173.3 MElem/sec

basic_types/encode_string_len_5
-------------------------------
base     1.00      44.8±0.46µs  212.9 MElem/sec
new      1.00      44.8±0.46µs  212.9 MElem/sec

basic_types/encode_string_len_500
---------------------------------
base     1.00   1201.2±74.08µs  7.9 MElem/sec
new      1.00   1201.2±74.08µs  7.9 MElem/sec

basic_types/encode_string_len_60
--------------------------------
base     1.00     121.9±3.03µs  78.2 MElem/sec
new      1.00     121.9±3.03µs  78.2 MElem/sec

basic_types/encode_string_list_len_10
-------------------------------------
base     1.00      67.5±3.19ns  141.3 MElem/sec
new      1.00      67.5±3.19ns  141.3 MElem/sec

basic_types/encode_string_list_len_100
--------------------------------------
base     1.00     537.8±8.79ns  177.3 MElem/sec
new      1.00     537.8±8.79ns  177.3 MElem/sec

basic_types/encode_string_list_len_1000
---------------------------------------
base     1.00       5.2±0.09µs  184.4 MElem/sec
new      1.00       5.2±0.09µs  184.4 MElem/sec

basic_types/encode_u128_random_seeded
-------------------------------------
base     1.00       7.1±0.01ms  134.4 MElem/sec
new      1.00       7.1±0.01ms  134.4 MElem/sec

basic_types/encode_u16_random_seeded
------------------------------------
base     1.00       4.7±0.07ms  205.0 MElem/sec
new      1.00       4.7±0.07ms  205.0 MElem/sec

basic_types/encode_u256_random_seeded
-------------------------------------
base     1.00       5.6±0.07ms  171.3 MElem/sec
new      1.00       5.6±0.07ms  171.3 MElem/sec

basic_types/encode_u32_random_seeded
------------------------------------
base     1.00       5.0±0.02ms  190.5 MElem/sec
new      1.00       5.0±0.02ms  190.5 MElem/sec

basic_types/encode_u64_random_seeded
------------------------------------
base     1.00       4.9±0.02ms  196.4 MElem/sec
new      1.00       4.9±0.02ms  196.4 MElem/sec

basic_types/encode_u8_random_seeded
-----------------------------------
base     1.00    1345.8±1.82µs  708.6 MElem/sec
new      1.00    1345.8±1.82µs  708.6 MElem/sec

common_types/encode_account_info
--------------------------------
base     1.00     116.4±3.93ns  8.2 MElem/sec
new      1.00     116.4±3.93ns  8.2 MElem/sec

common_types/encode_account_state
---------------------------------
base     1.00     135.4±4.96ns  7.0 MElem/sec
new      1.00     135.4±4.96ns  7.0 MElem/sec

common_types/encode_blobs_bundle
--------------------------------
base     1.00      94.1±0.59µs  10.4 KElem/sec
new      1.00      94.1±0.59µs  10.4 KElem/sec

common_types/encode_block
-------------------------
base     1.00       6.3±0.18µs  155.5 KElem/sec
new      1.00       6.3±0.18µs  155.5 KElem/sec

common_types/encode_block_header
--------------------------------
base     1.00    550.0±17.88ns  1775.7 KElem/sec
new      1.00    550.0±17.88ns  1775.7 KElem/sec

common_types/encode_encoded_requests
------------------------------------
base     1.00      18.0±1.34ns  53.1 MElem/sec
new      1.00      18.0±1.34ns  53.1 MElem/sec

common_types/encode_fork_id
---------------------------
base     1.00      63.9±2.30ns  14.9 MElem/sec
new      1.00      63.9±2.30ns  14.9 MElem/sec

common_types/encode_log
-----------------------
base     1.00     231.3±7.94ns  4.1 MElem/sec
new      1.00     231.3±7.94ns  4.1 MElem/sec

common_types/encode_receipt
---------------------------
base     1.00   1103.0±23.76ns  885.4 KElem/sec
new      1.00   1103.0±23.76ns  885.4 KElem/sec

common_types/encode_receipt_with_bloom
--------------------------------------
base     1.00   1198.0±15.16ns  815.2 KElem/sec
new      1.00   1198.0±15.16ns  815.2 KElem/sec

common_types/encode_withdrawals
-------------------------------
base     1.00     117.9±5.79ns  8.1 MElem/sec
new      1.00     117.9±5.79ns  8.1 MElem/sec

networking_p2p/encode_account_range_unit
----------------------------------------
base     1.00     269.4±9.48ns  3.5 MElem/sec
new      1.00     269.4±9.48ns  3.5 MElem/sec

networking_p2p/encode_account_state_slim
----------------------------------------
base     1.00     155.7±2.47ns  6.1 MElem/sec
new      1.00     155.7±2.47ns  6.1 MElem/sec

networking_p2p/encode_capability
--------------------------------
base     1.00      36.4±1.30ns  26.2 MElem/sec
new      1.00      36.4±1.30ns  26.2 MElem/sec

networking_p2p/encode_endpoint
------------------------------
base     1.00      60.8±3.17ns  15.7 MElem/sec
new      1.00      60.8±3.17ns  15.7 MElem/sec

networking_p2p/encode_enr_request_message
-----------------------------------------
base     1.00      38.2±2.55ns  25.0 MElem/sec
new      1.00      38.2±2.55ns  25.0 MElem/sec

networking_p2p/encode_find_node_message
---------------------------------------
base     1.00     127.9±2.98ns  7.5 MElem/sec
new      1.00     127.9±2.98ns  7.5 MElem/sec

networking_p2p/encode_neighbors_message
---------------------------------------
base     1.00    605.0±12.69ns  1614.0 KElem/sec
new      1.00    605.0±12.69ns  1614.0 KElem/sec

networking_p2p/encode_node
--------------------------
base     1.00     114.1±3.26ns  8.4 MElem/sec
new      1.00     114.1±3.26ns  8.4 MElem/sec

networking_p2p/encode_node_record
---------------------------------
base     1.00     226.9±2.65ns  4.2 MElem/sec
new      1.00     226.9±2.65ns  4.2 MElem/sec

networking_p2p/encode_ping_message
----------------------------------
base     1.00     221.7±4.89ns  4.3 MElem/sec
new      1.00     221.7±4.89ns  4.3 MElem/sec

networking_p2p/encode_storage_slot
----------------------------------
base     1.00     120.3±3.51ns  7.9 MElem/sec
new      1.00     120.3±3.51ns  7.9 MElem/sec

transactions/encode_call
------------------------
base     1.00       3.7±0.01ns  255.6 MElem/sec
new      1.00       3.7±0.01ns  255.6 MElem/sec

transactions/encode_create
--------------------------
base     1.00       2.2±0.02ns  434.4 MElem/sec
new      1.00       2.2±0.02ns  434.4 MElem/sec

transactions/encode_eip1559_transaction
---------------------------------------
base     1.00    358.9±11.18ns  2.7 MElem/sec
new      1.00    358.9±11.18ns  2.7 MElem/sec

transactions/encode_eip2930_transaction
---------------------------------------
base     1.00     353.4±9.67ns  2.7 MElem/sec
new      1.00     353.4±9.67ns  2.7 MElem/sec

transactions/encode_eip4844_transaction
---------------------------------------
base     1.00    413.4±13.93ns  2.3 MElem/sec
new      1.00    413.4±13.93ns  2.3 MElem/sec

transactions/encode_eip7702_transaction
---------------------------------------
base     1.00    647.9±17.01ns  1507.3 KElem/sec
new      1.00    647.9±17.01ns  1507.3 KElem/sec

transactions/encode_fee_token_transaction
-----------------------------------------
base     1.00    417.9±11.72ns  2.3 MElem/sec
new      1.00    417.9±11.72ns  2.3 MElem/sec

transactions/encode_legacy_transaction
--------------------------------------
base     1.00     159.1±9.50ns  6.0 MElem/sec
new      1.00     159.1±9.50ns  6.0 MElem/sec

transactions/encode_mempool_transaction
---------------------------------------
base     1.00    518.9±10.22ns  1882.0 KElem/sec
new      1.00    518.9±10.22ns  1882.0 KElem/sec

transactions/encode_p2p_transaction
-----------------------------------
base     1.00      11.3±0.12µs  86.5 KElem/sec
new      1.00      11.3±0.12µs  86.5 KElem/sec

transactions/encode_privileged_l2_transaction
---------------------------------------------
base     1.00    373.1±14.06ns  2.6 MElem/sec
new      1.00    373.1±14.06ns  2.6 MElem/sec

transactions/encode_wrapped_eip4844_transaction
-----------------------------------------------
base     1.00      17.3±0.11µs  56.5 KElem/sec
new      1.00      17.3±0.11µs  56.5 KElem/sec

trie/encode_branch_node
-----------------------
base     1.00      88.7±2.28ns  10.8 MElem/sec
new      1.00      88.7±2.28ns  10.8 MElem/sec

trie/encode_extension_node
--------------------------
base     1.00     121.2±2.22ns  7.9 MElem/sec
new      1.00     121.2±2.22ns  7.9 MElem/sec

trie/encode_leaf_node
---------------------
base     1.00     115.7±1.44ns  8.2 MElem/sec
new      1.00     115.7±1.44ns  8.2 MElem/sec

trie/encode_nibbles_len_129
---------------------------
base     1.00    469.8±14.03ns  2.0 MElem/sec
new      1.00    469.8±14.03ns  2.0 MElem/sec

trie/encode_nibbles_len_130
---------------------------
base     1.00     473.5±8.23ns  2.0 MElem/sec
new      1.00     473.5±8.23ns  2.0 MElem/sec

trie/encode_nibbles_len_500
---------------------------
base     1.00   1231.9±10.02ns  792.7 KElem/sec
new      1.00   1231.9±10.02ns  792.7 KElem/sec

trie/encode_nibbles_len_65
--------------------------
base     1.00     310.5±6.26ns  3.1 MElem/sec
new      1.00     310.5±6.26ns  3.1 MElem/sec

trie/encode_node_hash_hashed
----------------------------
base     1.00      68.1±3.41ns  14.0 MElem/sec
new      1.00      68.1±3.41ns  14.0 MElem/sec

trie/encode_node_hash_inline
----------------------------
base     1.00      45.6±4.05ns  20.9 MElem/sec
new      1.00      45.6±4.05ns  20.9 MElem/sec


- name: Run bench main
continue-on-error: true
run: make bench-rlp

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

The benchmark comparison won't work as-is. Two problems:

  1. cargo bench (via make bench-rlp) without --save-baseline writes to the default criterion baseline. The second run on the PR branch overwrites the first run's results, so there's nothing to compare.
  2. critcmp --list (line 50) only lists the names of saved baselines — it doesn't produce a comparison table.

Fix: save each run to a named baseline and compare them:

- name: Run bench main
  continue-on-error: true
  run: cd ./crates/common/rlp && cargo bench -- --save-baseline main

# ... checkout PR ...

- name: Run bench PR
  run: cd ./crates/common/rlp && cargo bench -- --save-baseline pr

- name: Save comparison
  run: |
    {
      printf '## RLP Bench Results\n\n```\n'
      critcmp main pr
      printf '\n```\n'
    } > result.md

Comment thread crates/common/Cargo.toml

[dev-dependencies]
hex-literal.workspace = true
ethrex-p2p.workspace = true

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

The benchmarks live in ethrex-rlp (crates/common/rlp/), not in ethrex-common. This dev-dependency seems unnecessary here and creates a circular dev-dependency (ethrex-commonethrex-p2pethrex-common). While Cargo allows circular dev-deps, it adds compilation overhead without benefit. Consider removing this and keeping the ethrex-p2p dev-dep only in crates/common/rlp/Cargo.toml where the benches actually are.

fn bench_encode_blobs_bundle(c: &mut Criterion) {
let mut group = c.benchmark_group("common_types");

let blobs_bundle = black_box(BlobsBundle {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

nit: This BlobsBundle has 4 blobs but only 1 commitment and 1 proof. In practice these counts must always match (one commitment + one proof per blob). Might want to use matching counts so the benchmark encodes a realistic structure:

blobs: vec![[6u8; BYTES_PER_BLOB]; 4],
commitments: vec![[0x78u8; 48]; 4],
proofs: vec![[0x78u8; 48]; 4],

@github-project-automation github-project-automation Bot moved this from In Review to In Progress in ethrex_l1 Feb 19, 2026
@edg-l edg-l closed this Mar 16, 2026
@github-project-automation github-project-automation Bot moved this from In Progress to Done in ethrex_l1 Mar 16, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

L1 Ethereum client

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

5 participants