mirror of
https://github.com/qdrant/qdrant.git
synced 2026-09-21 13:37:46 -05:00
HardwareCounterCell::disposable() Performance Improvement (#6511)
* Improve performance of HardwareCounterCell::disposable() by 72x * Fix ci
This commit is contained in:
@@ -61,3 +61,7 @@ harness = false
|
||||
[[bench]]
|
||||
name = "mmap_hashmap"
|
||||
harness = false
|
||||
|
||||
[[bench]]
|
||||
name = "hw_counter"
|
||||
harness = false
|
||||
|
||||
@@ -0,0 +1,20 @@
|
||||
use common::counter::hardware_accumulator::HwMeasurementAcc;
|
||||
use common::counter::hardware_counter::HardwareCounterCell;
|
||||
use criterion::{Criterion, criterion_group, criterion_main};
|
||||
|
||||
fn bench_hw_counter(c: &mut Criterion) {
|
||||
c.bench_function("Disposable Hw Cell", |b| {
|
||||
b.iter(|| {
|
||||
let _ = HardwareCounterCell::disposable();
|
||||
});
|
||||
});
|
||||
|
||||
c.bench_function("Disposable Hw Acc", |b| {
|
||||
b.iter(|| {
|
||||
let _ = HwMeasurementAcc::disposable();
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
criterion_group!(hw_counter, bench_hw_counter);
|
||||
criterion_main!(hw_counter);
|
||||
@@ -97,7 +97,7 @@ mod test {
|
||||
}
|
||||
|
||||
assert_eq!(parent.cpu_counter().get(), 0);
|
||||
assert_eq!(parent.accumulator.get_cpu(), 0);
|
||||
assert_eq!(parent.accumulator.as_ref().unwrap().get_cpu(), 0);
|
||||
}
|
||||
|
||||
#[test]
|
||||
@@ -111,7 +111,7 @@ mod test {
|
||||
|
||||
assert_eq!(parent.cpu_counter().get(), 5);
|
||||
|
||||
let parent_acc = parent.accumulator.clone();
|
||||
let parent_acc = parent.new_accumulator();
|
||||
drop(parent); // Parents accumulator gets written after `parent` drops.
|
||||
assert_eq!(parent_acc.get_cpu(), 5);
|
||||
}
|
||||
@@ -131,7 +131,7 @@ mod test {
|
||||
}
|
||||
|
||||
assert_eq!(parent.cpu_counter().get(), 0); // Parents accumulator gets written, not the counter cell!
|
||||
assert_eq!(parent.accumulator.get_cpu(), 5);
|
||||
assert_eq!(parent.accumulator.as_ref().unwrap().get_cpu(), 5);
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
||||
@@ -18,7 +18,7 @@ pub struct HardwareCounterCell {
|
||||
pub(super) payload_index_io_write_counter: CounterCell,
|
||||
pub(super) vector_io_read_counter: CounterCell,
|
||||
pub(super) vector_io_write_counter: CounterCell,
|
||||
pub(super) accumulator: HwMeasurementAcc,
|
||||
pub(super) accumulator: Option<HwMeasurementAcc>,
|
||||
}
|
||||
|
||||
#[cfg(feature = "testing")]
|
||||
@@ -50,7 +50,7 @@ impl HardwareCounterCell {
|
||||
payload_index_io_write_counter: CounterCell::new(),
|
||||
vector_io_read_counter: CounterCell::new(),
|
||||
vector_io_write_counter: CounterCell::new(),
|
||||
accumulator: HwMeasurementAcc::new(),
|
||||
accumulator: Some(HwMeasurementAcc::new()),
|
||||
}
|
||||
}
|
||||
|
||||
@@ -68,7 +68,7 @@ impl HardwareCounterCell {
|
||||
payload_index_io_write_counter: CounterCell::new(),
|
||||
vector_io_read_counter: CounterCell::new(),
|
||||
vector_io_write_counter: CounterCell::new(),
|
||||
accumulator: HwMeasurementAcc::disposable(),
|
||||
accumulator: None,
|
||||
}
|
||||
}
|
||||
|
||||
@@ -83,12 +83,14 @@ impl HardwareCounterCell {
|
||||
payload_index_io_write_counter: CounterCell::new(),
|
||||
vector_io_read_counter: CounterCell::new(),
|
||||
vector_io_write_counter: CounterCell::new(),
|
||||
accumulator,
|
||||
accumulator: Some(accumulator),
|
||||
}
|
||||
}
|
||||
|
||||
pub fn new_accumulator(&self) -> HwMeasurementAcc {
|
||||
self.accumulator.clone()
|
||||
self.accumulator
|
||||
.clone()
|
||||
.unwrap_or_else(HwMeasurementAcc::disposable)
|
||||
}
|
||||
|
||||
/// Create a copy of the current counter cell with the same accumulator and config,
|
||||
@@ -181,7 +183,9 @@ impl HardwareCounterCell {
|
||||
}
|
||||
|
||||
fn merge_to_accumulator(&self) {
|
||||
self.accumulator.accumulate(self.get_hw_data());
|
||||
if let Some(accumulator) = &self.accumulator {
|
||||
accumulator.accumulate(self.get_hw_data());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -201,7 +205,11 @@ impl Drop for HardwareCounterCell {
|
||||
impl From<&HardwareCounterCell> for HardwareData {
|
||||
fn from(value: &HardwareCounterCell) -> Self {
|
||||
let counter_values = value.get_hw_data();
|
||||
let acc_values = value.accumulator.hw_data();
|
||||
let acc_values = value
|
||||
.accumulator
|
||||
.as_ref()
|
||||
.map(|i| i.hw_data())
|
||||
.unwrap_or_default();
|
||||
counter_values + acc_values
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
use std::ops::Add;
|
||||
|
||||
/// Contains all hardware metrics. Only serves as value holding structure without any semantics.
|
||||
#[derive(Copy, Clone)]
|
||||
#[derive(Copy, Clone, Default)]
|
||||
pub struct HardwareData {
|
||||
pub cpu: usize,
|
||||
pub payload_io_read: usize,
|
||||
|
||||
Reference in New Issue
Block a user