Skip to content

Commit

Permalink
Squashed commit of the following:
Browse files Browse the repository at this point in the history
commit 731d941
Author: benjamin de charmoy <BenjaminDev@users.noreply.github.com>
Date:   Sat Apr 1 10:57:19 2023 +0200

    Fix logged obb being displayed with half of the requested size (#1749)

commit 1e84aa5
Author: Clement Rey <cr.rey.clement@gmail.com>
Date:   Fri Mar 31 17:43:57 2023 +0200

    `arrow2_convert` primitive (de)serialization benchmarks (#1742)

    * arrow2_convert primitive benchmarks

    * addressing PR comments
  • Loading branch information
teh-cmc committed Apr 1, 2023
1 parent ae49253 commit 824c0f3
Show file tree
Hide file tree
Showing 3 changed files with 146 additions and 1 deletion.
4 changes: 4 additions & 0 deletions crates/re_arrow_store/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -115,3 +115,7 @@ harness = false
[[bench]]
name = "arrow2"
harness = false

[[bench]]
name = "arrow2_convert"
harness = false
141 changes: 141 additions & 0 deletions crates/re_arrow_store/benches/arrow2_convert.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,141 @@
//! Keeping track of performance issues/regressions in `arrow2_convert` that directly affect us.
#[global_allocator]
static GLOBAL: mimalloc::MiMalloc = mimalloc::MiMalloc;

use arrow2::{array::PrimitiveArray, datatypes::PhysicalType, types::PrimitiveType};
use criterion::{criterion_group, criterion_main, Criterion};
use re_log_types::{
component_types::InstanceKey, external::arrow2_convert::deserialize::TryIntoCollection,
Component as _, DataCell,
};

// ---

criterion_group!(benches, serialize, deserialize);
criterion_main!(benches);

// ---

#[cfg(not(debug_assertions))]
const NUM_INSTANCES: usize = 100_000;

// `cargo test` also runs the benchmark setup code, so make sure they run quickly:
#[cfg(debug_assertions)]
const NUM_INSTANCES: usize = 1;

// ---

fn serialize(c: &mut Criterion) {
let mut group = c.benchmark_group(format!(
"arrow2_convert/serialize/primitive/instances={NUM_INSTANCES}"
));
group.throughput(criterion::Throughput::Elements(NUM_INSTANCES as _));

{
group.bench_function("arrow2_convert", |b| {
b.iter(|| {
let cell = DataCell::from_component::<InstanceKey>(0..NUM_INSTANCES as u64);
assert_eq!(NUM_INSTANCES as u32, cell.num_instances());
assert_eq!(
cell.datatype().to_physical_type(),
PhysicalType::Primitive(PrimitiveType::UInt64)
);
cell
});
});
}

{
group.bench_function("arrow2/from_values", |b| {
b.iter(|| {
let values = PrimitiveArray::from_values(0..NUM_INSTANCES as u64).boxed();
let cell = crate::DataCell::from_arrow(InstanceKey::name(), values);
assert_eq!(NUM_INSTANCES as u32, cell.num_instances());
assert_eq!(
cell.datatype().to_physical_type(),
PhysicalType::Primitive(PrimitiveType::UInt64)
);
cell
});
});
}

{
group.bench_function("arrow2/from_vec", |b| {
b.iter(|| {
// NOTE: We do the `collect()` here on purpose!
//
// All of these APIs have to allocate an array under the hood, except `from_vec`
// which is O(1) (it just unsafely reuses the vec's data pointer).
// We need to measure the collection in order to have a leveled playing field.
let values = PrimitiveArray::from_vec((0..NUM_INSTANCES as u64).collect()).boxed();
let cell = crate::DataCell::from_arrow(InstanceKey::name(), values);
assert_eq!(NUM_INSTANCES as u32, cell.num_instances());
assert_eq!(
cell.datatype().to_physical_type(),
PhysicalType::Primitive(PrimitiveType::UInt64)
);
cell
});
});
}
}

fn deserialize(c: &mut Criterion) {
let mut group = c.benchmark_group(format!(
"arrow2_convert/deserialize/primitive/instances={NUM_INSTANCES}"
));
group.throughput(criterion::Throughput::Elements(NUM_INSTANCES as _));

let cell = DataCell::from_component::<InstanceKey>(0..NUM_INSTANCES as u64);
let data = cell.as_arrow();

{
group.bench_function("arrow2_convert", |b| {
b.iter(|| {
let keys: Vec<InstanceKey> = data.as_ref().try_into_collection().unwrap();
assert_eq!(NUM_INSTANCES, keys.len());
assert_eq!(
InstanceKey(NUM_INSTANCES as u64 / 2),
keys[NUM_INSTANCES / 2]
);
keys
});
});
}

{
group.bench_function("arrow2/validity_checks", |b| {
b.iter(|| {
let data = data.as_any().downcast_ref::<PrimitiveArray<u64>>().unwrap();
let keys: Vec<InstanceKey> = data
.into_iter()
.filter_map(|v| v.copied().map(InstanceKey))
.collect();
assert_eq!(NUM_INSTANCES, keys.len());
assert_eq!(
InstanceKey(NUM_INSTANCES as u64 / 2),
keys[NUM_INSTANCES / 2]
);
keys
});
});
}

{
group.bench_function("arrow2/validity_bypass", |b| {
b.iter(|| {
let data = data.as_any().downcast_ref::<PrimitiveArray<u64>>().unwrap();
assert!(data.validity().is_none());
let keys: Vec<InstanceKey> = data.values_iter().copied().map(InstanceKey).collect();
assert_eq!(NUM_INSTANCES, keys.len());
assert_eq!(
InstanceKey(NUM_INSTANCES as u64 / 2),
keys[NUM_INSTANCES / 2]
);
keys
});
});
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ impl Boxes3DPart {
let color =
annotation_info.color(color.map(move |c| c.to_array()).as_ref(), default_color);

let scale = glam::Vec3::from(half_size);
let scale = glam::Vec3::from(half_size) * 2.0;
let rot = rotation.map(glam::Quat::from).unwrap_or_default();
let tran = position.map_or(glam::Vec3::ZERO, glam::Vec3::from);
let transform = glam::Affine3A::from_scale_rotation_translation(scale, rot, tran);
Expand Down

0 comments on commit 824c0f3

Please # to comment.