From 97bd81a32b352dc8d51c1a064be492f1f048ddba Mon Sep 17 00:00:00 2001 From: Brooks Prumo Date: Wed, 22 Jun 2022 07:41:06 -0500 Subject: [PATCH] Add bench for StatusCache::slot_deltas() (#26123) --- runtime/benches/status_cache.rs | 24 ++++++++++++++++++------ runtime/src/bank.rs | 2 +- 2 files changed, 19 insertions(+), 7 deletions(-) diff --git a/runtime/benches/status_cache.rs b/runtime/benches/status_cache.rs index bced5d55b7..b95e41add0 100644 --- a/runtime/benches/status_cache.rs +++ b/runtime/benches/status_cache.rs @@ -1,10 +1,9 @@ #![feature(test)] - extern crate test; use { bincode::serialize, - solana_runtime::status_cache::*, + solana_runtime::{bank::BankStatusCache, status_cache::*}, solana_sdk::{ hash::{hash, Hash}, signature::Signature, @@ -12,10 +11,8 @@ use { test::Bencher, }; -type BankStatusCache = StatusCache<()>; - #[bench] -fn test_statuscache_serialize(bencher: &mut Bencher) { +fn bench_status_cache_serialize(bencher: &mut Bencher) { let mut status_cache = BankStatusCache::default(); status_cache.add_root(0); status_cache.clear(); @@ -28,10 +25,25 @@ fn test_statuscache_serialize(bencher: &mut Bencher) { id = hash(id.as_ref()); sigbytes.extend(id.as_ref()); let sig = Signature::new(&sigbytes); - status_cache.insert(&blockhash, &sig, 0, ()); + status_cache.insert(&blockhash, &sig, 0, Ok(())); } } bencher.iter(|| { let _ = serialize(&status_cache.slot_deltas(&[0])).unwrap(); }); } + +#[bench] +fn bench_status_cache_slot_deltas(bencher: &mut Bencher) { + let mut status_cache = BankStatusCache::default(); + + // fill the status cache + let slots: Vec<_> = (42..).take(MAX_CACHE_ENTRIES).collect(); + for slot in &slots { + for _ in 0..5 { + status_cache.insert(&Hash::new_unique(), Hash::new_unique(), *slot, Ok(())); + } + } + + bencher.iter(|| test::black_box(status_cache.slot_deltas(&slots))); +} diff --git a/runtime/src/bank.rs b/runtime/src/bank.rs index 22e11dfdc5..cefd1c1e19 100644 --- a/runtime/src/bank.rs +++ b/runtime/src/bank.rs @@ -250,7 +250,7 @@ impl RentDebits { } } -type BankStatusCache = StatusCache>; +pub type BankStatusCache = StatusCache>; #[frozen_abi(digest = "2YZk2K45HmmAafmxPJnYVXyQ7uA7WuBrRkpwrCawdK31")] pub type BankSlotDelta = SlotDelta>;