Skip to content

perf(levm): use specialized PUSH1 and PUSH2 implementations #3262

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

Merged
merged 6 commits into from
Jun 23, 2025

Conversation

edg-l
Copy link
Contributor

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

Motivation
According to stats from @azteca1998 PUSH2 and PUSH1 are widely used:

Loaded 903636264 rows (3447.10MiB)
Stats (of 903636264 records):
  0xf1: count=   730979  t_min=  2278  t_max=1512728  t_avg=110877.43  t_acc=81049072024  CALL
  0x61: count=131856777  t_min=   136  t_max= 549032  t_avg=   189.29  t_acc=24959614846  PUSH2
  0x56: count= 78745029  t_min=   170  t_max=1488792  t_avg=   243.75  t_acc=19194034756  JUMP
  0x60: count= 86327863  t_min=   136  t_max= 837080  t_avg=   199.78  t_acc=17246262544  PUSH1
  0x5b: count=107216057  t_min=   102  t_max= 267308  t_avg=   159.43  t_acc=17093508806  JUMPDEST
  0x50: count= 86546732  t_min=   102  t_max= 353260  t_avg=   174.49  t_acc=15101132640  POP
  0x57: count= 53096953  t_min=   102  t_max=1382576  t_avg=   233.40  t_acc=12393069292  JUMPI
  0x81: count= 55585321  t_min=   102  t_max= 267410  t_avg=   192.79  t_acc=10716509980  DUP2
  0x01: count= 56493418  t_min=   102  t_max=1431060  t_avg=   189.52  t_acc=10706399944  ADD
  0x91: count= 31380921  t_min=   102  t_max= 146030  t_avg=   205.38  t_acc= 6444862520  SWAP2

Furthermore i keep seeing U256::from_big_endian taking quite some time on samply so I made specialized PUSH1 and PUSH2 implementations that avoid that, also using fixed size arrays.

Benchmarks:

Hoodi 11k:

main 9m10.471s
pr 8m25.933s

Description

Closes #issue_number

Benchmark Results Comparison

Benchmark Results: Factorial

Command Mean [ms] Min [ms] Max [ms] Relative
levm_Factorial_pr 634.2 ± 7.3 629.6 654.2 2.71 ± 0.04
levm_Factorial 726.1 ± 5.2 722.5 740.1 3.11 ± 0.03
levm_FactorialRecursive_pr 3.567 ± 0.021 3.541 3.604 2.22 ± 0.05
levm_FactorialRecursive 3.828 ± 0.035 3.775 3.889 2.39 ± 0.03
levm_Fibonacci_pr 629.2 ± 6.4 625.7 646.9 2.99 ± 0.03
levm_Fibonacci 727.7 ± 6.5 722.3 743.9 3.47 ± 0.03
levm_ManyHashes_pr 14.9 ± 0.2 14.7 15.3 1.70 ± 0.03
levm_ManyHashes 16.3 ± 0.1 16.2 16.4 1.87 ± 0.02
levm_BubbleSort_pr 5.065 ± 0.023 5.034 5.107 1.58 ± 0.01
levm_BubbleSort 5.508 ± 0.035 5.489 5.603 1.71 ± 0.02
levm_ERC20Transfer_pr 461.5 ± 1.3 459.7 463.4 1.87 ± 0.03
levm_ERC20Transfer 487.9 ± 2.4 484.1 491.0 1.99 ± 0.01
levm_ERC20Mint_pr 306.8 ± 8.9 300.1 328.5 2.22 ± 0.07
levm_ERC20Mint 320.1 ± 1.5 317.9 322.6 2.31 ± 0.05
levm_ERC20Approval_pr 1.779 ± 0.023 1.763 1.838 1.69 ± 0.02
levm_ERC20Approval 1.850 ± 0.011 1.837 1.873 1.76 ± 0.02

image

According to the samply this makes op_push nearly negligible (from 30% to 0%)

Copy link

Lines of code report

Total lines added: 39
Total lines removed: 0
Total lines changed: 39

Detailed view
+---------------------------------------------------+-------+------+
| File                                              | Lines | Diff |
+---------------------------------------------------+-------+------+
| ethrex/crates/vm/levm/src/execution_handlers.rs   | 208   | +2   |
+---------------------------------------------------+-------+------+
| ethrex/crates/vm/levm/src/opcode_handlers/push.rs | 78    | +37  |
+---------------------------------------------------+-------+------+

Copy link

github-actions bot commented Jun 23, 2025

Benchmark Results Comparison

PR Results

Benchmark Results: Factorial

Command Mean [ms] Min [ms] Max [ms] Relative
revm_Factorial 234.1 ± 1.5 232.2 237.1 1.00
levm_Factorial 673.3 ± 5.4 668.1 683.9 2.88 ± 0.03

Benchmark Results: Factorial - Recursive

Command Mean [s] Min [s] Max [s] Relative
revm_FactorialRecursive 1.616 ± 0.038 1.534 1.678 1.00
levm_FactorialRecursive 3.634 ± 0.025 3.606 3.678 2.25 ± 0.05

Benchmark Results: Fibonacci

Command Mean [ms] Min [ms] Max [ms] Relative
revm_Fibonacci 208.9 ± 1.4 205.9 210.5 1.00
levm_Fibonacci 675.0 ± 1.7 673.6 679.1 3.23 ± 0.02

Benchmark Results: ManyHashes

Command Mean [ms] Min [ms] Max [ms] Relative
revm_ManyHashes 9.0 ± 0.1 8.8 9.2 1.00
levm_ManyHashes 15.0 ± 0.1 14.9 15.2 1.67 ± 0.03

Benchmark Results: BubbleSort

Command Mean [s] Min [s] Max [s] Relative
revm_BubbleSort 3.191 ± 0.022 3.170 3.222 1.00
levm_BubbleSort 5.162 ± 0.047 5.118 5.282 1.62 ± 0.02

Benchmark Results: ERC20 - Transfer

Command Mean [ms] Min [ms] Max [ms] Relative
revm_ERC20Transfer 244.1 ± 1.5 242.5 246.6 1.00
levm_ERC20Transfer 474.9 ± 4.9 468.8 484.0 1.95 ± 0.02

Benchmark Results: ERC20 - Mint

Command Mean [ms] Min [ms] Max [ms] Relative
revm_ERC20Mint 136.7 ± 0.8 135.6 138.4 1.00
levm_ERC20Mint 304.2 ± 2.8 299.9 310.2 2.23 ± 0.02

Benchmark Results: ERC20 - Approval

Command Mean [s] Min [s] Max [s] Relative
revm_ERC20Approval 1.062 ± 0.084 1.032 1.303 1.00
levm_ERC20Approval 1.787 ± 0.006 1.781 1.797 1.68 ± 0.13

Main Results

Benchmark Results: Factorial

Command Mean [ms] Min [ms] Max [ms] Relative
revm_Factorial 234.0 ± 6.6 230.6 252.7 1.00
levm_Factorial 718.6 ± 5.2 715.2 732.3 3.07 ± 0.09

Benchmark Results: Factorial - Recursive

Command Mean [s] Min [s] Max [s] Relative
revm_FactorialRecursive 1.588 ± 0.039 1.511 1.640 1.00
levm_FactorialRecursive 3.826 ± 0.037 3.784 3.891 2.41 ± 0.06

Benchmark Results: Fibonacci

Command Mean [ms] Min [ms] Max [ms] Relative
revm_Fibonacci 207.3 ± 0.4 206.4 207.8 1.00
levm_Fibonacci 726.3 ± 5.5 722.0 740.9 3.50 ± 0.03

Benchmark Results: ManyHashes

Command Mean [ms] Min [ms] Max [ms] Relative
revm_ManyHashes 8.7 ± 0.1 8.6 8.8 1.00
levm_ManyHashes 15.8 ± 0.1 15.6 15.9 1.81 ± 0.02

Benchmark Results: BubbleSort

Command Mean [s] Min [s] Max [s] Relative
revm_BubbleSort 3.200 ± 0.025 3.172 3.258 1.00
levm_BubbleSort 5.384 ± 0.041 5.350 5.480 1.68 ± 0.02

Benchmark Results: ERC20 - Transfer

Command Mean [ms] Min [ms] Max [ms] Relative
revm_ERC20Transfer 243.7 ± 2.6 241.8 248.6 1.00
levm_ERC20Transfer 492.7 ± 3.4 489.1 500.0 2.02 ± 0.03

Benchmark Results: ERC20 - Mint

Command Mean [ms] Min [ms] Max [ms] Relative
revm_ERC20Mint 136.9 ± 0.7 136.1 138.4 1.00
levm_ERC20Mint 321.9 ± 4.0 318.1 329.0 2.35 ± 0.03

Benchmark Results: ERC20 - Approval

Command Mean [s] Min [s] Max [s] Relative
revm_ERC20Approval 1.062 ± 0.043 1.040 1.184 1.00
levm_ERC20Approval 1.864 ± 0.012 1.850 1.878 1.75 ± 0.07

@edg-l edg-l marked this pull request as ready for review June 23, 2025 09:40
@edg-l edg-l requested a review from a team as a code owner June 23, 2025 09:40
Copy link
Collaborator

@Arkenan Arkenan left a comment

Choose a reason for hiding this comment

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

Approved with a comment

Copy link

github-actions bot commented Jun 23, 2025

Benchmark Block Execution Results Comparison Against Main

Command Mean [s] Min [s] Max [s] Relative
base 227.127 ± 0.927 225.807 228.843 1.01 ± 0.01
head 225.031 ± 0.782 224.062 226.714 1.00

@edg-l edg-l enabled auto-merge June 23, 2025 13:05
@edg-l edg-l added this pull request to the merge queue Jun 23, 2025
Merged via the queue into main with commit bca73af Jun 23, 2025
33 of 36 checks passed
@edg-l edg-l deleted the improve_push1_2 branch June 23, 2025 13:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants