Files
qdrant/lib/segment/benches/buffered_update_bitslice.rs
Arnaud GourlayandClaude Fable 5 c196d2eb1a Benches: use SmallRng instead of ChaCha12-based generators (#9887)
* Benches: use SmallRng instead of ChaCha12-based generators

All benchmarks used StdRng or rand::rng() (ThreadRng), both backed by the
ChaCha12 block cipher in rand 0.10. Benchmarks do not need crypto-strength
randomness, and several draw random values inside the timed closure, so
cipher work was included in the measurement itself.

Switch every bench target to SmallRng (Xoshiro256++), and key the HNSW
graph cache and sparse index cache by RNG algorithm so stale caches built
from the old generator are not reused against newly generated vectors.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>

* Benches: replace free-function rand::random with local SmallRng

Addresses review: rand::random draws from the thread RNG (ChaCha12),
including inside the timed loop of the pq score benchmark.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>

---------

Co-authored-by: Claude Fable 5 <noreply@anthropic.com>
2026-07-17 17:22:27 +02:00

74 lines
2.2 KiB
Rust

use std::hint::black_box;
use std::iter;
use common::mmap::create_and_ensure_length;
use common::stored_bitslice::MmapBitSlice;
use common::universal_io::{MmapFs, OpenOptions};
use criterion::{Criterion, criterion_group, criterion_main};
use rand::prelude::*;
use rand::rngs::SmallRng;
use segment::common::buffered_update_bitslice::BufferedUpdateBitSlice;
use tempfile::tempdir;
const SIZE: usize = 4 * 1024 * 1024;
const FLAG_COUNT: usize = 1_000_000;
const LOOKUP_COUNT: usize = 1_000_000;
fn buffered_update_bitslice(c: &mut Criterion) {
let mut rng = SmallRng::seed_from_u64(42);
let dir = tempdir().unwrap();
let path = dir.path().join("bitslice.bin");
let _ = create_and_ensure_length(
&path,
SIZE.div_ceil(u8::BITS as usize)
.next_multiple_of(size_of::<u64>()),
)
.unwrap();
let bitslice_storage =
MmapBitSlice::open(&MmapFs, &path, OpenOptions::new_for_test(), ()).unwrap();
let buffered_update_bitslice = BufferedUpdateBitSlice::new(bitslice_storage);
// Set random flags and persist
for _ in 0..FLAG_COUNT {
buffered_update_bitslice.set(rng.random::<u64>() as usize % SIZE, rng.random());
}
buffered_update_bitslice.flusher()().unwrap();
let mut group = c.benchmark_group("buffered-update-bitslice");
let lookups: Vec<_> = iter::repeat_with(|| rng.random::<u64>() as usize % SIZE)
.take(LOOKUP_COUNT)
.collect();
group.bench_function("lookup-without-pending-changes", |b| {
b.iter(|| {
for lookup in &lookups {
black_box(buffered_update_bitslice.get(*lookup).unwrap());
}
});
});
// Set random flags and keep them in pending changes list
for _ in 0..FLAG_COUNT {
buffered_update_bitslice.set(rng.random::<u64>() as usize % SIZE, rng.random());
}
group.bench_function("lookup-with-pending-changes", |b| {
b.iter(|| {
for lookup in &lookups {
black_box(buffered_update_bitslice.get(*lookup).unwrap());
}
});
});
}
criterion_group! {
name = benches;
config = Criterion::default();
targets = buffered_update_bitslice
}
criterion_main!(benches);