Skip to content

perf(levm): improve sstore perfomance further #3657

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

Conversation

edg-l
Copy link
Contributor

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

Motivation
Improves sstore perfomance

Requires #3564

From 1100 to over 2200

image

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.

Copy link

github-actions bot commented Jul 16, 2025

Lines of code report

Total lines added: 42
Total lines removed: 6
Total lines changed: 48

Detailed view
+------------------------------------------------------------------------+-------+------+
| File                                                                   | Lines | Diff |
+------------------------------------------------------------------------+-------+------+
| ethrex/crates/common/utils.rs                                          | 57    | +28  |
+------------------------------------------------------------------------+-------+------+
| ethrex/crates/storage/store_db/libmdbx.rs                              | 1478  | +1   |
+------------------------------------------------------------------------+-------+------+
| ethrex/crates/vm/levm/bench/revm_comparison/src/levm_bench.rs          | 70    | +1   |
+------------------------------------------------------------------------+-------+------+
| ethrex/crates/vm/levm/src/call_frame.rs                                | 296   | +3   |
+------------------------------------------------------------------------+-------+------+
| ethrex/crates/vm/levm/src/db/gen_db.rs                                 | 241   | -6   |
+------------------------------------------------------------------------+-------+------+
| ethrex/crates/vm/levm/src/memory.rs                                    | 276   | +3   |
+------------------------------------------------------------------------+-------+------+
| ethrex/crates/vm/levm/src/opcode_handlers/stack_memory_storage_flow.rs | 284   | +5   |
+------------------------------------------------------------------------+-------+------+
| ethrex/crates/vm/levm/src/utils.rs                                     | 445   | +1   |
+------------------------------------------------------------------------+-------+------+

Copy link

github-actions bot commented Jul 16, 2025

Benchmark Results Comparison

Benchmark Results: SstoreBench_no_opt

Command Mean [s] Min [s] Max [s] Relative
main_revm_SstoreBench_no_opt 161.5 ± 4.3 158.4 172.7 1.59 ± 0.09
main_levm_SstoreBench_no_opt 114.8 ± 7.0 104.7 124.1 1.13 ± 0.09
pr_levm_SstoreBench_no_opt 101.7 ± 4.7 98.8 114.9 1.00
Detailed Results

Benchmark Results: BubbleSort

Command Mean [s] Min [s] Max [s] Relative
main_revm_BubbleSort 3.204 ± 0.013 3.187 3.228 1.00
main_levm_BubbleSort 4.277 ± 0.016 4.253 4.301 1.33 ± 0.01
pr_revm_BubbleSort 3.211 ± 0.017 3.193 3.238 1.00 ± 0.01
pr_levm_BubbleSort 4.170 ± 0.024 4.149 4.228 1.30 ± 0.01

Benchmark Results: ERC20Approval

Command Mean [s] Min [s] Max [s] Relative
main_revm_ERC20Approval 1.055 ± 0.023 1.038 1.114 1.01 ± 0.02
main_levm_ERC20Approval 1.434 ± 0.014 1.416 1.466 1.37 ± 0.02
pr_revm_ERC20Approval 1.048 ± 0.011 1.035 1.069 1.00
pr_levm_ERC20Approval 1.419 ± 0.016 1.404 1.458 1.35 ± 0.02

Benchmark Results: ERC20Mint

Command Mean [ms] Min [ms] Max [ms] Relative
main_revm_ERC20Mint 138.2 ± 1.1 137.1 140.7 1.00
main_levm_ERC20Mint 220.1 ± 2.9 216.2 224.7 1.59 ± 0.03
pr_revm_ERC20Mint 138.5 ± 0.6 137.4 139.5 1.00 ± 0.01
pr_levm_ERC20Mint 206.4 ± 3.1 204.0 213.6 1.49 ± 0.03

Benchmark Results: ERC20Transfer

Command Mean [ms] Min [ms] Max [ms] Relative
main_revm_ERC20Transfer 244.3 ± 1.1 242.7 246.9 1.00
main_levm_ERC20Transfer 359.9 ± 1.3 357.8 362.8 1.47 ± 0.01
pr_revm_ERC20Transfer 245.1 ± 3.2 242.6 252.4 1.00 ± 0.01
pr_levm_ERC20Transfer 358.5 ± 7.8 354.8 379.7 1.47 ± 0.03

Benchmark Results: Factorial

Command Mean [ms] Min [ms] Max [ms] Relative
main_revm_Factorial 229.6 ± 1.6 228.3 232.8 1.00 ± 0.01
main_levm_Factorial 451.7 ± 3.6 443.8 457.4 1.97 ± 0.02
pr_revm_Factorial 229.5 ± 1.1 228.0 231.6 1.00
pr_levm_Factorial 457.4 ± 11.9 449.3 486.9 1.99 ± 0.05

Benchmark Results: FactorialRecursive

Command Mean [s] Min [s] Max [s] Relative
main_revm_FactorialRecursive 1.596 ± 0.020 1.550 1.624 1.01 ± 0.06
main_levm_FactorialRecursive 8.208 ± 0.052 8.140 8.311 5.21 ± 0.32
pr_revm_FactorialRecursive 1.576 ± 0.097 1.308 1.648 1.00
pr_levm_FactorialRecursive 8.246 ± 0.027 8.209 8.296 5.23 ± 0.32

Benchmark Results: Fibonacci

Command Mean [ms] Min [ms] Max [ms] Relative
main_revm_Fibonacci 204.0 ± 1.8 202.6 208.7 1.00
main_levm_Fibonacci 467.5 ± 18.8 452.2 507.3 2.29 ± 0.09
pr_revm_Fibonacci 206.9 ± 10.2 202.9 235.9 1.01 ± 0.05
pr_levm_Fibonacci 469.7 ± 15.7 449.1 499.2 2.30 ± 0.08

Benchmark Results: FibonacciRecursive

Command Mean [ms] Min [ms] Max [ms] Relative
main_revm_FibonacciRecursive 850.0 ± 13.1 825.0 866.6 1.00
main_levm_FibonacciRecursive 1315.8 ± 15.2 1288.1 1338.7 1.55 ± 0.03
pr_revm_FibonacciRecursive 860.0 ± 17.6 844.1 902.4 1.01 ± 0.03
pr_levm_FibonacciRecursive 1327.1 ± 18.7 1302.0 1351.2 1.56 ± 0.03

Benchmark Results: ManyHashes

Command Mean [ms] Min [ms] Max [ms] Relative
main_revm_ManyHashes 8.7 ± 0.1 8.6 8.9 1.00
main_levm_ManyHashes 12.4 ± 0.1 12.3 12.6 1.42 ± 0.01
pr_revm_ManyHashes 8.8 ± 0.1 8.7 8.9 1.00 ± 0.01
pr_levm_ManyHashes 12.0 ± 0.1 11.9 12.3 1.38 ± 0.02

Benchmark Results: MstoreBench

Command Mean [ms] Min [ms] Max [ms] Relative
main_revm_MstoreBench 265.8 ± 2.3 263.8 271.3 1.00
main_levm_MstoreBench 639.1 ± 4.4 636.2 651.3 2.40 ± 0.03
pr_revm_MstoreBench 265.8 ± 2.4 263.0 271.6 1.00 ± 0.01
pr_levm_MstoreBench 640.5 ± 6.8 636.1 656.8 2.41 ± 0.03

Benchmark Results: Push

Command Mean [ms] Min [ms] Max [ms] Relative
main_revm_Push 291.5 ± 2.0 289.5 296.3 1.00 ± 0.01
main_levm_Push 819.4 ± 10.2 810.6 838.8 2.81 ± 0.04
pr_revm_Push 291.2 ± 0.9 290.0 292.6 1.00
pr_levm_Push 815.1 ± 7.5 809.1 834.7 2.80 ± 0.03

Benchmark Results: SstoreBench_no_opt

Command Mean [ms] Min [ms] Max [ms] Relative
main_revm_SstoreBench_no_opt 161.5 ± 4.3 158.4 172.7 1.59 ± 0.09
main_levm_SstoreBench_no_opt 114.8 ± 7.0 104.7 124.1 1.13 ± 0.09
pr_revm_SstoreBench_no_opt 159.8 ± 1.1 158.5 161.8 1.57 ± 0.07
pr_levm_SstoreBench_no_opt 101.7 ± 4.7 98.8 114.9 1.00

@edg-l edg-l moved this from Todo to In review in ethrex_performance Jul 17, 2025
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

Base automatically changed from new_memory to main July 17, 2025 14:19
Copy link

github-actions bot commented Jul 17, 2025

Benchmark Block Execution Results Comparison Against Main

Command Mean [s] Min [s] Max [s] Relative
base 207.215 ± 0.407 206.393 207.752 1.00
head 209.377 ± 0.433 208.682 209.989 1.01 ± 0.00

@Arkenan Arkenan added this pull request to the merge queue Jul 17, 2025
Merged via the queue into main with commit 23191af Jul 17, 2025
48 checks passed
@Arkenan Arkenan deleted the sstore_improvements branch July 17, 2025 17:43
@github-project-automation github-project-automation bot moved this from In review to Done in ethrex_performance Jul 17, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Status: Done
Development

Successfully merging this pull request may close these issues.

3 participants