Skip to content

Commit

Permalink
add cache support to point bench
Browse files Browse the repository at this point in the history
  • Loading branch information
teh-cmc committed Jan 4, 2024
1 parent 61a5b97 commit 314e884
Showing 1 changed file with 123 additions and 76 deletions.
199 changes: 123 additions & 76 deletions crates/re_space_view_spatial/benches/bench_points.rs
Original file line number Diff line number Diff line change
@@ -2,10 +2,10 @@
use re_data_store::{DataStore, LatestAtQuery};
use re_log_types::{DataRow, EntityPath, RowId, TimeInt, TimePoint, Timeline};
use re_space_view_spatial::LoadedPoints;
use re_space_view_spatial::{LoadedPoints, Points3DComponentData};
use re_types::{
archetypes::Points3D,
components::{Color, InstanceKey, Position3D},
components::{Color, InstanceKey, Position3D, Radius, Text},
Loggable as _,
};
use re_viewer_context::Annotations;
@@ -51,88 +51,135 @@ fn bench_points(c: &mut criterion::Criterion) {
};

let latest_at = LatestAtQuery::latest(timeline);
let at = latest_at.at;
let latest_at = re_query_cache::AnyQuery::from(latest_at);
let annotations = Annotations::missing();

{
let mut group = c.benchmark_group("Points3D");
group.bench_function("query_archetype", |b| {
b.iter(|| {
let arch_view =
re_query::query_archetype::<Points3D>(&store, &latest_at, &ent_path).unwrap();
assert_eq!(arch_view.num_instances(), NUM_POINTS);
arch_view
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,
|(_, keys, _, _, _, _, _, _)| {
assert_eq!(keys.as_slice().len(), NUM_POINTS);
},
)
.unwrap();
});
});
}

let arch_view = re_query::query_archetype::<Points3D>(&store, &latest_at, &ent_path).unwrap();
assert_eq!(arch_view.num_instances(), 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(&arch_view, &ent_path, latest_at.at, &annotations).unwrap();
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(&arch_view).unwrap();
assert_eq!(positions.len(), NUM_POINTS);
positions
});
});
}

{
let points = LoadedPoints::load(&arch_view, &ent_path, latest_at.at, &annotations).unwrap();

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(&arch_view, &ent_path, &points.annotation_infos)
.unwrap();
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(&arch_view, &ent_path).unwrap();
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(&arch_view);
assert_eq!(picking_ids.len(), NUM_POINTS);
picking_ids
});
});
}
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
});
});
}

{
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 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
});
});
}

// 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
});
});
}

{
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
});
});
}
},
)
.unwrap();
}

0 comments on commit 314e884

Please sign in to comment.