Skip to content

perf(core): improve u256 handling, improving PUSH and other opcodes#3332

Merged
Arkenan merged 4 commits into
mainfrom
improve_u256_conversions
Jun 27, 2025
Merged

perf(core): improve u256 handling, improving PUSH and other opcodes#3332
Arkenan merged 4 commits into
mainfrom
improve_u256_conversions

Conversation

@edg-l

@edg-l edg-l commented Jun 26, 2025

Copy link
Copy Markdown
Contributor

Motivation

The function u265::from_big_endian(slice) which is widely used in the codebase can be made faster through more compile time information.

With this change, i could add a constant generic op_push

Benchmarks:

Seems like our current benchmarks don't measure this part of the code, there is no difference in the levm bench, however external opcode benchmarks show a 2-2.5x improvement on PUSH and MSTORE based benches

Description

Closes #3358

@github-actions

github-actions Bot commented Jun 26, 2025

Copy link
Copy Markdown

Lines of code report

Total lines added: 57
Total lines removed: 32
Total lines changed: 89

Detailed view
+----------------------------------------------------+-------+------+
| File                                               | Lines | Diff |
+----------------------------------------------------+-------+------+
| ethrex/crates/common/common.rs                     | 9     | +1   |
+----------------------------------------------------+-------+------+
| ethrex/crates/common/utils.rs                      | 24    | +24  |
+----------------------------------------------------+-------+------+
| ethrex/crates/vm/levm/src/execution_handlers.rs    | 252   | +26  |
+----------------------------------------------------+-------+------+
| ethrex/crates/vm/levm/src/opcode_handlers/block.rs | 126   | +1   |
+----------------------------------------------------+-------+------+
| ethrex/crates/vm/levm/src/opcode_handlers/push.rs  | 46    | -32  |
+----------------------------------------------------+-------+------+
| ethrex/crates/vm/levm/src/precompiles.rs           | 1272  | +2   |
+----------------------------------------------------+-------+------+
| ethrex/crates/vm/levm/src/utils.rs                 | 442   | +3   |
+----------------------------------------------------+-------+------+

@edg-l edg-l added the performance Block execution throughput and performance in general label Jun 26, 2025
@edg-l edg-l changed the title perf(core): Improve u256 handling, improving PUSH and other opcodes perf(core): improve u256 handling, improving PUSH and other opcodes Jun 26, 2025
@github-actions

github-actions Bot commented Jun 26, 2025

Copy link
Copy Markdown

Benchmark Results Comparison

PR Results

Benchmark Results: Factorial

Command Mean [ms] Min [ms] Max [ms] Relative
revm_Factorial 231.1 ± 1.0 229.8 232.5 1.00
levm_Factorial 439.6 ± 2.7 437.2 446.4 1.90 ± 0.01

Benchmark Results: Factorial - Recursive

Command Mean [s] Min [s] Max [s] Relative
revm_FactorialRecursive 1.588 ± 0.018 1.568 1.624 1.00
levm_FactorialRecursive 2.649 ± 0.015 2.619 2.664 1.67 ± 0.02

Benchmark Results: Fibonacci

Command Mean [ms] Min [ms] Max [ms] Relative
revm_Fibonacci 207.6 ± 1.2 206.2 210.4 1.00
levm_Fibonacci 432.2 ± 5.3 428.9 446.0 2.08 ± 0.03

Benchmark Results: ManyHashes

Command Mean [ms] Min [ms] Max [ms] Relative
revm_ManyHashes 8.5 ± 0.1 8.5 8.8 1.00
levm_ManyHashes 13.5 ± 0.1 13.3 13.6 1.58 ± 0.02

Benchmark Results: BubbleSort

Command Mean [s] Min [s] Max [s] Relative
revm_BubbleSort 3.169 ± 0.011 3.156 3.189 1.00
levm_BubbleSort 4.524 ± 0.023 4.492 4.564 1.43 ± 0.01

Benchmark Results: ERC20 - Transfer

Command Mean [ms] Min [ms] Max [ms] Relative
revm_ERC20Transfer 241.4 ± 4.1 237.3 247.5 1.00
levm_ERC20Transfer 411.8 ± 5.0 408.7 425.4 1.71 ± 0.04

Benchmark Results: ERC20 - Mint

Command Mean [ms] Min [ms] Max [ms] Relative
revm_ERC20Mint 136.0 ± 0.5 134.9 136.5 1.00
levm_ERC20Mint 262.7 ± 2.7 260.4 268.7 1.93 ± 0.02

Benchmark Results: ERC20 - Approval

Command Mean [s] Min [s] Max [s] Relative
revm_ERC20Approval 1.037 ± 0.005 1.028 1.041 1.00
levm_ERC20Approval 1.577 ± 0.038 1.559 1.683 1.52 ± 0.04

Main Results

Benchmark Results: Factorial

Command Mean [ms] Min [ms] Max [ms] Relative
revm_Factorial 231.1 ± 1.6 230.2 235.4 1.00
levm_Factorial 468.3 ± 14.0 459.9 505.5 2.03 ± 0.06

Benchmark Results: Factorial - Recursive

Command Mean [s] Min [s] Max [s] Relative
revm_FactorialRecursive 1.538 ± 0.095 1.274 1.599 1.00
levm_FactorialRecursive 2.749 ± 0.035 2.708 2.801 1.79 ± 0.11

Benchmark Results: Fibonacci

Command Mean [ms] Min [ms] Max [ms] Relative
revm_Fibonacci 207.2 ± 0.9 206.4 209.2 1.00
levm_Fibonacci 460.6 ± 5.0 456.9 474.4 2.22 ± 0.03

Benchmark Results: ManyHashes

Command Mean [ms] Min [ms] Max [ms] Relative
revm_ManyHashes 8.6 ± 0.1 8.5 8.7 1.00
levm_ManyHashes 13.4 ± 0.2 13.2 13.8 1.57 ± 0.02

Benchmark Results: BubbleSort

Command Mean [s] Min [s] Max [s] Relative
revm_BubbleSort 3.185 ± 0.030 3.161 3.266 1.00
levm_BubbleSort 4.517 ± 0.025 4.492 4.560 1.42 ± 0.02

Benchmark Results: ERC20 - Transfer

Command Mean [ms] Min [ms] Max [ms] Relative
revm_ERC20Transfer 240.8 ± 6.9 237.3 260.3 1.00
levm_ERC20Transfer 416.4 ± 4.4 412.6 424.5 1.73 ± 0.05

Benchmark Results: ERC20 - Mint

Command Mean [ms] Min [ms] Max [ms] Relative
revm_ERC20Mint 134.1 ± 0.6 132.9 134.7 1.00
levm_ERC20Mint 274.3 ± 32.1 262.2 365.4 2.05 ± 0.24

Benchmark Results: ERC20 - Approval

Command Mean [s] Min [s] Max [s] Relative
revm_ERC20Approval 1.040 ± 0.017 1.023 1.073 1.00
levm_ERC20Approval 1.598 ± 0.007 1.592 1.615 1.54 ± 0.03

Comment thread crates/common/utils.rs
Comment thread crates/vm/levm/src/execution_handlers.rs Outdated
@github-actions

Copy link
Copy Markdown

Benchmark for 178d297

Click to view benchmark
Test Base PR %
block payload building bench 0.2±0.00ns 0.2±0.00ns 0.00%

@github-actions

github-actions Bot commented Jun 26, 2025

Copy link
Copy Markdown

Benchmark Block Execution Results Comparison Against Main

Command Mean [s] Min [s] Max [s] Relative
base 212.315 ± 1.170 210.166 214.646 1.01 ± 0.01
head 211.257 ± 0.740 210.039 212.762 1.00

@edg-l
edg-l marked this pull request as ready for review June 27, 2025 09:30
@edg-l
edg-l requested a review from a team as a code owner June 27, 2025 09:30
@edg-l
edg-l requested a review from Oppen June 27, 2025 09:31
@github-actions

Copy link
Copy Markdown

Benchmark for 371a7fb

Click to view benchmark
Test Base PR %
block payload building bench 0.2±0.00ns 0.2±0.00ns 0.00%

@Arkenan Arkenan left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

LGTM

@Arkenan
Arkenan added this pull request to the merge queue Jun 27, 2025
Merged via the queue into main with commit 2e4bc87 Jun 27, 2025
42 checks passed
@Arkenan
Arkenan deleted the improve_u256_conversions branch June 27, 2025 16:01
d-roak pushed a commit to 1sixtech/ethrex that referenced this pull request Jul 17, 2025
…ambdaclass#3332)

**Motivation**

The function `u265::from_big_endian(slice)` which is widely used in the
codebase can be made faster through more compile time information.

With this change, i could add a constant generic op_push

Benchmarks:

Seems like our current benchmarks don't measure this part of the code,
there is no difference in the levm bench, however external opcode
benchmarks show a 2-2.5x improvement on PUSH and MSTORE based benches

**Description**

<!-- A clear and concise general description of the changes this PR
introduces -->

<!-- Link to issues: Resolves lambdaclass#111, Resolves lambdaclass#222 -->

Closes lambdaclass#3358
pedrobergamini pushed a commit to pedrobergamini/ethrex that referenced this pull request Aug 24, 2025
…ambdaclass#3332)

**Motivation**

The function `u265::from_big_endian(slice)` which is widely used in the
codebase can be made faster through more compile time information.

With this change, i could add a constant generic op_push

Benchmarks:

Seems like our current benchmarks don't measure this part of the code,
there is no difference in the levm bench, however external opcode
benchmarks show a 2-2.5x improvement on PUSH and MSTORE based benches

**Description**

<!-- A clear and concise general description of the changes this PR
introduces -->

<!-- Link to issues: Resolves lambdaclass#111, Resolves lambdaclass#222 -->

Closes lambdaclass#3358
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

performance Block execution throughput and performance in general

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Improve u265::from_big_endian

3 participants