Skip to content

Conversation

SDartayet
Copy link
Contributor

@SDartayet SDartayet commented Oct 3, 2025

Motivation

Cleaning up our code and improving it's performance. This PR is part of a broader campaign to remove clones from our code.

Description

This PR removes most of the .clone() calls from the types and utils of the common crate. Those clones that couldn't be removed are justified with an // ok-clone comment

Part of #4668

Copy link

github-actions bot commented Oct 3, 2025

Lines of code report

Total lines added: 47
Total lines removed: 56
Total lines changed: 103

Detailed view
+--------------------------------------------------------+-------+------+
| File                                                   | Lines | Diff |
+--------------------------------------------------------+-------+------+
| ethrex/crates/common/serde_utils.rs                    | 575   | -36  |
+--------------------------------------------------------+-------+------+
| ethrex/crates/common/types/blobs_bundle.rs             | 369   | +1   |
+--------------------------------------------------------+-------+------+
| ethrex/crates/common/types/transaction.rs              | 2821  | -16  |
+--------------------------------------------------------+-------+------+
| ethrex/crates/networking/rpc/engine/payload.rs         | 695   | +8   |
+--------------------------------------------------------+-------+------+
| ethrex/crates/vm/backends/levm/mod.rs                  | 459   | -2   |
+--------------------------------------------------------+-------+------+
| ethrex/crates/vm/levm/src/environment.rs               | 92    | -1   |
+--------------------------------------------------------+-------+------+
| ethrex/crates/vm/levm/src/hooks/default_hook.rs        | 349   | +2   |
+--------------------------------------------------------+-------+------+
| ethrex/tooling/ef_tests/state/runner/levm_runner.rs    | 478   | +23  |
+--------------------------------------------------------+-------+------+
| ethrex/tooling/ef_tests/state/runner/mod.rs            | 278   | +2   |
+--------------------------------------------------------+-------+------+
| ethrex/tooling/ef_tests/state/runner/revm_runner.rs    | 681   | +10  |
+--------------------------------------------------------+-------+------+
| ethrex/tooling/ef_tests/state_v2/src/modules/error.rs  | 10    | +1   |
+--------------------------------------------------------+-------+------+
| ethrex/tooling/ef_tests/state_v2/src/modules/runner.rs | 220   | -1   |
+--------------------------------------------------------+-------+------+

Copy link

github-actions bot commented Oct 3, 2025

Benchmark Results Comparison

No significant difference was registered for any benchmark run.

Detailed Results

Benchmark Results: BubbleSort

Command Mean [s] Min [s] Max [s] Relative
main_revm_BubbleSort 4.735 ± 0.021 4.710 4.772 1.02 ± 0.01
main_levm_BubbleSort 4.682 ± 0.107 4.632 4.983 1.01 ± 0.02
pr_revm_BubbleSort 4.724 ± 0.017 4.699 4.752 1.02 ± 0.01
pr_levm_BubbleSort 4.638 ± 0.018 4.619 4.680 1.00

Benchmark Results: ERC20Approval

Command Mean [s] Min [s] Max [s] Relative
main_revm_ERC20Approval 1.548 ± 0.004 1.542 1.556 1.00
main_levm_ERC20Approval 1.632 ± 0.019 1.621 1.685 1.05 ± 0.01
pr_revm_ERC20Approval 1.563 ± 0.009 1.554 1.586 1.01 ± 0.01
pr_levm_ERC20Approval 1.635 ± 0.006 1.628 1.644 1.06 ± 0.00

Benchmark Results: ERC20Mint

Command Mean [ms] Min [ms] Max [ms] Relative
main_revm_ERC20Mint 187.9 ± 5.5 184.1 203.3 1.00 ± 0.03
main_levm_ERC20Mint 199.1 ± 4.9 196.7 212.9 1.06 ± 0.03
pr_revm_ERC20Mint 187.3 ± 0.8 186.2 188.8 1.00
pr_levm_ERC20Mint 198.5 ± 1.7 197.2 201.4 1.06 ± 0.01

Benchmark Results: ERC20Transfer

Command Mean [ms] Min [ms] Max [ms] Relative
main_revm_ERC20Transfer 357.6 ± 1.9 354.8 360.7 1.00
main_levm_ERC20Transfer 382.7 ± 2.7 379.5 389.0 1.07 ± 0.01
pr_revm_ERC20Transfer 362.3 ± 15.0 356.6 405.0 1.01 ± 0.04
pr_levm_ERC20Transfer 383.8 ± 1.2 382.0 385.9 1.07 ± 0.01

Benchmark Results: Factorial

Command Mean [ms] Min [ms] Max [ms] Relative
main_revm_Factorial 241.3 ± 4.4 238.1 249.2 1.00 ± 0.03
main_levm_Factorial 287.3 ± 9.5 282.9 314.2 1.19 ± 0.05
pr_revm_Factorial 240.5 ± 4.7 237.5 251.0 1.00
pr_levm_Factorial 288.8 ± 21.6 280.1 350.0 1.20 ± 0.09

Benchmark Results: FactorialRecursive

Command Mean [s] Min [s] Max [s] Relative
main_revm_FactorialRecursive 1.734 ± 0.034 1.697 1.789 1.00
main_levm_FactorialRecursive 8.712 ± 0.063 8.546 8.756 5.02 ± 0.10
pr_revm_FactorialRecursive 1.747 ± 0.066 1.681 1.911 1.01 ± 0.04
pr_levm_FactorialRecursive 8.898 ± 0.099 8.775 9.109 5.13 ± 0.11

Benchmark Results: Fibonacci

Command Mean [ms] Min [ms] Max [ms] Relative
main_revm_Fibonacci 211.4 ± 5.8 208.7 227.9 1.00
main_levm_Fibonacci 251.0 ± 1.7 249.3 255.7 1.19 ± 0.03
pr_revm_Fibonacci 212.5 ± 6.5 209.8 230.9 1.01 ± 0.04
pr_levm_Fibonacci 252.4 ± 4.4 249.9 264.7 1.19 ± 0.04

Benchmark Results: FibonacciRecursive

Command Mean [ms] Min [ms] Max [ms] Relative
main_revm_FibonacciRecursive 915.3 ± 8.9 905.2 929.3 1.00
main_levm_FibonacciRecursive 1033.2 ± 3.2 1027.3 1038.7 1.13 ± 0.01
pr_revm_FibonacciRecursive 921.7 ± 4.7 914.0 928.2 1.01 ± 0.01
pr_levm_FibonacciRecursive 1042.0 ± 20.4 1026.7 1096.4 1.14 ± 0.02

Benchmark Results: ManyHashes

Command Mean [ms] Min [ms] Max [ms] Relative
main_revm_ManyHashes 12.4 ± 0.1 12.3 12.5 1.00
main_levm_ManyHashes 13.8 ± 0.1 13.7 14.0 1.12 ± 0.01
pr_revm_ManyHashes 12.5 ± 0.1 12.4 12.7 1.01 ± 0.01
pr_levm_ManyHashes 13.8 ± 0.1 13.7 14.0 1.11 ± 0.01

Benchmark Results: MstoreBench

Command Mean [ms] Min [ms] Max [ms] Relative
main_revm_MstoreBench 268.3 ± 5.1 263.9 277.0 1.01 ± 0.03
main_levm_MstoreBench 756.9 ± 1.9 753.6 759.3 2.84 ± 0.06
pr_revm_MstoreBench 266.5 ± 5.2 262.4 276.8 1.00
pr_levm_MstoreBench 754.6 ± 1.1 753.0 755.9 2.83 ± 0.06

Benchmark Results: Push

Command Mean [ms] Min [ms] Max [ms] Relative
main_revm_Push 299.4 ± 2.0 298.0 305.0 1.00
main_levm_Push 831.2 ± 2.6 828.3 837.2 2.78 ± 0.02
pr_revm_Push 299.8 ± 1.2 298.4 302.4 1.00 ± 0.01
pr_levm_Push 828.5 ± 1.3 827.1 831.6 2.77 ± 0.02

Benchmark Results: SstoreBench_no_opt

Command Mean [ms] Min [ms] Max [ms] Relative
main_revm_SstoreBench_no_opt 218.7 ± 0.8 217.6 219.9 2.35 ± 0.04
main_levm_SstoreBench_no_opt 93.1 ± 1.6 90.1 94.5 1.00
pr_revm_SstoreBench_no_opt 218.4 ± 1.1 217.1 220.5 2.34 ± 0.04
pr_levm_SstoreBench_no_opt 94.5 ± 2.9 91.3 102.0 1.02 ± 0.04

@SDartayet SDartayet changed the title Remove clones from common chore(l1): remove clones from common Oct 6, 2025
@github-actions github-actions bot added the L1 Ethereum client label Oct 6, 2025
@SDartayet SDartayet changed the title chore(l1): remove clones from common chore(l1): remove/justify clones from common Oct 6, 2025
@SDartayet SDartayet marked this pull request as ready for review October 6, 2025 21:24
@SDartayet SDartayet requested a review from a team as a code owner October 6, 2025 21:24
@ethrex-project-sync ethrex-project-sync bot moved this to In Review in ethrex_l1 Oct 6, 2025
Co-authored-by: fmoletta <[email protected]>
Comment on lines +201 to +210
let tx = if authorization_list.is_some() {
Transaction::EIP7702Transaction(EIP7702Transaction {
to: match test_tx.to {
TxKind::Call(to) => to,
TxKind::Create => return Err(EFTestRunnerError::EIP7702ShouldNotBeCreateType),
},
value: test_tx.value,
data: test_tx.data.clone(),
access_list,
authorization_list: list,
access_list: access_list,
authorization_list: authorization_list.unwrap(),
Copy link
Contributor

Choose a reason for hiding this comment

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

Why was this change needed?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ah, that was because I removed the blob hashes field from the environment (since it required cloning the blob hashes from the transaction). The way the runner worked was that for EIP4844 transactions, it encoded them as EIP1599 txs and then injected the blob parameters via the environment. Because this would cause tests to fail now the environment didn't have the blob hashes, I had to add some extra logic to build the test transaction as an EIP4844 one when appropriate

Copy link
Contributor

Choose a reason for hiding this comment

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

Makes sense, I wonder if we can keep the match/ use an if let Some so we don't have to unwrap the authorization_list

let fork_id = ForkId::new(
chain_config,
genesis_header.clone(),
genesis_header.clone(), // ok-clone: value is needed later, clone is in test
Copy link
Collaborator

Choose a reason for hiding this comment

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

I don't think we have to justify clones in tests

@SDartayet SDartayet force-pushed the remove-clones-from-common branch from c3e53f4 to ff04834 Compare October 8, 2025 22:47
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

L1 Ethereum client

Projects

Status: In Review

Development

Successfully merging this pull request may close these issues.

3 participants