Skip to content

Commit

Permalink
self-review
Browse files Browse the repository at this point in the history
  • Loading branch information
teh-cmc committed Jan 8, 2024
1 parent d314099 commit 70898d7
Showing 1 changed file with 123 additions and 105 deletions.
228 changes: 123 additions & 105 deletions crates/re_space_view_spatial/benches/bench_points.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use re_log_types::{DataRow, EntityPath, RowId, TimeInt, TimePoint, Timeline};
use re_space_view_spatial::{LoadedPoints, Points3DComponentData};
use re_types::{
archetypes::Points3D,
components::{Color, InstanceKey, Position3D, Radius, Text},
components::{ClassId, Color, InstanceKey, KeypointId, Position3D, Radius, Text},
Loggable as _,
};
use re_viewer_context::Annotations;
Expand All @@ -18,12 +18,21 @@ criterion::criterion_group!(benches, bench_points);

// ---

#[cfg(not(debug_assertions))]
const NUM_POINTS: usize = 1_000_000;

// `cargo test` also runs the benchmark setup code, so make sure they run quickly:
#[cfg(debug_assertions)]
const NUM_POINTS: usize = 10;
mod constants {
pub const NUM_POINTS: usize = 10;
pub const CACHED: &[bool] = &[true];
}

#[cfg(not(debug_assertions))]
mod constants {
pub const NUM_POINTS: usize = 1_000_000;
pub const CACHED: &[bool] = &[false, true];
}

#[allow(clippy::wildcard_imports)]
use self::constants::*;

// ---

Expand Down Expand Up @@ -55,21 +64,25 @@ fn bench_points(c: &mut criterion::Criterion) {
let latest_at = re_query_cache::AnyQuery::from(latest_at);
let annotations = Annotations::missing();

{
fn bench_name(cached: bool, name: &str) -> String {
format!("{name}/cached={cached}")
}

for cached in CACHED {
let mut group = c.benchmark_group("Points3D");
group.bench_function("query_archetype", |b| {
group.bench_function(bench_name(*cached, "query_archetype"), |b| {
b.iter(|| {
re_query_cache::query_archetype_pov1_comp5::<
Points3D,
Position3D,
Color,
Radius,
Text,
re_types::components::KeypointId,
re_types::components::ClassId,
KeypointId,
ClassId,
_,
>(
true,
*cached,
&store,
&latest_at,
&ent_path,
Expand All @@ -82,104 +95,109 @@ fn bench_points(c: &mut criterion::Criterion) {
});
}

re_query_cache::query_archetype_pov1_comp5::<
Points3D,
Position3D,
Color,
Radius,
Text,
re_types::components::KeypointId,
re_types::components::ClassId,
_,
>(
true,
&store,
&latest_at,
&ent_path,
|(_, instance_keys, positions, colors, radii, labels, keypoint_ids, class_ids)| {
let data = Points3DComponentData {
instance_keys: instance_keys.as_slice(),
positions: positions.as_slice(),
colors: colors.as_slice(),
radii: radii.as_slice(),
labels: labels.as_slice(),
keypoint_ids: keypoint_ids
.iter()
.any(Option::is_some)
.then_some(keypoint_ids.as_slice()),
class_ids: class_ids
.iter()
.any(Option::is_some)
.then_some(class_ids.as_slice()),
};
assert_eq!(data.instance_keys.len(), NUM_POINTS);

{
let mut group = c.benchmark_group("Points3D");
group.throughput(criterion::Throughput::Elements(NUM_POINTS as _));
group.bench_function("load_all", |b| {
b.iter(|| {
let points = LoadedPoints::load(&data, &ent_path, at, &annotations);
assert_eq!(points.positions.len(), NUM_POINTS);
assert_eq!(points.colors.len(), NUM_POINTS);
assert_eq!(points.radii.len(), NUM_POINTS); // NOTE: we don't log radii, but we should get a list of defaults!
points
for cached in CACHED {
re_query_cache::query_archetype_pov1_comp5::<
Points3D,
Position3D,
Color,
Radius,
Text,
KeypointId,
ClassId,
_,
>(
*cached,
&store,
&latest_at,
&ent_path,
|(_, instance_keys, positions, colors, radii, labels, keypoint_ids, class_ids)| {
let data = Points3DComponentData {
instance_keys: instance_keys.as_slice(),
positions: positions.as_slice(),
colors: colors.as_slice(),
radii: radii.as_slice(),
labels: labels.as_slice(),
keypoint_ids: keypoint_ids
.iter()
.any(Option::is_some)
.then_some(keypoint_ids.as_slice()),
class_ids: class_ids
.iter()
.any(Option::is_some)
.then_some(class_ids.as_slice()),
};
assert_eq!(data.instance_keys.len(), NUM_POINTS);

{
let mut group = c.benchmark_group("Points3D");
group.throughput(criterion::Throughput::Elements(NUM_POINTS as _));
group.bench_function(bench_name(*cached, "load_all"), |b| {
b.iter(|| {
let points = LoadedPoints::load(&data, &ent_path, at, &annotations);
assert_eq!(points.positions.len(), NUM_POINTS);
assert_eq!(points.colors.len(), NUM_POINTS);
assert_eq!(points.radii.len(), NUM_POINTS); // NOTE: we don't log radii, but we should get a list of defaults!
points
});
});
});
}

{
let mut group = c.benchmark_group("Points3D");
group.throughput(criterion::Throughput::Elements(NUM_POINTS as _));
group.bench_function("load_positions", |b| {
b.iter(|| {
let positions = LoadedPoints::load_positions(&data);
assert_eq!(positions.len(), NUM_POINTS);
positions
}

{
let mut group = c.benchmark_group("Points3D");
group.throughput(criterion::Throughput::Elements(NUM_POINTS as _));
group.bench_function(bench_name(*cached, "load_positions"), |b| {
b.iter(|| {
let positions = LoadedPoints::load_positions(&data);
assert_eq!(positions.len(), NUM_POINTS);
positions
});
});
});
}

{
let points = LoadedPoints::load(&data, &ent_path, at, &annotations);

let mut group = c.benchmark_group("Points3D");
group.throughput(criterion::Throughput::Elements(NUM_POINTS as _));
group.bench_function("load_colors", |b| {
b.iter(|| {
let colors =
LoadedPoints::load_colors(&data, &ent_path, &points.annotation_infos);
assert_eq!(colors.len(), NUM_POINTS);
colors
}

{
let points = LoadedPoints::load(&data, &ent_path, at, &annotations);

let mut group = c.benchmark_group("Points3D");
group.throughput(criterion::Throughput::Elements(NUM_POINTS as _));
group.bench_function(bench_name(*cached, "load_colors"), |b| {
b.iter(|| {
let colors = LoadedPoints::load_colors(
&data,
&ent_path,
&points.annotation_infos,
);
assert_eq!(colors.len(), NUM_POINTS);
colors
});
});
});
}

// NOTE: we don't log radii!
{
let mut group = c.benchmark_group("Points3D");
group.throughput(criterion::Throughput::Elements(NUM_POINTS as _));
group.bench_function("load_radii", |b| {
b.iter(|| {
let radii = LoadedPoints::load_radii(&data, &ent_path);
assert_eq!(radii.len(), NUM_POINTS);
radii
}

// NOTE: we don't log radii!
{
let mut group = c.benchmark_group("Points3D");
group.throughput(criterion::Throughput::Elements(NUM_POINTS as _));
group.bench_function(bench_name(*cached, "load_radii"), |b| {
b.iter(|| {
let radii = LoadedPoints::load_radii(&data, &ent_path);
assert_eq!(radii.len(), NUM_POINTS);
radii
});
});
});
}

{
let mut group = c.benchmark_group("Points3D");
group.throughput(criterion::Throughput::Elements(NUM_POINTS as _));
group.bench_function("load_picking_ids", |b| {
b.iter(|| {
let picking_ids = LoadedPoints::load_picking_ids(&data);
assert_eq!(picking_ids.len(), NUM_POINTS);
picking_ids
}

{
let mut group = c.benchmark_group("Points3D");
group.throughput(criterion::Throughput::Elements(NUM_POINTS as _));
group.bench_function(bench_name(*cached, "load_picking_ids"), |b| {
b.iter(|| {
let picking_ids = LoadedPoints::load_picking_ids(&data);
assert_eq!(picking_ids.len(), NUM_POINTS);
picking_ids
});
});
});
}
},
)
.unwrap();
}
},
)
.unwrap();
}
}

0 comments on commit 70898d7

Please sign in to comment.