Skip to content

Commit 3149473

Browse files
authored
misc: Rethnet state benchmark tweaks (#4037)
1 parent 5f984d9 commit 3149473

File tree

10 files changed

+83
-70
lines changed

10 files changed

+83
-70
lines changed

.cargo-husky/hooks/pre-commit

+1-1
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ else
1717
fi
1818

1919
cargo check --workspace ${CHECK_FEATURE_FLAG} --all-targets
20-
cargo check --workspace --all-targets
20+
cargo check --workspace --all-targets --no-default-features
2121
cargo test --workspace --all-targets --features tracing,bench-once${TEST_REMOTE}
2222
cargo test --doc --workspace --features tracing
2323
cargo clippy --all -- -D warnings

.github/workflows/hardhat-core-ci.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ jobs:
6262
uses: actions-rs/cargo@v1
6363
with:
6464
command: check
65-
args: --workspace --all-targets
65+
args: --workspace --all-targets --no-default-features
6666

6767
test-core:
6868
name: Test core (${{ matrix.os }}, Node ${{ matrix.node }}, ${{ matrix.vm }})

crates/rethnet_evm/Cargo.toml

+10-1
Original file line numberDiff line numberDiff line change
@@ -32,17 +32,26 @@ test-remote = []
3232
tracing = ["dep:tracing"]
3333

3434
[[bench]]
35-
name = "state"
35+
name = "database_commit"
36+
path = "benches/state/database_commit.rs"
3637
harness = false
3738

3839
[[bench]]
3940
name = "state_debug"
41+
path = "benches/state/state_debug.rs"
4042
harness = false
4143

4244
[[bench]]
4345
name = "state_history"
46+
path = "benches/state/state_history.rs"
4447
harness = false
4548

4649
[[bench]]
4750
name = "state_history_block_context"
51+
path = "benches/state/state_history_block_context.rs"
52+
harness = false
53+
54+
[[bench]]
55+
name = "state_ref"
56+
path = "benches/state/state_ref.rs"
4857
harness = false
Original file line numberDiff line numberDiff line change
@@ -1,49 +1,10 @@
1-
use std::str::FromStr;
2-
31
use criterion::{criterion_group, criterion_main, Criterion};
42
use revm::{db::StateRef, primitives::Bytecode};
53

64
use rethnet_eth::{Address, Bytes, U256};
75

86
mod util;
9-
use util::{bench_sync_state_method, state_prep_no_op, Permutations};
10-
11-
fn bench_basic(c: &mut Criterion) {
12-
bench_sync_state_method(
13-
c,
14-
"StateRef:basic",
15-
state_prep_no_op,
16-
|state, number_of_accounts, _, _| {
17-
for i in (1..=number_of_accounts).rev() {
18-
let result = state.basic(Address::from_str(&format!("0x{:0>40x}", i)).unwrap());
19-
debug_assert!(result.is_ok());
20-
}
21-
},
22-
&[0],
23-
&[1],
24-
);
25-
}
26-
27-
fn bench_code_by_hash(c: &mut Criterion) {
28-
bench_sync_state_method(
29-
c,
30-
"StateRef:code_by_hash",
31-
state_prep_no_op,
32-
|state, number_of_accounts, _, _| {
33-
for i in (1..=number_of_accounts).rev() {
34-
let result = state.code_by_hash(
35-
Bytecode::new_raw(Bytes::copy_from_slice(
36-
Address::from_low_u64_ne(i).as_bytes(),
37-
))
38-
.hash(),
39-
);
40-
debug_assert!(result.is_ok());
41-
}
42-
},
43-
&[0],
44-
&[1],
45-
);
46-
}
7+
use util::{bench_sync_state_method, state_prep_no_op};
478

489
fn bench_database_commit(c: &mut Criterion) {
4910
use hashbrown::HashMap;
@@ -66,7 +27,7 @@ fn bench_database_commit(c: &mut Criterion) {
6627
let mut accounts_to_commit: HashMap<Address, Account> = HashMap::new();
6728
let json_accounts: HashMap<Address, AccountState> = serde_json::from_str(
6829
&std::fs::read_to_string(
69-
"benches/fixtures/accounts_changed_in_mainnet_block_17295357.json",
30+
"benches/state/fixtures/accounts_changed_in_mainnet_block_17295357.json",
7031
)
7132
.unwrap(),
7233
/* a fresh set of account updates can be retrieved via, eg:
@@ -118,7 +79,8 @@ fn bench_database_commit(c: &mut Criterion) {
11879
|state, _number_of_accounts, _, _| {
11980
state.commit(accounts_to_commit.clone());
12081

121-
debug_assert!(json_accounts.iter().all(|(address, json)| {
82+
#[cfg(debug_assertions)]
83+
json_accounts.iter().for_each(|(address, json)| {
12284
if let Some(committed) = state.basic(*address).unwrap() {
12385
debug_assert!(committed.balance == json.balance.unwrap());
12486
debug_assert!(committed.nonce == json.nonce.unwrap());
@@ -132,35 +94,12 @@ fn bench_database_commit(c: &mut Criterion) {
13294
} else {
13395
debug_assert!(false);
13496
}
135-
true
136-
}));
97+
});
13798
},
13899
&[0],
139100
&[1],
140101
);
141102
}
142103

143-
fn bench_storage(c: &mut Criterion) {
144-
bench_sync_state_method(
145-
c,
146-
"StateRef:storage",
147-
state_prep_no_op,
148-
|state, number_of_accounts, _, _| {
149-
for i in (1..=number_of_accounts).rev() {
150-
let result = state.storage(Address::from_low_u64_ne(i), U256::from(i));
151-
debug_assert!(result.is_ok());
152-
}
153-
},
154-
&Permutations::storage_scales(),
155-
&[1],
156-
);
157-
}
158-
159-
criterion_group!(
160-
benches,
161-
bench_basic,
162-
bench_code_by_hash,
163-
bench_storage,
164-
bench_database_commit
165-
);
104+
criterion_group!(benches, bench_database_commit);
166105
criterion_main!(benches);
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
use std::str::FromStr;
2+
3+
use criterion::{criterion_group, criterion_main, Criterion};
4+
use revm::{db::StateRef, primitives::Bytecode};
5+
6+
use rethnet_eth::{Address, Bytes, U256};
7+
8+
mod util;
9+
use util::{bench_sync_state_method, state_prep_no_op, Permutations};
10+
11+
fn bench_basic(c: &mut Criterion) {
12+
bench_sync_state_method(
13+
c,
14+
"StateRef:basic",
15+
state_prep_no_op,
16+
|state, number_of_accounts, _, _| {
17+
for i in (1..=number_of_accounts).rev() {
18+
let result = state.basic(Address::from_str(&format!("0x{:0>40x}", i)).unwrap());
19+
debug_assert!(result.is_ok());
20+
}
21+
},
22+
&[0],
23+
&[1],
24+
);
25+
}
26+
27+
fn bench_code_by_hash(c: &mut Criterion) {
28+
bench_sync_state_method(
29+
c,
30+
"StateRef:code_by_hash",
31+
state_prep_no_op,
32+
|state, number_of_accounts, _, _| {
33+
for i in (1..=number_of_accounts).rev() {
34+
let result = state.code_by_hash(
35+
Bytecode::new_raw(Bytes::copy_from_slice(
36+
Address::from_low_u64_ne(i).as_bytes(),
37+
))
38+
.hash(),
39+
);
40+
debug_assert!(result.is_ok());
41+
}
42+
},
43+
&[0],
44+
&[1],
45+
);
46+
}
47+
48+
fn bench_storage(c: &mut Criterion) {
49+
bench_sync_state_method(
50+
c,
51+
"StateRef:storage",
52+
state_prep_no_op,
53+
|state, number_of_accounts, _, _| {
54+
for i in (1..=number_of_accounts).rev() {
55+
let result = state.storage(Address::from_low_u64_ne(i), U256::from(i));
56+
debug_assert!(result.is_ok());
57+
}
58+
},
59+
&Permutations::storage_scales(),
60+
&[1],
61+
);
62+
}
63+
64+
criterion_group!(benches, bench_basic, bench_code_by_hash, bench_storage,);
65+
criterion_main!(benches);
File renamed without changes.

0 commit comments

Comments
 (0)