Opt: optimize dedup hash filter reset (#25555)
* refactor compute_hash * optimize dedup filter reset * clippy * clippy2 * Revert "refactor compute_hash" This reverts commit 4d09ad07f71c8cd634d405876ae8139a5e7a121a.
This commit is contained in:
parent
b09faf4cee
commit
ae9513f00a
|
@ -0,0 +1,46 @@
|
|||
#![feature(test)]
|
||||
|
||||
extern crate test;
|
||||
|
||||
use {
|
||||
std::sync::atomic::{AtomicU64, Ordering},
|
||||
test::Bencher,
|
||||
};
|
||||
|
||||
const N: usize = 1_000_000;
|
||||
|
||||
// test bench_reset1 ... bench: 436,240 ns/iter (+/- 176,714)
|
||||
// test bench_reset2 ... bench: 274,007 ns/iter (+/- 129,552)
|
||||
|
||||
#[bench]
|
||||
fn bench_reset1(bencher: &mut Bencher) {
|
||||
solana_logger::setup();
|
||||
|
||||
let mut v = Vec::with_capacity(N);
|
||||
v.resize_with(N, AtomicU64::default);
|
||||
|
||||
bencher.iter(|| {
|
||||
test::black_box({
|
||||
for i in &v {
|
||||
i.store(0, Ordering::Relaxed);
|
||||
}
|
||||
0
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
#[bench]
|
||||
fn bench_reset2(bencher: &mut Bencher) {
|
||||
solana_logger::setup();
|
||||
|
||||
let mut v = Vec::with_capacity(N);
|
||||
v.resize_with(N, AtomicU64::default);
|
||||
|
||||
bencher.iter(|| {
|
||||
test::black_box({
|
||||
v.clear();
|
||||
v.resize_with(N, AtomicU64::default);
|
||||
0
|
||||
});
|
||||
});
|
||||
}
|
|
@ -476,9 +476,9 @@ impl Deduper {
|
|||
//false positive rate is 1/1000 at that point
|
||||
let saturated = self.saturated.load(Ordering::Relaxed);
|
||||
if saturated || now.duration_since(self.age) > self.max_age {
|
||||
for i in &self.filter {
|
||||
i.store(0, Ordering::Relaxed);
|
||||
}
|
||||
let len = self.filter.len();
|
||||
self.filter.clear();
|
||||
self.filter.resize_with(len, AtomicU64::default);
|
||||
self.seed = thread_rng().gen();
|
||||
self.age = now;
|
||||
self.saturated.store(false, Ordering::Relaxed);
|
||||
|
|
Loading…
Reference in New Issue