Skip to content

perf(levm): new memory model #3564

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 46 commits into from
Jul 17, 2025
Merged

perf(levm): new memory model #3564

merged 46 commits into from
Jul 17, 2025

Conversation

edg-l
Copy link
Contributor

@edg-l edg-l commented Jul 8, 2025

Motivation

Gas benchmarks show an 23% improvement on opcode based timings and 12% on end to end.
30% improvement in mgas for mstore (before unsafe)

After adding unsafe we see a 30% improvement on top of the mstore improvements and overall general improvements on other opcodes.

Copy link

github-actions bot commented Jul 8, 2025

Lines of code report

Total lines added: 210
Total lines removed: 1
Total lines changed: 211

Detailed view
+------------------------------------------------------------------------+-------+------+
| File                                                                   | Lines | Diff |
+------------------------------------------------------------------------+-------+------+
| ethrex/crates/vm/levm/src/call_frame.rs                                | 293   | +25  |
+------------------------------------------------------------------------+-------+------+
| ethrex/crates/vm/levm/src/execution_handlers.rs                        | 254   | +2   |
+------------------------------------------------------------------------+-------+------+
| ethrex/crates/vm/levm/src/memory.rs                                    | 273   | +92  |
+------------------------------------------------------------------------+-------+------+
| ethrex/crates/vm/levm/src/opcode_handlers/environment.rs               | 308   | +20  |
+------------------------------------------------------------------------+-------+------+
| ethrex/crates/vm/levm/src/opcode_handlers/logging.rs                   | 43    | +2   |
+------------------------------------------------------------------------+-------+------+
| ethrex/crates/vm/levm/src/opcode_handlers/push.rs                      | 45    | -1   |
+------------------------------------------------------------------------+-------+------+
| ethrex/crates/vm/levm/src/opcode_handlers/stack_memory_storage_flow.rs | 279   | +11  |
+------------------------------------------------------------------------+-------+------+
| ethrex/crates/vm/levm/src/opcode_handlers/system.rs                    | 824   | +55  |
+------------------------------------------------------------------------+-------+------+
| ethrex/crates/vm/levm/src/vm.rs                                        | 217   | +3   |
+------------------------------------------------------------------------+-------+------+

Copy link

github-actions bot commented Jul 8, 2025

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 3.192 ± 0.038 3.166 3.295 1.00
main_levm_BubbleSort 4.430 ± 0.013 4.414 4.453 1.39 ± 0.02
pr_revm_BubbleSort 3.208 ± 0.014 3.189 3.231 1.01 ± 0.01
pr_levm_BubbleSort 4.517 ± 0.012 4.498 4.539 1.42 ± 0.02

Benchmark Results: ERC20Approval

Command Mean [s] Min [s] Max [s] Relative
main_revm_ERC20Approval 1.034 ± 0.009 1.022 1.049 1.00
main_levm_ERC20Approval 1.515 ± 0.006 1.506 1.524 1.46 ± 0.01
pr_revm_ERC20Approval 1.057 ± 0.007 1.051 1.073 1.02 ± 0.01
pr_levm_ERC20Approval 1.547 ± 0.005 1.536 1.554 1.50 ± 0.01

Benchmark Results: ERC20Mint

Command Mean [ms] Min [ms] Max [ms] Relative
main_revm_ERC20Mint 137.2 ± 1.1 135.7 139.2 1.00
main_levm_ERC20Mint 254.2 ± 1.8 252.0 257.3 1.85 ± 0.02
pr_revm_ERC20Mint 138.3 ± 1.0 137.5 141.0 1.01 ± 0.01
pr_levm_ERC20Mint 258.9 ± 2.1 255.7 262.9 1.89 ± 0.02

Benchmark Results: ERC20Transfer

Command Mean [ms] Min [ms] Max [ms] Relative
main_revm_ERC20Transfer 239.7 ± 1.5 237.5 242.1 1.00
main_levm_ERC20Transfer 396.5 ± 1.7 394.5 400.0 1.65 ± 0.01
pr_revm_ERC20Transfer 250.8 ± 1.0 248.8 252.0 1.05 ± 0.01
pr_levm_ERC20Transfer 404.2 ± 2.8 400.7 409.7 1.69 ± 0.02

Benchmark Results: Factorial

Command Mean [ms] Min [ms] Max [ms] Relative
main_revm_Factorial 232.6 ± 0.5 231.9 233.5 1.00
main_levm_Factorial 442.9 ± 1.9 441.0 447.0 1.90 ± 0.01
pr_revm_Factorial 239.1 ± 1.0 237.4 240.8 1.03 ± 0.00
pr_levm_Factorial 474.2 ± 28.4 462.9 554.5 2.04 ± 0.12

Benchmark Results: FactorialRecursive

Command Mean [s] Min [s] Max [s] Relative
main_revm_FactorialRecursive 1.638 ± 0.020 1.604 1.670 1.00
main_levm_FactorialRecursive 2.679 ± 0.014 2.657 2.699 1.64 ± 0.02
pr_revm_FactorialRecursive 1.670 ± 0.023 1.642 1.712 1.02 ± 0.02
pr_levm_FactorialRecursive 3.073 ± 0.011 3.056 3.087 1.88 ± 0.02

Benchmark Results: Fibonacci

Command Mean [ms] Min [ms] Max [ms] Relative
main_revm_Fibonacci 208.8 ± 3.0 206.9 217.0 1.00
main_levm_Fibonacci 442.6 ± 2.9 439.2 449.3 2.12 ± 0.03
pr_revm_Fibonacci 212.2 ± 0.7 211.2 213.6 1.02 ± 0.01
pr_levm_Fibonacci 465.6 ± 19.4 455.9 520.4 2.23 ± 0.10

Benchmark Results: FibonacciRecursive

Command Mean [ms] Min [ms] Max [ms] Relative
main_revm_FibonacciRecursive 883.3 ± 13.7 858.1 904.3 1.00
main_levm_FibonacciRecursive 1384.5 ± 11.6 1372.5 1411.5 1.57 ± 0.03
pr_revm_FibonacciRecursive 899.4 ± 9.1 887.0 919.3 1.02 ± 0.02
pr_levm_FibonacciRecursive 1636.0 ± 15.2 1618.7 1674.7 1.85 ± 0.03

Benchmark Results: ManyHashes

Command Mean [ms] Min [ms] Max [ms] Relative
main_revm_ManyHashes 8.7 ± 0.1 8.6 8.8 1.00
main_levm_ManyHashes 13.2 ± 0.2 13.1 13.7 1.52 ± 0.02
pr_revm_ManyHashes 8.9 ± 0.1 8.8 9.1 1.03 ± 0.02
pr_levm_ManyHashes 13.2 ± 0.2 13.0 13.6 1.52 ± 0.02

Benchmark Results: MstoreBench

Command Mean [ms] Min [ms] Max [ms] Relative
main_revm_MstoreBench 269.1 ± 3.8 265.9 279.1 1.00
main_levm_MstoreBench 931.8 ± 3.2 928.9 938.2 3.46 ± 0.05
pr_revm_MstoreBench 275.2 ± 1.9 273.1 278.7 1.02 ± 0.02
pr_levm_MstoreBench 906.4 ± 2.3 902.8 911.2 3.37 ± 0.05

Benchmark Results: Push

Command Mean [ms] Min [ms] Max [ms] Relative
main_revm_Push 299.5 ± 2.7 296.0 304.6 1.00
main_levm_Push 1040.7 ± 9.9 1034.1 1068.3 3.47 ± 0.05
pr_revm_Push 303.3 ± 1.2 302.0 306.2 1.01 ± 0.01
pr_levm_Push 1072.8 ± 6.9 1063.8 1089.8 3.58 ± 0.04

Copy link

github-actions bot commented Jul 8, 2025

Benchmark for 7bf6dbb

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

Copy link

github-actions bot commented Jul 8, 2025

Benchmark for e945949

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

Copy link

github-actions bot commented Jul 8, 2025

Benchmark Results: Factorial

Command Mean [s] Min [s] Max [s] Relative
main_revm_Factorial 314.6 ± 251.7 231.7 1030.9 1.32 ± 1.05
main_levm_Factorial 442.5 ± 1.4 440.5 444.4 1.85 ± 0.01
pr_revm_Factorial 238.9 ± 0.5 237.9 239.4 1.00
Detailed Results

Benchmark Results: BubbleSort

Command Mean [s] Min [s] Max [s] Relative
main_revm_BubbleSort 3.169 ± 0.011 3.159 3.195 1.00
main_levm_BubbleSort 4.426 ± 0.016 4.402 4.450 1.40 ± 0.01
pr_revm_BubbleSort 3.256 ± 0.025 3.234 3.319 1.03 ± 0.01
pr_levm_BubbleSort 4.554 ± 0.046 4.501 4.642 1.44 ± 0.02

Benchmark Results: ERC20Approval

Command Mean [s] Min [s] Max [s] Relative
main_revm_ERC20Approval 1.027 ± 0.004 1.022 1.036 1.00
main_levm_ERC20Approval 1.518 ± 0.010 1.506 1.536 1.48 ± 0.01
pr_revm_ERC20Approval 1.057 ± 0.011 1.046 1.085 1.03 ± 0.01
pr_levm_ERC20Approval 1.599 ± 0.019 1.575 1.631 1.56 ± 0.02

Benchmark Results: ERC20Mint

Command Mean [ms] Min [ms] Max [ms] Relative
main_revm_ERC20Mint 140.0 ± 8.1 135.6 161.3 1.02 ± 0.06
main_levm_ERC20Mint 251.3 ± 3.4 247.7 259.1 1.83 ± 0.03
pr_revm_ERC20Mint 137.3 ± 1.7 136.0 141.8 1.00
pr_levm_ERC20Mint 264.9 ± 2.8 261.0 269.7 1.93 ± 0.03

Benchmark Results: ERC20Transfer

Command Mean [ms] Min [ms] Max [ms] Relative
main_revm_ERC20Transfer 240.2 ± 2.4 238.1 244.8 1.00
main_levm_ERC20Transfer 398.6 ± 3.7 393.7 408.0 1.66 ± 0.02
pr_revm_ERC20Transfer 246.7 ± 0.9 245.8 248.9 1.03 ± 0.01
pr_levm_ERC20Transfer 410.7 ± 1.6 409.0 413.7 1.71 ± 0.02

Benchmark Results: Factorial

Command Mean [ms] Min [ms] Max [ms] Relative
main_revm_Factorial 314.6 ± 251.7 231.7 1030.9 1.32 ± 1.05
main_levm_Factorial 442.5 ± 1.4 440.5 444.4 1.85 ± 0.01
pr_revm_Factorial 238.9 ± 0.5 237.9 239.4 1.00
pr_levm_Factorial 466.2 ± 2.2 464.3 471.9 1.95 ± 0.01

Benchmark Results: FactorialRecursive

Command Mean [s] Min [s] Max [s] Relative
main_revm_FactorialRecursive 1.633 ± 0.040 1.552 1.692 1.00
main_levm_FactorialRecursive 2.707 ± 0.023 2.685 2.759 1.66 ± 0.04
pr_revm_FactorialRecursive 1.672 ± 0.020 1.649 1.713 1.02 ± 0.03
pr_levm_FactorialRecursive 3.106 ± 0.039 3.076 3.192 1.90 ± 0.05

Benchmark Results: Fibonacci

Command Mean [ms] Min [ms] Max [ms] Relative
main_revm_Fibonacci 210.0 ± 4.5 206.3 219.5 1.00
main_levm_Fibonacci 447.0 ± 12.3 437.3 474.4 2.13 ± 0.07
pr_revm_Fibonacci 212.4 ± 0.9 210.6 214.1 1.01 ± 0.02
pr_levm_Fibonacci 458.2 ± 2.2 455.3 461.1 2.18 ± 0.05

Benchmark Results: FibonacciRecursive

Command Mean [ms] Min [ms] Max [ms] Relative
main_revm_FibonacciRecursive 884.7 ± 11.0 865.7 901.3 1.00
main_levm_FibonacciRecursive 1404.1 ± 20.9 1382.7 1448.2 1.59 ± 0.03
pr_revm_FibonacciRecursive 898.6 ± 9.4 877.8 914.3 1.02 ± 0.02
pr_levm_FibonacciRecursive 1660.0 ± 18.7 1647.7 1709.6 1.88 ± 0.03

Benchmark Results: ManyHashes

Command Mean [ms] Min [ms] Max [ms] Relative
main_revm_ManyHashes 8.7 ± 0.1 8.6 8.8 1.00
main_levm_ManyHashes 13.3 ± 0.1 13.2 13.5 1.53 ± 0.02
pr_revm_ManyHashes 8.9 ± 0.1 8.9 9.1 1.03 ± 0.01
pr_levm_ManyHashes 13.2 ± 0.1 13.1 13.4 1.52 ± 0.01

Benchmark Results: MstoreBench

Command Mean [ms] Min [ms] Max [ms] Relative
main_revm_MstoreBench 269.1 ± 2.6 266.3 275.1 1.00
main_levm_MstoreBench 934.2 ± 3.1 930.2 939.7 3.47 ± 0.04
pr_revm_MstoreBench 274.7 ± 3.2 272.7 283.3 1.02 ± 0.02
pr_levm_MstoreBench 965.4 ± 33.9 944.8 1059.0 3.59 ± 0.13

Benchmark Results: Push

Command Mean [ms] Min [ms] Max [ms] Relative
main_revm_Push 298.6 ± 1.7 296.5 301.5 1.00
main_levm_Push 1048.0 ± 5.9 1042.3 1063.6 3.51 ± 0.03
pr_revm_Push 305.6 ± 6.2 302.0 322.1 1.02 ± 0.02
pr_levm_Push 1125.5 ± 10.8 1112.5 1143.6 3.77 ± 0.04

Copy link

github-actions bot commented Jul 8, 2025

Benchmark for fdfda3f

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

Copy link

github-actions bot commented Jul 8, 2025

Benchmark Results: FactorialRecursive

Command Mean [s] Min [s] Max [s] Relative
main_revm_FactorialRecursive 1.630 ± 0.025 1.587 1.668 1.01 ± 0.02
main_levm_FactorialRecursive 2.734 ± 0.016 2.698 2.759 1.69 ± 0.02
pr_levm_FactorialRecursive 6.762 ± 0.033 6.714 6.806 4.18 ± 0.05

Benchmark Results: MstoreBench

Command Mean [s] Min [s] Max [s] Relative
main_revm_MstoreBench 271.3 ± 8.5 266.2 293.4 1.02 ± 0.03
main_levm_MstoreBench 955.7 ± 3.1 951.4 959.7 3.61 ± 0.04
pr_levm_MstoreBench 769.0 ± 2.2 766.8 772.4 2.90 ± 0.03
Detailed Results

Benchmark Results: BubbleSort

Command Mean [s] Min [s] Max [s] Relative
main_revm_BubbleSort 3.173 ± 0.019 3.152 3.200 1.00
main_levm_BubbleSort 4.511 ± 0.027 4.475 4.548 1.42 ± 0.01
pr_revm_BubbleSort 3.194 ± 0.020 3.180 3.246 1.01 ± 0.01
pr_levm_BubbleSort 4.432 ± 0.028 4.397 4.497 1.40 ± 0.01

Benchmark Results: ERC20Approval

Command Mean [s] Min [s] Max [s] Relative
main_revm_ERC20Approval 1.030 ± 0.008 1.023 1.049 1.00
main_levm_ERC20Approval 1.557 ± 0.009 1.550 1.581 1.51 ± 0.01
pr_revm_ERC20Approval 1.064 ± 0.010 1.056 1.084 1.03 ± 0.01
pr_levm_ERC20Approval 1.498 ± 0.016 1.483 1.537 1.45 ± 0.02

Benchmark Results: ERC20Mint

Command Mean [ms] Min [ms] Max [ms] Relative
main_revm_ERC20Mint 136.7 ± 0.9 135.7 137.7 1.00
main_levm_ERC20Mint 261.7 ± 2.3 259.7 266.2 1.91 ± 0.02
pr_revm_ERC20Mint 140.3 ± 1.2 138.9 142.8 1.03 ± 0.01
pr_levm_ERC20Mint 248.7 ± 1.4 246.7 251.8 1.82 ± 0.02

Benchmark Results: ERC20Transfer

Command Mean [ms] Min [ms] Max [ms] Relative
main_revm_ERC20Transfer 238.5 ± 2.3 237.2 245.0 1.00
main_levm_ERC20Transfer 408.6 ± 1.5 405.7 410.2 1.71 ± 0.02
pr_revm_ERC20Transfer 248.4 ± 2.0 246.6 252.6 1.04 ± 0.01
pr_levm_ERC20Transfer 391.4 ± 3.5 386.2 396.4 1.64 ± 0.02

Benchmark Results: Factorial

Command Mean [ms] Min [ms] Max [ms] Relative
main_revm_Factorial 232.4 ± 0.7 231.1 233.9 1.00
main_levm_Factorial 474.4 ± 1.1 473.5 476.9 2.04 ± 0.01
pr_revm_Factorial 232.5 ± 1.4 230.8 235.4 1.00 ± 0.01
pr_levm_Factorial 438.5 ± 2.8 436.0 443.7 1.89 ± 0.01

Benchmark Results: FactorialRecursive

Command Mean [s] Min [s] Max [s] Relative
main_revm_FactorialRecursive 1.630 ± 0.025 1.587 1.668 1.01 ± 0.02
main_levm_FactorialRecursive 2.734 ± 0.016 2.698 2.759 1.69 ± 0.02
pr_revm_FactorialRecursive 1.616 ± 0.018 1.588 1.639 1.00
pr_levm_FactorialRecursive 6.762 ± 0.033 6.714 6.806 4.18 ± 0.05

Benchmark Results: Fibonacci

Command Mean [ms] Min [ms] Max [ms] Relative
main_revm_Fibonacci 207.4 ± 2.1 203.3 212.1 1.00
main_levm_Fibonacci 466.4 ± 4.0 461.7 473.9 2.25 ± 0.03
pr_revm_Fibonacci 209.1 ± 1.7 207.6 213.6 1.01 ± 0.01
pr_levm_Fibonacci 435.7 ± 8.7 430.3 459.4 2.10 ± 0.05

Benchmark Results: FibonacciRecursive

Command Mean [ms] Min [ms] Max [ms] Relative
main_revm_FibonacciRecursive 872.3 ± 11.2 848.3 886.8 1.01 ± 0.01
main_levm_FibonacciRecursive 1451.0 ± 6.7 1442.4 1461.3 1.68 ± 0.01
pr_revm_FibonacciRecursive 864.6 ± 5.7 858.0 871.6 1.00
pr_levm_FibonacciRecursive 1590.4 ± 14.7 1571.4 1615.4 1.84 ± 0.02

Benchmark Results: ManyHashes

Command Mean [ms] Min [ms] Max [ms] Relative
main_revm_ManyHashes 8.6 ± 0.1 8.6 8.7 1.00
main_levm_ManyHashes 13.9 ± 0.7 13.6 15.9 1.61 ± 0.08
pr_revm_ManyHashes 8.7 ± 0.1 8.7 8.9 1.01 ± 0.01
pr_levm_ManyHashes 12.7 ± 0.3 12.4 13.2 1.47 ± 0.04

Benchmark Results: MstoreBench

Command Mean [ms] Min [ms] Max [ms] Relative
main_revm_MstoreBench 271.3 ± 8.5 266.2 293.4 1.02 ± 0.03
main_levm_MstoreBench 955.7 ± 3.1 951.4 959.7 3.61 ± 0.04
pr_revm_MstoreBench 264.9 ± 2.7 263.5 272.5 1.00
pr_levm_MstoreBench 769.0 ± 2.2 766.8 772.4 2.90 ± 0.03

Benchmark Results: Push

Command Mean [ms] Min [ms] Max [ms] Relative
main_revm_Push 297.6 ± 0.5 296.7 298.1 1.02 ± 0.01
main_levm_Push 1065.3 ± 3.2 1060.3 1070.0 3.67 ± 0.03
pr_revm_Push 290.4 ± 2.0 288.3 295.4 1.00
pr_levm_Push 919.3 ± 12.1 912.0 953.2 3.17 ± 0.05

Copy link

github-actions bot commented Jul 8, 2025

Benchmark for 1bf004d

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

Copy link

github-actions bot commented Jul 8, 2025

Benchmark Block Execution Results Comparison Against Main

Command Mean [s] Min [s] Max [s] Relative
base 210.931 ± 0.655 210.065 211.750 1.01 ± 0.00
head 209.437 ± 0.762 208.251 210.681 1.00

Copy link

github-actions bot commented Jul 9, 2025

Benchmark Results: FactorialRecursive

Command Mean [s] Min [s] Max [s] Relative
main_revm_FactorialRecursive 1.638 ± 0.024 1.602 1.690 1.02 ± 0.02
main_levm_FactorialRecursive 2.730 ± 0.021 2.704 2.766 1.70 ± 0.03
pr_levm_FactorialRecursive 6.809 ± 0.032 6.766 6.869 4.24 ± 0.06
Detailed Results

Benchmark Results: BubbleSort

Command Mean [s] Min [s] Max [s] Relative
main_revm_BubbleSort 3.248 ± 0.206 3.158 3.831 1.01 ± 0.06
main_levm_BubbleSort 4.497 ± 0.018 4.478 4.535 1.40 ± 0.01
pr_revm_BubbleSort 3.207 ± 0.015 3.191 3.232 1.00
pr_levm_BubbleSort 4.593 ± 0.055 4.547 4.731 1.43 ± 0.02

Benchmark Results: ERC20Approval

Command Mean [s] Min [s] Max [s] Relative
main_revm_ERC20Approval 1.026 ± 0.005 1.022 1.035 1.00
main_levm_ERC20Approval 1.566 ± 0.035 1.542 1.654 1.53 ± 0.03
pr_revm_ERC20Approval 1.041 ± 0.011 1.028 1.056 1.01 ± 0.01
pr_levm_ERC20Approval 1.549 ± 0.017 1.536 1.588 1.51 ± 0.02

Benchmark Results: ERC20Mint

Command Mean [ms] Min [ms] Max [ms] Relative
main_revm_ERC20Mint 136.7 ± 0.5 136.1 137.8 1.00
main_levm_ERC20Mint 258.6 ± 2.3 256.4 263.7 1.89 ± 0.02
pr_revm_ERC20Mint 137.9 ± 0.8 136.8 139.1 1.01 ± 0.01
pr_levm_ERC20Mint 252.3 ± 1.1 250.9 254.3 1.85 ± 0.01

Benchmark Results: ERC20Transfer

Command Mean [ms] Min [ms] Max [ms] Relative
main_revm_ERC20Transfer 240.7 ± 2.3 238.8 246.5 1.00
main_levm_ERC20Transfer 406.9 ± 2.6 404.5 412.2 1.69 ± 0.02
pr_revm_ERC20Transfer 243.9 ± 4.1 241.0 253.2 1.01 ± 0.02
pr_levm_ERC20Transfer 400.2 ± 3.4 396.8 407.3 1.66 ± 0.02

Benchmark Results: Factorial

Command Mean [ms] Min [ms] Max [ms] Relative
main_revm_Factorial 231.6 ± 0.9 230.2 233.0 1.00
main_levm_Factorial 473.7 ± 2.0 472.0 478.6 2.05 ± 0.01
pr_revm_Factorial 234.2 ± 4.5 230.7 244.9 1.01 ± 0.02
pr_levm_Factorial 460.4 ± 1.8 457.0 464.1 1.99 ± 0.01

Benchmark Results: FactorialRecursive

Command Mean [s] Min [s] Max [s] Relative
main_revm_FactorialRecursive 1.638 ± 0.024 1.602 1.690 1.02 ± 0.02
main_levm_FactorialRecursive 2.730 ± 0.021 2.704 2.766 1.70 ± 0.03
pr_revm_FactorialRecursive 1.604 ± 0.023 1.556 1.641 1.00
pr_levm_FactorialRecursive 6.809 ± 0.032 6.766 6.869 4.24 ± 0.06

Benchmark Results: Fibonacci

Command Mean [ms] Min [ms] Max [ms] Relative
main_revm_Fibonacci 206.6 ± 0.6 205.7 207.7 1.01 ± 0.00
main_levm_Fibonacci 464.3 ± 1.7 461.0 466.3 2.27 ± 0.01
pr_revm_Fibonacci 204.7 ± 0.5 203.6 205.3 1.00
pr_levm_Fibonacci 452.4 ± 10.3 443.2 478.6 2.21 ± 0.05

Benchmark Results: FibonacciRecursive

Command Mean [ms] Min [ms] Max [ms] Relative
main_revm_FibonacciRecursive 878.8 ± 6.6 867.1 890.4 1.03 ± 0.01
main_levm_FibonacciRecursive 1429.7 ± 13.4 1409.7 1452.3 1.68 ± 0.02
pr_revm_FibonacciRecursive 853.3 ± 8.2 838.7 863.6 1.00
pr_levm_FibonacciRecursive 1602.5 ± 12.4 1591.7 1635.1 1.88 ± 0.02

Benchmark Results: ManyHashes

Command Mean [ms] Min [ms] Max [ms] Relative
main_revm_ManyHashes 8.7 ± 0.0 8.7 8.8 1.00
main_levm_ManyHashes 13.4 ± 0.1 13.2 13.6 1.54 ± 0.01
pr_revm_ManyHashes 8.8 ± 0.1 8.7 8.9 1.00 ± 0.01
pr_levm_ManyHashes 13.1 ± 0.1 13.0 13.2 1.50 ± 0.01

Benchmark Results: MstoreBench

Command Mean [ms] Min [ms] Max [ms] Relative
main_revm_MstoreBench 268.9 ± 2.2 267.0 275.0 1.01 ± 0.01
main_levm_MstoreBench 945.1 ± 3.7 941.1 951.9 3.56 ± 0.04
pr_revm_MstoreBench 265.7 ± 2.6 263.2 271.8 1.00
pr_levm_MstoreBench 827.2 ± 1.7 824.4 829.3 3.11 ± 0.03

Benchmark Results: Push

Command Mean [ms] Min [ms] Max [ms] Relative
main_revm_Push 297.9 ± 1.1 296.5 299.7 1.02 ± 0.01
main_levm_Push 1052.9 ± 4.6 1048.7 1063.6 3.59 ± 0.03
pr_revm_Push 293.1 ± 1.7 290.8 295.9 1.00
pr_levm_Push 983.0 ± 25.9 969.3 1055.9 3.35 ± 0.09

Copy link

github-actions bot commented Jul 9, 2025

Benchmark for 804e443

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

Copy link

github-actions bot commented Jul 9, 2025

Benchmark for 5ff7ec8

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

Copy link

github-actions bot commented Jul 9, 2025

Benchmark for 81c980a

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

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.

LGTM great PR

Copy link
Contributor

@JereSalo JereSalo left a comment

Choose a reason for hiding this comment

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

I wonder why we changed some + for wrapping_add. In some places it doesn't seem to be necessary, is it?

Some of the usize::MAX sets that we do could be replaced by an error like VeryLargeNumber? Maybe in some places the behavior is the same but I'm not completely sure.

@edg-l
Copy link
Contributor Author

edg-l commented Jul 17, 2025

Some of the usize::MAX sets that we do could be replaced by an error like VeryLargeNumber? Maybe in some places the behavior is the same but I'm not completely sure.

We have to be careful with "early errors" from ? which can for example, prevent incrementing the gas (which needs to be done even if there is an error). Thats why.

@edg-l edg-l requested review from Oppen and JereSalo July 17, 2025 06:06
@JereSalo
Copy link
Contributor

Some of the usize::MAX sets that we do could be replaced by an error like VeryLargeNumber? Maybe in some places the behavior is the same but I'm not completely sure.

We have to be careful with "early errors" from ? which can for example, prevent incrementing the gas (which needs to be done even if there is an error). Thats why.

We don't need to increment gas when there's an error. Errors like that consume all gas left so it doesn't matter

@edg-l
Copy link
Contributor Author

edg-l commented Jul 17, 2025

Some of the usize::MAX sets that we do could be replaced by an error like VeryLargeNumber? Maybe in some places the behavior is the same but I'm not completely sure.

We have to be careful with "early errors" from ? which can for example, prevent incrementing the gas (which needs to be done even if there is an error). Thats why.

We don't need to increment gas when there's an error. Errors like that consume all gas left so it doesn't matter

Actually the trick about not throwing the error, is that calculate_memory_size which is used for gas costs, doesn't error if the size is 0. This is why we use those dummy values instead of throwing an error earlier, because while the offset may fail to parse, size is 0 so it is valid. And if size is not 0 it will error later with a checked overflow.

@JereSalo
Copy link
Contributor

Some of the usize::MAX sets that we do could be replaced by an error like VeryLargeNumber? Maybe in some places the behavior is the same but I'm not completely sure.

We have to be careful with "early errors" from ? which can for example, prevent incrementing the gas (which needs to be done even if there is an error). Thats why.

We don't need to increment gas when there's an error. Errors like that consume all gas left so it doesn't matter

Actually the trick about not throwing the error, is that calculate_memory_size which is used for gas costs, doesn't error if the size is 0. This is why we use those dummy values instead of throwing an error earlier, because while the offset may fail to parse, size is 0 so it is valid. And if size is not 0 it will error later with a checked overflow.

You're right, I forgot about the cases in which size was zero.

@edg-l edg-l added this pull request to the merge queue Jul 17, 2025
Merged via the queue into main with commit 22b6430 Jul 17, 2025
44 of 46 checks passed
@github-project-automation github-project-automation bot moved this from In review to Done in ethrex_performance Jul 17, 2025
@edg-l edg-l deleted the new_memory branch July 17, 2025 14:19
d-roak pushed a commit to 1sixtech/ethrex that referenced this pull request Jul 17, 2025
**Motivation**

Gas benchmarks show an 23% improvement on opcode based timings and 12%
on end to end.
30% improvement in mgas for mstore (before unsafe)

After adding unsafe we see a 30% improvement on top of the mstore
improvements and overall general improvements on other opcodes.
github-merge-queue bot pushed a commit that referenced this pull request Jul 17, 2025
**Motivation**
Improves sstore perfomance

Requires #3564

From 1100 to over 2200

<img width="1896" height="281" alt="image"
src="https://github.com/user-attachments/assets/7f5697a3-048c-4554-91bb-22839bb91d95"
/>

The main change is going from Hashmaps to BTreeMaps.

They are more efficient for the type of storages we use, for small
datasets (1k~100k i would say) they overperform hashmaps due to avoiding
entirely the hashing cost, which seemed to be the biggest factor.

This changes comes with 2 other minor changes, like a more efficient
u256 to big endian and a change to backup_storage_slot.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
levm Lambda EVM implementation performance
Projects
Status: Done
Development

Successfully merging this pull request may close these issues.

4 participants