feat: set up codspeed (#13372)

This commit is contained in:
DaniPopes
2024-12-20 13:21:51 +02:00
committed by GitHub
parent 3966130844
commit a4f86b0e2d
34 changed files with 318 additions and 398 deletions

View File

@ -1,6 +1,6 @@
#![allow(missing_docs, unreachable_pub)]
use criterion::{
black_box, criterion_group, criterion_main, measurement::WallTime, BenchmarkGroup, Criterion,
criterion_group, criterion_main, measurement::WallTime, BenchmarkGroup, Criterion,
};
use proptest::{
prelude::*,
@ -11,7 +11,7 @@ use reth_trie_common::{
prefix_set::{PrefixSet, PrefixSetMut},
Nibbles,
};
use std::collections::BTreeSet;
use std::{collections::BTreeSet, hint::black_box};
/// Abstraction for aggregating nibbles and freezing it to a type
/// that can be later used for benching.
@ -48,6 +48,12 @@ pub fn prefix_set_lookups(c: &mut Criterion) {
let mut group = c.benchmark_group("Prefix Set Lookups");
for size in [10, 100, 1_000, 10_000] {
// Too slow.
#[allow(unexpected_cfgs)]
if cfg!(codspeed) && size > 1_000 {
continue;
}
let test_data = generate_test_data(size);
use implementations::*;

View File

@ -54,6 +54,14 @@ proptest-arbitrary-interop.workspace = true
[features]
default = ["metrics"]
metrics = ["reth-metrics", "dep:metrics", "reth-trie/metrics"]
test-utils = [
"reth-trie/test-utils",
"reth-trie-common/test-utils",
"reth-db/test-utils",
"reth-primitives/test-utils",
"reth-provider/test-utils",
"reth-trie-db/test-utils",
]
[[bench]]
name = "root"

View File

@ -20,6 +20,12 @@ pub fn calculate_state_root(c: &mut Criterion) {
group.sample_size(20);
for size in [1_000, 3_000, 5_000, 10_000] {
// Too slow.
#[allow(unexpected_cfgs)]
if cfg!(codspeed) && size > 3_000 {
continue;
}
let (db_state, updated_state) = generate_test_data(size);
let provider_factory = create_test_provider_factory();
{

View File

@ -41,6 +41,19 @@ proptest-arbitrary-interop.workspace = true
proptest.workspace = true
rand.workspace = true
[features]
test-utils = [
"reth-primitives-traits/test-utils",
"reth-trie/test-utils",
"reth-trie-common/test-utils",
]
arbitrary = [
"reth-primitives-traits/arbitrary",
"reth-trie-common/arbitrary",
"alloy-primitives/arbitrary",
"smallvec/arbitrary",
]
[[bench]]
name = "root"
harness = false

View File

@ -1,6 +1,4 @@
#![allow(missing_docs, unreachable_pub)]
use std::time::{Duration, Instant};
#![allow(missing_docs)]
use alloy_primitives::{B256, U256};
use criterion::{criterion_group, criterion_main, Criterion};
@ -11,7 +9,7 @@ use reth_testing_utils::generators;
use reth_trie::Nibbles;
use reth_trie_sparse::RevealedSparseTrie;
pub fn update_rlp_node_level(c: &mut Criterion) {
fn update_rlp_node_level(c: &mut Criterion) {
let mut rng = generators::rng();
let mut group = c.benchmark_group("update rlp node level");
@ -53,20 +51,11 @@ pub fn update_rlp_node_level(c: &mut Criterion) {
group.bench_function(
format!("size {size} | updated {updated_leaves}% | depth {depth}"),
|b| {
// Use `iter_custom` to avoid measuring clones and drops
b.iter_custom(|iters| {
let mut elapsed = Duration::ZERO;
let mut cloned = sparse.clone();
for _ in 0..iters {
let start = Instant::now();
cloned.update_rlp_node_level(depth);
elapsed += start.elapsed();
cloned = sparse.clone();
}
elapsed
})
b.iter_batched_ref(
|| sparse.clone(),
|cloned| cloned.update_rlp_node_level(depth),
criterion::BatchSize::PerIteration,
)
},
);
}

View File

@ -1,4 +1,4 @@
#![allow(missing_docs, unreachable_pub)]
#![allow(missing_docs)]
use alloy_primitives::{map::B256HashMap, B256, U256};
use criterion::{criterion_group, criterion_main, BenchmarkId, Criterion};
@ -15,11 +15,17 @@ use reth_trie::{
use reth_trie_common::{HashBuilder, Nibbles};
use reth_trie_sparse::SparseTrie;
pub fn calculate_root_from_leaves(c: &mut Criterion) {
fn calculate_root_from_leaves(c: &mut Criterion) {
let mut group = c.benchmark_group("calculate root from leaves");
group.sample_size(20);
for size in [1_000, 5_000, 10_000, 100_000] {
// Too slow.
#[allow(unexpected_cfgs)]
if cfg!(codspeed) && size > 5_000 {
continue;
}
let state = generate_test_data(size);
// hash builder
@ -29,6 +35,7 @@ pub fn calculate_root_from_leaves(c: &mut Criterion) {
hb.add_leaf(Nibbles::unpack(key), &alloy_rlp::encode_fixed_size(value));
}
hb.root();
hb
})
});
@ -44,19 +51,32 @@ pub fn calculate_root_from_leaves(c: &mut Criterion) {
.unwrap();
}
sparse.root().unwrap();
sparse
})
});
}
}
pub fn calculate_root_from_leaves_repeated(c: &mut Criterion) {
fn calculate_root_from_leaves_repeated(c: &mut Criterion) {
let mut group = c.benchmark_group("calculate root from leaves repeated");
group.sample_size(20);
for init_size in [1_000, 10_000, 100_000] {
// Too slow.
#[allow(unexpected_cfgs)]
if cfg!(codspeed) && init_size > 10_000 {
continue;
}
let init_state = generate_test_data(init_size);
for update_size in [100, 1_000, 5_000, 10_000] {
// Too slow.
#[allow(unexpected_cfgs)]
if cfg!(codspeed) && update_size > 1_000 {
continue;
}
for num_updates in [1, 3, 5, 10] {
let updates =
(0..num_updates).map(|_| generate_test_data(update_size)).collect::<Vec<_>>();

View File

@ -61,19 +61,20 @@ criterion.workspace = true
[features]
metrics = ["reth-metrics", "dep:metrics"]
serde = [
"alloy-primitives/serde",
"alloy-consensus/serde",
"alloy-trie/serde",
"alloy-primitives/serde",
"alloy-consensus/serde",
"alloy-trie/serde",
"alloy-eips/serde",
"revm/serde",
"reth-trie-common/serde"
"revm/serde",
"reth-trie-common/serde",
]
test-utils = [
"triehash",
"revm/test-utils",
"reth-primitives/test-utils",
"reth-trie-common/test-utils",
"reth-stages-types/test-utils"
"triehash",
"revm/test-utils",
"reth-primitives/test-utils",
"reth-trie-common/test-utils",
"reth-trie-sparse/test-utils",
"reth-stages-types/test-utils",
]
[[bench]]

View File

@ -10,6 +10,12 @@ pub fn hash_post_state(c: &mut Criterion) {
group.sample_size(20);
for size in [100, 1_000, 3_000, 5_000, 10_000] {
// Too slow.
#[allow(unexpected_cfgs)]
if cfg!(codspeed) && size > 1_000 {
continue;
}
let state = generate_test_data(size);
// sequence

View File

@ -1,10 +1,11 @@
#![allow(missing_docs, unreachable_pub)]
use alloy_primitives::B256;
use criterion::{black_box, criterion_group, criterion_main, Criterion};
use criterion::{criterion_group, criterion_main, Criterion};
use proptest::{prelude::*, strategy::ValueTree, test_runner::TestRunner};
use proptest_arbitrary_interop::arb;
use reth_primitives::{Receipt, ReceiptWithBloom};
use reth_trie::triehash::KeccakHasher;
use std::hint::black_box;
/// Benchmarks different implementations of the root calculation.
pub fn trie_root_benchmark(c: &mut Criterion) {