feat(trie): use global thread pool in async state root calculation (#11057)

This commit is contained in:
Federico Gimenez
2024-09-23 19:45:12 +02:00
committed by GitHub
parent b29ff1f6cc
commit efa5d45e4e
4 changed files with 21 additions and 45 deletions

View File

@ -3,13 +3,11 @@ use alloy_primitives::{B256, U256};
use criterion::{criterion_group, criterion_main, BenchmarkId, Criterion};
use proptest::{prelude::*, strategy::ValueTree, test_runner::TestRunner};
use proptest_arbitrary_interop::arb;
use rayon::ThreadPoolBuilder;
use reth_primitives::Account;
use reth_provider::{
providers::ConsistentDbView, test_utils::create_test_provider_factory, StateChangeWriter,
TrieWriter,
};
use reth_tasks::pool::BlockingTaskPool;
use reth_trie::{
hashed_cursor::HashedPostStateCursorFactory, HashedPostState, HashedStorage, StateRoot,
TrieInput,
@ -23,7 +21,6 @@ pub fn calculate_state_root(c: &mut Criterion) {
group.sample_size(20);
let runtime = tokio::runtime::Runtime::new().unwrap();
let blocking_pool = BlockingTaskPool::new(ThreadPoolBuilder::default().build().unwrap());
for size in [1_000, 3_000, 5_000, 10_000] {
let (db_state, updated_state) = generate_test_data(size);
@ -77,13 +74,7 @@ pub fn calculate_state_root(c: &mut Criterion) {
// async root
group.bench_function(BenchmarkId::new("async root", size), |b| {
b.to_async(&runtime).iter_with_setup(
|| {
AsyncStateRoot::new(
view.clone(),
blocking_pool.clone(),
TrieInput::from_state(updated_state.clone()),
)
},
|| AsyncStateRoot::new(view.clone(), TrieInput::from_state(updated_state.clone())),
|calculator| calculator.incremental_root(),
);
});