diff --git a/crates/chia-bls/benches/cache.rs b/crates/chia-bls/benches/cache.rs index 4498c66e5..c2960373c 100644 --- a/crates/chia-bls/benches/cache.rs +++ b/crates/chia-bls/benches/cache.rs @@ -24,41 +24,49 @@ fn cache_benchmark(c: &mut Criterion) { } let bls_cache = BlsCache::default(); - c.bench_function("bls_cache.aggregate_verify, 0% cache hits", |b| { b.iter(|| { + let bls_cache = bls_cache.clone(); assert!(bls_cache.aggregate_verify(pks.iter().zip([&msg].iter().cycle()), &agg_sig)); }); }); // populate 10% of keys + let bls_cache = BlsCache::default(); bls_cache.aggregate_verify(pks[0..100].iter().zip([&msg].iter().cycle()), &agg_sig); c.bench_function("bls_cache.aggregate_verify, 10% cache hits", |b| { b.iter(|| { + let bls_cache = bls_cache.clone(); assert!(bls_cache.aggregate_verify(pks.iter().zip([&msg].iter().cycle()), &agg_sig)); }); }); // populate another 10% of keys - bls_cache.aggregate_verify(pks[100..200].iter().zip([&msg].iter().cycle()), &agg_sig); + let bls_cache = BlsCache::default(); + bls_cache.aggregate_verify(pks[0..200].iter().zip([&msg].iter().cycle()), &agg_sig); c.bench_function("bls_cache.aggregate_verify, 20% cache hits", |b| { b.iter(|| { + let bls_cache = bls_cache.clone(); assert!(bls_cache.aggregate_verify(pks.iter().zip([&msg].iter().cycle()), &agg_sig)); }); }); // populate another 30% of keys - bls_cache.aggregate_verify(pks[200..500].iter().zip([&msg].iter().cycle()), &agg_sig); + let bls_cache = BlsCache::default(); + bls_cache.aggregate_verify(pks[0..500].iter().zip([&msg].iter().cycle()), &agg_sig); c.bench_function("bls_cache.aggregate_verify, 50% cache hits", |b| { b.iter(|| { + let bls_cache = bls_cache.clone(); assert!(bls_cache.aggregate_verify(pks.iter().zip([&msg].iter().cycle()), &agg_sig)); }); }); // populate all other keys - bls_cache.aggregate_verify(pks[500..1000].iter().zip([&msg].iter().cycle()), &agg_sig); + let bls_cache = BlsCache::default(); + bls_cache.aggregate_verify(pks[0..1000].iter().zip([&msg].iter().cycle()), &agg_sig); c.bench_function("bls_cache.aggregate_verify, 100% cache hits", |b| { b.iter(|| { + let bls_cache = bls_cache.clone(); assert!(bls_cache.aggregate_verify(pks.iter().zip([&msg].iter().cycle()), &agg_sig)); }); }); diff --git a/crates/chia-bls/src/bls_cache.rs b/crates/chia-bls/src/bls_cache.rs index 355c2e017..e97af3f2e 100644 --- a/crates/chia-bls/src/bls_cache.rs +++ b/crates/chia-bls/src/bls_cache.rs @@ -22,6 +22,14 @@ pub struct BlsCache { cache: Mutex>, } +impl Clone for BlsCache { + fn clone(&self) -> Self { + Self { + cache: Mutex::new(self.cache.lock().clone()), + } + } +} + impl Default for BlsCache { fn default() -> Self { Self::new(NonZeroUsize::new(50000).unwrap())