Skip to content

Commit

Permalink
squashed origin/main
Browse files Browse the repository at this point in the history
commit 4439309
Author: Clement Rey <[email protected]>
Date:   Mon Apr 3 12:31:17 2023 +0200

    `arrow2` erased refcounted clones benchmarks (#1745)

    * arrow2 erased refcounted clone benchmarks

    * lint

    * addressing PR comments

    * dude

commit 2728854
Author: Andreas Reich <[email protected]>
Date:   Mon Apr 3 11:49:38 2023 +0200

    Improve dealing with raw buffers for texture read/write (#1744)

    * Replace TextureRowDataInfo with the more versatile Texture2DBufferInfo

    * comment & naming fixes

commit d5b68f2
Author: Andreas Reich <[email protected]>
Date:   Mon Apr 3 10:01:46 2023 +0200

    Tracked 3D cameras lead now to on-hover rays in other space views that show the same camera but don't track it. (#1751)

    In the same way as a 2D scene causes a on-hover ray in all space views that contain the space camera at which the 2D view "sits".

commit ef2b5dc
Author: Clement Rey <[email protected]>
Date:   Sat Apr 1 16:15:11 2023 +0200

    benchmarks for common vector ops across `smallvec`/`tinyvec`/std (#1747)

    * benchmarks for common vector ops

    * handle N=1

commit 731d941
Author: benjamin de charmoy <[email protected]>
Date:   Sat Apr 1 10:57:19 2023 +0200

    Fix logged obb being displayed with half of the requested size (#1749)
  • Loading branch information
teh-cmc committed Apr 3, 2023
1 parent 9c96f45 commit f666f1d
Show file tree
Hide file tree
Showing 17 changed files with 780 additions and 139 deletions.
2 changes: 2 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions crates/re_arrow_store/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,8 @@ polars-core = { workspace = true, features = [
"sort_multiple",
] }
rand = "0.8"
smallvec = { version = "1.0", features = ["const_generics", "union"] }
tinyvec = { version = "1.6", features = ["alloc", "rustc_1_55"] }


[lib]
Expand Down Expand Up @@ -119,3 +121,7 @@ harness = false
[[bench]]
name = "arrow2_convert"
harness = false

[[bench]]
name = "vectors"
harness = false
215 changes: 211 additions & 4 deletions crates/re_arrow_store/benches/arrow2.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,24 @@
#[global_allocator]
static GLOBAL: mimalloc::MiMalloc = mimalloc::MiMalloc;

use arrow2::{array::Array, compute::aggregate::estimated_bytes_size};
use std::sync::Arc;

use arrow2::{
array::{Array, PrimitiveArray, StructArray},
compute::aggregate::estimated_bytes_size,
};
use criterion::{criterion_group, criterion_main, Criterion};
use itertools::Itertools;
use re_log_types::{
component_types::{InstanceKey, Point2D, Rect2D},
datagen::{build_some_instances, build_some_point2d, build_some_rects},
external::arrow2_convert::serialize::TryIntoArrow,
SerializableComponent,
DataCell, SerializableComponent,
};

// ---

criterion_group!(benches, estimated_size_bytes);
criterion_group!(benches, erased_clone, estimated_size_bytes);
criterion_main!(benches);

// ---
Expand Down Expand Up @@ -54,7 +60,7 @@ impl std::fmt::Display for ArrayKind {
}
}

fn estimated_size_bytes(c: &mut Criterion) {
fn erased_clone(c: &mut Criterion) {
let kind = [
ArrayKind::Primitive,
ArrayKind::Struct,
Expand Down Expand Up @@ -164,3 +170,204 @@ fn estimated_size_bytes(c: &mut Criterion) {
}
}
}

fn estimated_size_bytes(c: &mut Criterion) {
let kind = [ArrayKind::Primitive, ArrayKind::Struct];

for kind in kind {
let mut group = c.benchmark_group(format!(
"arrow2/erased_clone/{kind}/rows={NUM_ROWS}/instances={NUM_INSTANCES}"
));
group.throughput(criterion::Throughput::Elements(NUM_ROWS as _));

fn generate_cells(kind: ArrayKind) -> Vec<DataCell> {
match kind {
ArrayKind::Primitive => (0..NUM_ROWS)
.map(|_| DataCell::from_native(build_some_instances(NUM_INSTANCES).as_slice()))
.collect(),
ArrayKind::Struct => (0..NUM_ROWS)
.map(|_| DataCell::from_native(build_some_point2d(NUM_INSTANCES).as_slice()))
.collect(),
ArrayKind::StructLarge => (0..NUM_ROWS)
.map(|_| DataCell::from_native(build_some_rects(NUM_INSTANCES).as_slice()))
.collect(),
}
}

{
{
let cells = generate_cells(kind);
let total_instances = cells.iter().map(|cell| cell.num_instances()).sum::<u32>();
assert_eq!(total_instances, (NUM_ROWS * NUM_INSTANCES) as u32);

group.bench_function("cell/arc_erased", |b| {
b.iter(|| {
let cells = cells.clone();
assert_eq!(
total_instances,
cells.iter().map(|cell| cell.num_instances()).sum::<u32>()
);
cells
});
});
}

{
let cells = generate_cells(kind).into_iter().map(Arc::new).collect_vec();
let total_instances = cells.iter().map(|cell| cell.num_instances()).sum::<u32>();
assert_eq!(total_instances, (NUM_ROWS * NUM_INSTANCES) as u32);

group.bench_function("cell/wrapped_in_arc", |b| {
b.iter(|| {
let cells = cells.clone();
assert_eq!(
total_instances,
cells.iter().map(|cell| cell.num_instances()).sum::<u32>()
);
cells
});
});
}

{
let cells = generate_cells(kind);
let arrays = cells.iter().map(|cell| cell.as_arrow()).collect_vec();
let total_instances = arrays.iter().map(|array| array.len() as u32).sum::<u32>();
assert_eq!(total_instances, (NUM_ROWS * NUM_INSTANCES) as u32);

group.bench_function("array", |b| {
b.iter(|| {
let arrays = arrays.clone();
assert_eq!(
total_instances,
arrays.iter().map(|array| array.len() as u32).sum::<u32>()
);
arrays
});
});
}

match kind {
ArrayKind::Primitive => {
let cells = generate_cells(kind);
let arrays = cells
.iter()
.map(|cell| {
cell.as_arrow_ref()
.as_any()
.downcast_ref::<PrimitiveArray<u64>>()
.unwrap()
.clone()
})
.collect_vec();
let total_instances =
arrays.iter().map(|array| array.len() as u32).sum::<u32>();
assert_eq!(total_instances, (NUM_ROWS * NUM_INSTANCES) as u32);

group.bench_function("array/downcast_first", |b| {
b.iter(|| {
let arrays = arrays.clone();
assert_eq!(
total_instances,
arrays.iter().map(|array| array.len() as u32).sum::<u32>()
);
arrays
});
});
}
ArrayKind::Struct | ArrayKind::StructLarge => {
let cells = generate_cells(kind);
let arrays = cells
.iter()
.map(|cell| {
cell.as_arrow_ref()
.as_any()
.downcast_ref::<StructArray>()
.unwrap()
.clone()
})
.collect_vec();
let total_instances =
arrays.iter().map(|array| array.len() as u32).sum::<u32>();
assert_eq!(total_instances, (NUM_ROWS * NUM_INSTANCES) as u32);

group.bench_function("array/downcast_first", |b| {
b.iter(|| {
let arrays = arrays.clone();
assert_eq!(
total_instances,
arrays.iter().map(|array| array.len() as u32).sum::<u32>()
);
arrays
});
});
}
}
}

{
fn generate_points() -> Vec<Vec<Point2D>> {
(0..NUM_ROWS)
.map(|_| build_some_point2d(NUM_INSTANCES))
.collect()
}

fn generate_keys() -> Vec<Vec<InstanceKey>> {
(0..NUM_ROWS)
.map(|_| build_some_instances(NUM_INSTANCES))
.collect()
}

fn generate_rects() -> Vec<Vec<Rect2D>> {
(0..NUM_ROWS)
.map(|_| build_some_rects(NUM_INSTANCES))
.collect()
}

match kind {
ArrayKind::Primitive => bench_std(&mut group, generate_keys()),
ArrayKind::Struct => bench_std(&mut group, generate_points()),
ArrayKind::StructLarge => bench_std(&mut group, generate_rects()),
}

fn bench_std<T: Clone>(
group: &mut criterion::BenchmarkGroup<'_, criterion::measurement::WallTime>,
data: Vec<Vec<T>>,
) {
{
let vecs = data.clone();
let total_instances = vecs.iter().map(|vec| vec.len() as u32).sum::<u32>();
assert_eq!(total_instances, (NUM_ROWS * NUM_INSTANCES) as u32);

group.bench_function("vec/full_copy", |b| {
b.iter(|| {
let vecs = vecs.clone();
assert_eq!(
total_instances,
vecs.iter().map(|vec| vec.len() as u32).sum::<u32>()
);
vecs
});
});
}

{
let vecs = data.into_iter().map(Arc::new).collect_vec();
let total_instances = vecs.iter().map(|vec| vec.len() as u32).sum::<u32>();
assert_eq!(total_instances, (NUM_ROWS * NUM_INSTANCES) as u32);

group.bench_function("vec/wrapped_in_arc", |b| {
b.iter(|| {
let vecs = vecs.clone();
assert_eq!(
total_instances,
vecs.iter().map(|vec| vec.len() as u32).sum::<u32>()
);
vecs
});
});
}
}
}
}
}
Loading

0 comments on commit f666f1d

Please sign in to comment.