Skip to content

perf(core): block snapshots with layers #2664

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

Draft
wants to merge 45 commits into
base: main
Choose a base branch
from
Draft

perf(core): block snapshots with layers #2664

wants to merge 45 commits into from

Conversation

edg-l
Copy link
Member

@edg-l edg-l commented May 5, 2025

Motivation

Adds block snapshots using disk and diff layers. Improving performance by reducing database queries.

Description

Heavily inspired by https://github.com/ethereum/go-ethereum/blob/master/core/state/snapshot/

Uses a base disk layer at block X, adding diff layers as blocks come at X + 1, X + 2, until the cap of max layers is reached, when that happens, flattening of layers is done, moving the bottom disk layer closer to the head block like a moving window.

When one queries for example for the account state at HEAD-4 block. The snapshot tree requests the snapshot at HEAD-4, then using a bloom filter which aggregates all accounts from previous diff layers, we can now if we skip to the disk layer directly or traverse the diff layers. Traversing the diff layers is faster than quering the database.

Closes #1997, however we should open more issues for missing features:

Missing features:

  • A database table for snapshots for use in the disk layer, instead of using the trie.
  • Save snapshots and diff layers to the database

Copy link

github-actions bot commented May 5, 2025

Lines of code report

Total lines added: 1059
Total lines removed: 0
Total lines changed: 1059

Detailed view
+---------------------------------------------+-------+------+
| File                                        | Lines | Diff |
+---------------------------------------------+-------+------+
| ethrex/crates/blockchain/blockchain.rs      | 499   | +4   |
+---------------------------------------------+-------+------+
| ethrex/crates/storage/cache.rs              | 14    | +14  |
+---------------------------------------------+-------+------+
| ethrex/crates/storage/lib.rs                | 16    | +3   |
+---------------------------------------------+-------+------+
| ethrex/crates/storage/snapshot/difflayer.rs | 203   | +203 |
+---------------------------------------------+-------+------+
| ethrex/crates/storage/snapshot/disklayer.rs | 134   | +134 |
+---------------------------------------------+-------+------+
| ethrex/crates/storage/snapshot/error.rs     | 19    | +19  |
+---------------------------------------------+-------+------+
| ethrex/crates/storage/snapshot/mod.rs       | 5     | +5   |
+---------------------------------------------+-------+------+
| ethrex/crates/storage/snapshot/tree.rs      | 604   | +604 |
+---------------------------------------------+-------+------+
| ethrex/crates/storage/store.rs              | 1298  | +73  |
+---------------------------------------------+-------+------+

Copy link

github-actions bot commented May 5, 2025

Benchmark for 93bb4dc

Click to view benchmark
Test Base PR %
Trie/cita-trie insert 10k 39.3±4.00ms 39.6±4.64ms +0.76%
Trie/cita-trie insert 1k 3.7±0.05ms 3.7±0.05ms 0.00%
Trie/ethrex-trie insert 10k 129.4±4.93ms 134.7±5.32ms +4.10%
Trie/ethrex-trie insert 1k 11.1±0.13ms 11.2±0.15ms +0.90%

Copy link

github-actions bot commented May 6, 2025

Benchmark for 42d6956

Click to view benchmark
Test Base PR %
Trie/cita-trie insert 10k 33.6±0.24ms 34.8±0.91ms +3.57%
Trie/cita-trie insert 1k 3.4±0.05ms 3.5±0.12ms +2.94%
Trie/ethrex-trie insert 10k 113.8±2.12ms 120.2±4.69ms +5.62%
Trie/ethrex-trie insert 1k 10.2±0.26ms 10.5±0.79ms +2.94%

Copy link

github-actions bot commented May 6, 2025

Benchmark for a9f99ff

Click to view benchmark
Test Base PR %
Trie/cita-trie insert 10k 34.2±1.99ms 41.5±4.16ms +21.35%
Trie/cita-trie insert 1k 3.7±0.06ms 3.7±0.06ms 0.00%
Trie/ethrex-trie insert 10k 135.7±3.75ms 131.1±2.22ms -3.39%
Trie/ethrex-trie insert 1k 11.3±0.26ms 11.5±0.47ms +1.77%

Copy link

github-actions bot commented May 6, 2025

Benchmark for b7b493f

Click to view benchmark
Test Base PR %
Trie/cita-trie insert 10k 36.2±1.43ms 39.2±1.79ms +8.29%
Trie/cita-trie insert 1k 3.6±0.03ms 3.7±0.09ms +2.78%
Trie/ethrex-trie insert 10k 129.6±1.77ms 132.0±2.70ms +1.85%
Trie/ethrex-trie insert 1k 11.0±0.26ms 11.2±0.32ms +1.82%

Copy link

github-actions bot commented May 6, 2025

Benchmark for bce47f6

Click to view benchmark
Test Base PR %
Trie/cita-trie insert 10k 37.7±2.61ms 38.7±2.90ms +2.65%
Trie/cita-trie insert 1k 3.6±0.06ms 3.6±0.04ms 0.00%
Trie/ethrex-trie insert 10k 131.6±2.64ms 130.7±1.92ms -0.68%
Trie/ethrex-trie insert 1k 11.2±0.37ms 11.0±0.06ms -1.79%

Copy link

github-actions bot commented May 6, 2025

Benchmark for b40e593

Click to view benchmark
Test Base PR %
Trie/cita-trie insert 10k 35.7±0.68ms 35.8±0.73ms +0.28%
Trie/cita-trie insert 1k 3.8±0.04ms 3.6±0.04ms -5.26%
Trie/ethrex-trie insert 10k 127.5±2.88ms 127.2±3.70ms -0.24%
Trie/ethrex-trie insert 1k 11.1±0.17ms 11.3±0.57ms +1.80%

Copy link

github-actions bot commented May 6, 2025

Benchmark for ee8ac59

Click to view benchmark
Test Base PR %
Trie/cita-trie insert 10k 36.7±1.02ms 37.1±1.74ms +1.09%
Trie/cita-trie insert 1k 3.7±0.05ms 3.7±0.07ms 0.00%
Trie/ethrex-trie insert 10k 130.1±2.80ms 127.8±2.97ms -1.77%
Trie/ethrex-trie insert 1k 11.0±0.11ms 11.1±0.06ms +0.91%

@edg-l edg-l changed the title WIP: Snapshots feat(core): block snapshots with layers May 7, 2025
@edg-l edg-l changed the title feat(core): block snapshots with layers perf(core): block snapshots with layers May 7, 2025
Copy link

github-actions bot commented May 7, 2025

Benchmark for c144ed8

Click to view benchmark
Test Base PR %
Trie/cita-trie insert 10k 35.8±0.83ms 38.8±1.29ms +8.38%
Trie/cita-trie insert 1k 3.7±0.05ms 3.9±0.04ms +5.41%
Trie/ethrex-trie insert 10k 132.1±3.59ms 128.2±3.19ms -2.95%
Trie/ethrex-trie insert 1k 11.3±0.46ms 11.2±0.39ms -0.88%

Copy link

github-actions bot commented May 7, 2025

Benchmark Block Execution Results Comparison Against Main

Command Mean [s] Min [s] Max [s] Relative
base 218.324 ± 0.608 217.430 219.344 1.00 ± 0.01
head 217.661 ± 0.918 216.390 219.289 1.00

Copy link

github-actions bot commented May 7, 2025

Benchmark for 084ba79

Click to view benchmark
Test Base PR %
Trie/cita-trie insert 10k 33.7±1.29ms 41.0±2.02ms +21.66%
Trie/cita-trie insert 1k 3.7±0.03ms 3.7±0.11ms 0.00%
Trie/ethrex-trie insert 10k 138.8±3.52ms 134.8±3.78ms -2.88%
Trie/ethrex-trie insert 1k 11.3±0.13ms 11.3±0.31ms 0.00%

Copy link

github-actions bot commented May 7, 2025

Benchmark for 9cc084f

Click to view benchmark
Test Base PR %
Trie/cita-trie insert 10k 34.8±0.47ms 35.5±0.34ms +2.01%
Trie/cita-trie insert 1k 3.6±0.09ms 3.7±0.04ms +2.78%
Trie/ethrex-trie insert 10k 124.1±1.42ms 123.5±1.13ms -0.48%
Trie/ethrex-trie insert 1k 11.1±0.16ms 11.2±0.36ms +0.90%

Copy link

github-actions bot commented May 7, 2025

Benchmark for 23432e3

Click to view benchmark
Test Base PR %
Trie/cita-trie insert 10k 35.6±1.00ms 36.7±1.31ms +3.09%
Trie/cita-trie insert 1k 3.7±0.03ms 3.7±0.05ms 0.00%
Trie/ethrex-trie insert 10k 128.8±2.79ms 128.7±2.03ms -0.08%
Trie/ethrex-trie insert 1k 11.1±0.06ms 11.2±0.64ms +0.90%

Copy link

Benchmark for d3a4665

Click to view benchmark
Test Base PR %
Trie/cita-trie insert 10k 36.2±1.28ms 36.7±1.30ms +1.38%
Trie/cita-trie insert 1k 3.7±0.09ms 3.9±0.14ms +5.41%
Trie/ethrex-trie insert 10k 128.1±4.68ms 131.9±5.59ms +2.97%
Trie/ethrex-trie insert 1k 11.1±0.21ms 11.5±0.28ms +3.60%

Copy link

Benchmark for a4e259a

Click to view benchmark
Test Base PR %
Trie/cita-trie insert 10k 35.5±0.57ms 35.3±0.41ms -0.56%
Trie/cita-trie insert 1k 3.7±0.09ms 3.6±0.11ms -2.70%
Trie/ethrex-trie insert 10k 124.2±2.75ms 123.6±2.25ms -0.48%
Trie/ethrex-trie insert 1k 11.1±0.32ms 11.1±0.39ms 0.00%

Copy link

Benchmark for e1ecd9d

Click to view benchmark
Test Base PR %
Trie/cita-trie insert 10k 36.4±0.87ms 35.5±0.72ms -2.47%
Trie/cita-trie insert 1k 3.7±0.19ms 3.7±0.02ms 0.00%
Trie/ethrex-trie insert 10k 134.9±3.55ms 128.1±2.52ms -5.04%
Trie/ethrex-trie insert 1k 11.3±0.26ms 11.4±0.48ms +0.88%

Copy link

Benchmark for de9e830

Click to view benchmark
Test Base PR %
Trie/cita-trie insert 10k 37.5±2.15ms 36.6±1.07ms -2.40%
Trie/cita-trie insert 1k 3.7±0.06ms 3.7±0.05ms 0.00%
Trie/ethrex-trie insert 10k 129.7±2.44ms 134.7±1.59ms +3.86%
Trie/ethrex-trie insert 1k 11.1±0.11ms 11.2±0.09ms +0.90%

Copy link

Benchmark for 2b9c848

Click to view benchmark
Test Base PR %
Trie/cita-trie insert 10k 37.5±0.98ms 38.9±2.21ms +3.73%
Trie/cita-trie insert 1k 3.7±0.05ms 3.7±0.04ms 0.00%
Trie/ethrex-trie insert 10k 136.2±3.32ms 136.0±2.08ms -0.15%
Trie/ethrex-trie insert 1k 11.2±0.54ms 11.4±0.71ms +1.79%

Copy link

Benchmark for 6cd17bd

Click to view benchmark
Test Base PR %
Trie/cita-trie insert 10k 36.4±1.25ms 41.2±3.38ms +13.19%
Trie/cita-trie insert 1k 3.6±0.05ms 3.7±0.04ms +2.78%
Trie/ethrex-trie insert 10k 132.6±4.13ms 127.9±2.20ms -3.54%
Trie/ethrex-trie insert 1k 11.4±0.56ms 11.2±0.36ms -1.75%

Copy link

Benchmark for c90d6c3

Click to view benchmark
Test Base PR %
Trie/cita-trie insert 10k 36.9±1.34ms 35.8±0.71ms -2.98%
Trie/cita-trie insert 1k 3.7±0.03ms 3.7±0.03ms 0.00%
Trie/ethrex-trie insert 10k 129.1±2.34ms 127.8±1.42ms -1.01%
Trie/ethrex-trie insert 1k 11.1±0.14ms 11.3±0.34ms +1.80%

Copy link

Benchmark for 0b94a3c

Click to view benchmark
Test Base PR %
Trie/cita-trie insert 10k 36.1±0.81ms 36.1±0.59ms 0.00%
Trie/cita-trie insert 1k 3.6±0.07ms 3.7±0.05ms +2.78%
Trie/ethrex-trie insert 10k 131.2±2.38ms 130.6±2.20ms -0.46%
Trie/ethrex-trie insert 1k 11.1±0.23ms 11.2±0.44ms +0.90%

@edg-l
Copy link
Member Author

edg-l commented May 14, 2025

[METRIC] BLOCK EXECUTION THROUGHPUT: 0.64 Ggas/s TIME SPENT: 37 ms. #Txs: 452. exec/Ggas: 891 ms (57%), st/Ggas: 637 ms (41%)

on a ryzen 7900x3d with 64gb

Copy link

Benchmark for 6990c8d

Click to view benchmark
Test Base PR %
Trie/cita-trie insert 10k 39.3±2.63ms 33.2±1.98ms -15.52%
Trie/cita-trie insert 1k 3.6±0.14ms 3.7±0.01ms +2.78%
Trie/ethrex-trie insert 10k 133.3±2.10ms 132.8±3.07ms -0.38%
Trie/ethrex-trie insert 1k 11.2±0.18ms 11.2±0.49ms 0.00%

Copy link

Benchmark for 98eb4e6

Click to view benchmark
Test Base PR %
Trie/cita-trie insert 10k 37.1±1.45ms 37.8±1.85ms +1.89%
Trie/cita-trie insert 1k 3.6±0.03ms 3.7±0.04ms +2.78%
Trie/ethrex-trie insert 10k 132.1±2.84ms 131.1±3.44ms -0.76%
Trie/ethrex-trie insert 1k 11.2±0.10ms 11.1±0.07ms -0.89%

Copy link

Benchmark for df0afa7

Click to view benchmark
Test Base PR %
Trie/cita-trie insert 10k 31.9±1.16ms 32.8±1.04ms +2.82%
Trie/cita-trie insert 1k 3.7±0.06ms 3.7±0.02ms 0.00%
Trie/ethrex-trie insert 10k 136.2±2.83ms 133.9±2.10ms -1.69%
Trie/ethrex-trie insert 1k 11.3±0.09ms 11.2±0.50ms -0.88%

Copy link

Benchmark for f4045a2

Click to view benchmark
Test Base PR %
Trie/cita-trie insert 10k 35.5±0.65ms 36.6±1.55ms +3.10%
Trie/cita-trie insert 1k 3.8±0.05ms 3.7±0.05ms -2.63%
Trie/ethrex-trie insert 10k 129.8±2.69ms 127.9±2.05ms -1.46%
Trie/ethrex-trie insert 1k 11.2±0.07ms 11.3±0.62ms +0.89%

Copy link

Benchmark for 91d0686

Click to view benchmark
Test Base PR %
Trie/cita-trie insert 10k 36.2±0.63ms 36.8±1.15ms +1.66%
Trie/cita-trie insert 1k 3.7±0.05ms 3.7±0.05ms 0.00%
Trie/ethrex-trie insert 10k 130.0±2.88ms 125.1±1.70ms -3.77%
Trie/ethrex-trie insert 1k 11.1±0.04ms 11.2±0.68ms +0.90%

Copy link

Benchmark for 1df7c68

Click to view benchmark
Test Base PR %
Trie/cita-trie insert 10k 35.0±0.55ms 35.5±0.42ms +1.43%
Trie/cita-trie insert 1k 3.6±0.05ms 3.7±0.05ms +2.78%
Trie/ethrex-trie insert 10k 123.7±2.36ms 123.2±1.08ms -0.40%
Trie/ethrex-trie insert 1k 11.0±0.22ms 11.4±0.73ms +3.64%

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.

perf: state snapshots
2 participants