-
Notifications
You must be signed in to change notification settings - Fork 369
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Optimize gathering of point cloud colors (#3730)
Saves around 2ms of native CPU-time on OPF. On native this is mostly hidden by the parallelism, but on web it is a real saving. Found by looking at the in-browser profiler. ### What ### Checklist * [x] I have read and agree to [Contributor Guide](https://github.com/rerun-io/rerun/blob/main/CONTRIBUTING.md) and the [Code of Conduct](https://github.com/rerun-io/rerun/blob/main/CODE_OF_CONDUCT.md) * [x] I've included a screenshot or gif (if applicable) * [x] I have tested [demo.rerun.io](https://demo.rerun.io/pr/3730) (if applicable) * [x] The PR title and labels are set such as to maximize their usefulness for the next release's CHANGELOG - [PR Build Summary](https://build.rerun.io/pr/3730) - [Docs preview](https://rerun.io/preview/a55c07912e4d24103187b05e34ffa4dc4a606da2/docs) <!--DOCS-PREVIEW--> - [Examples preview](https://rerun.io/preview/a55c07912e4d24103187b05e34ffa4dc4a606da2/examples) <!--EXAMPLES-PREVIEW--> - [Recent benchmark results](https://ref.rerun.io/dev/bench/) - [Wasm size tracking](https://ref.rerun.io/dev/sizes/)
- Loading branch information
Showing
13 changed files
with
428 additions
and
156 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,134 @@ | ||
//! High-level benchmark of the CPU-side of our `Points3D` rendering. | ||
use re_arrow_store::{DataStore, LatestAtQuery}; | ||
use re_log_types::{DataRow, EntityPath, RowId, TimeInt, TimePoint, Timeline}; | ||
use re_space_view_spatial::LoadedPoints; | ||
use re_types::{ | ||
archetypes::Points3D, | ||
components::{Color, InstanceKey, Position3D}, | ||
Loggable as _, | ||
}; | ||
use re_viewer_context::Annotations; | ||
|
||
#[global_allocator] | ||
static GLOBAL: mimalloc::MiMalloc = mimalloc::MiMalloc; | ||
|
||
criterion::criterion_main!(benches); | ||
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; | ||
|
||
// --- | ||
|
||
/// Mimics `examples/python/open_photogrammetry_format/main.py` | ||
fn bench_points(c: &mut criterion::Criterion) { | ||
let timeline = Timeline::log_time(); | ||
let ent_path = EntityPath::from("points"); | ||
|
||
let store = { | ||
let mut store = DataStore::new(InstanceKey::name(), Default::default()); | ||
|
||
let positions = vec![Position3D::new(0.1, 0.2, 0.3); NUM_POINTS]; | ||
let colors = vec![Color::from(0xffffffff); NUM_POINTS]; | ||
let points = Points3D::new(positions).with_colors(colors); | ||
let mut timepoint = TimePoint::default(); | ||
timepoint.insert(timeline, TimeInt::from_seconds(0)); | ||
let data_row = | ||
DataRow::from_archetype(RowId::random(), timepoint, ent_path.clone(), &points).unwrap(); | ||
store.insert_row(&data_row).unwrap(); | ||
store | ||
}; | ||
|
||
let latest_at = LatestAtQuery::latest(timeline); | ||
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 | ||
}); | ||
}); | ||
} | ||
|
||
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 | ||
}); | ||
}); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.