Skip to content

Commit f666f1d

Browse files
committed
squashed origin/main
commit 4439309 Author: Clement Rey <cr.rey.clement@gmail.com> 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 <andreas@rerun.io> 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 <andreas@rerun.io> 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 <cr.rey.clement@gmail.com> 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 <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)
1 parent 9c96f45 commit f666f1d

File tree

17 files changed

+780
-139
lines changed

17 files changed

+780
-139
lines changed

Cargo.lock

Lines changed: 2 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

crates/re_arrow_store/Cargo.toml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,8 @@ polars-core = { workspace = true, features = [
8181
"sort_multiple",
8282
] }
8383
rand = "0.8"
84+
smallvec = { version = "1.0", features = ["const_generics", "union"] }
85+
tinyvec = { version = "1.6", features = ["alloc", "rustc_1_55"] }
8486

8587

8688
[lib]
@@ -119,3 +121,7 @@ harness = false
119121
[[bench]]
120122
name = "arrow2_convert"
121123
harness = false
124+
125+
[[bench]]
126+
name = "vectors"
127+
harness = false

crates/re_arrow_store/benches/arrow2.rs

Lines changed: 211 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,18 +3,24 @@
33
#[global_allocator]
44
static GLOBAL: mimalloc::MiMalloc = mimalloc::MiMalloc;
55

6-
use arrow2::{array::Array, compute::aggregate::estimated_bytes_size};
6+
use std::sync::Arc;
7+
8+
use arrow2::{
9+
array::{Array, PrimitiveArray, StructArray},
10+
compute::aggregate::estimated_bytes_size,
11+
};
712
use criterion::{criterion_group, criterion_main, Criterion};
813
use itertools::Itertools;
914
use re_log_types::{
15+
component_types::{InstanceKey, Point2D, Rect2D},
1016
datagen::{build_some_instances, build_some_point2d, build_some_rects},
1117
external::arrow2_convert::serialize::TryIntoArrow,
12-
SerializableComponent,
18+
DataCell, SerializableComponent,
1319
};
1420

1521
// ---
1622

17-
criterion_group!(benches, estimated_size_bytes);
23+
criterion_group!(benches, erased_clone, estimated_size_bytes);
1824
criterion_main!(benches);
1925

2026
// ---
@@ -54,7 +60,7 @@ impl std::fmt::Display for ArrayKind {
5460
}
5561
}
5662

57-
fn estimated_size_bytes(c: &mut Criterion) {
63+
fn erased_clone(c: &mut Criterion) {
5864
let kind = [
5965
ArrayKind::Primitive,
6066
ArrayKind::Struct,
@@ -164,3 +170,204 @@ fn estimated_size_bytes(c: &mut Criterion) {
164170
}
165171
}
166172
}
173+
174+
fn estimated_size_bytes(c: &mut Criterion) {
175+
let kind = [ArrayKind::Primitive, ArrayKind::Struct];
176+
177+
for kind in kind {
178+
let mut group = c.benchmark_group(format!(
179+
"arrow2/erased_clone/{kind}/rows={NUM_ROWS}/instances={NUM_INSTANCES}"
180+
));
181+
group.throughput(criterion::Throughput::Elements(NUM_ROWS as _));
182+
183+
fn generate_cells(kind: ArrayKind) -> Vec<DataCell> {
184+
match kind {
185+
ArrayKind::Primitive => (0..NUM_ROWS)
186+
.map(|_| DataCell::from_native(build_some_instances(NUM_INSTANCES).as_slice()))
187+
.collect(),
188+
ArrayKind::Struct => (0..NUM_ROWS)
189+
.map(|_| DataCell::from_native(build_some_point2d(NUM_INSTANCES).as_slice()))
190+
.collect(),
191+
ArrayKind::StructLarge => (0..NUM_ROWS)
192+
.map(|_| DataCell::from_native(build_some_rects(NUM_INSTANCES).as_slice()))
193+
.collect(),
194+
}
195+
}
196+
197+
{
198+
{
199+
let cells = generate_cells(kind);
200+
let total_instances = cells.iter().map(|cell| cell.num_instances()).sum::<u32>();
201+
assert_eq!(total_instances, (NUM_ROWS * NUM_INSTANCES) as u32);
202+
203+
group.bench_function("cell/arc_erased", |b| {
204+
b.iter(|| {
205+
let cells = cells.clone();
206+
assert_eq!(
207+
total_instances,
208+
cells.iter().map(|cell| cell.num_instances()).sum::<u32>()
209+
);
210+
cells
211+
});
212+
});
213+
}
214+
215+
{
216+
let cells = generate_cells(kind).into_iter().map(Arc::new).collect_vec();
217+
let total_instances = cells.iter().map(|cell| cell.num_instances()).sum::<u32>();
218+
assert_eq!(total_instances, (NUM_ROWS * NUM_INSTANCES) as u32);
219+
220+
group.bench_function("cell/wrapped_in_arc", |b| {
221+
b.iter(|| {
222+
let cells = cells.clone();
223+
assert_eq!(
224+
total_instances,
225+
cells.iter().map(|cell| cell.num_instances()).sum::<u32>()
226+
);
227+
cells
228+
});
229+
});
230+
}
231+
232+
{
233+
let cells = generate_cells(kind);
234+
let arrays = cells.iter().map(|cell| cell.as_arrow()).collect_vec();
235+
let total_instances = arrays.iter().map(|array| array.len() as u32).sum::<u32>();
236+
assert_eq!(total_instances, (NUM_ROWS * NUM_INSTANCES) as u32);
237+
238+
group.bench_function("array", |b| {
239+
b.iter(|| {
240+
let arrays = arrays.clone();
241+
assert_eq!(
242+
total_instances,
243+
arrays.iter().map(|array| array.len() as u32).sum::<u32>()
244+
);
245+
arrays
246+
});
247+
});
248+
}
249+
250+
match kind {
251+
ArrayKind::Primitive => {
252+
let cells = generate_cells(kind);
253+
let arrays = cells
254+
.iter()
255+
.map(|cell| {
256+
cell.as_arrow_ref()
257+
.as_any()
258+
.downcast_ref::<PrimitiveArray<u64>>()
259+
.unwrap()
260+
.clone()
261+
})
262+
.collect_vec();
263+
let total_instances =
264+
arrays.iter().map(|array| array.len() as u32).sum::<u32>();
265+
assert_eq!(total_instances, (NUM_ROWS * NUM_INSTANCES) as u32);
266+
267+
group.bench_function("array/downcast_first", |b| {
268+
b.iter(|| {
269+
let arrays = arrays.clone();
270+
assert_eq!(
271+
total_instances,
272+
arrays.iter().map(|array| array.len() as u32).sum::<u32>()
273+
);
274+
arrays
275+
});
276+
});
277+
}
278+
ArrayKind::Struct | ArrayKind::StructLarge => {
279+
let cells = generate_cells(kind);
280+
let arrays = cells
281+
.iter()
282+
.map(|cell| {
283+
cell.as_arrow_ref()
284+
.as_any()
285+
.downcast_ref::<StructArray>()
286+
.unwrap()
287+
.clone()
288+
})
289+
.collect_vec();
290+
let total_instances =
291+
arrays.iter().map(|array| array.len() as u32).sum::<u32>();
292+
assert_eq!(total_instances, (NUM_ROWS * NUM_INSTANCES) as u32);
293+
294+
group.bench_function("array/downcast_first", |b| {
295+
b.iter(|| {
296+
let arrays = arrays.clone();
297+
assert_eq!(
298+
total_instances,
299+
arrays.iter().map(|array| array.len() as u32).sum::<u32>()
300+
);
301+
arrays
302+
});
303+
});
304+
}
305+
}
306+
}
307+
308+
{
309+
fn generate_points() -> Vec<Vec<Point2D>> {
310+
(0..NUM_ROWS)
311+
.map(|_| build_some_point2d(NUM_INSTANCES))
312+
.collect()
313+
}
314+
315+
fn generate_keys() -> Vec<Vec<InstanceKey>> {
316+
(0..NUM_ROWS)
317+
.map(|_| build_some_instances(NUM_INSTANCES))
318+
.collect()
319+
}
320+
321+
fn generate_rects() -> Vec<Vec<Rect2D>> {
322+
(0..NUM_ROWS)
323+
.map(|_| build_some_rects(NUM_INSTANCES))
324+
.collect()
325+
}
326+
327+
match kind {
328+
ArrayKind::Primitive => bench_std(&mut group, generate_keys()),
329+
ArrayKind::Struct => bench_std(&mut group, generate_points()),
330+
ArrayKind::StructLarge => bench_std(&mut group, generate_rects()),
331+
}
332+
333+
fn bench_std<T: Clone>(
334+
group: &mut criterion::BenchmarkGroup<'_, criterion::measurement::WallTime>,
335+
data: Vec<Vec<T>>,
336+
) {
337+
{
338+
let vecs = data.clone();
339+
let total_instances = vecs.iter().map(|vec| vec.len() as u32).sum::<u32>();
340+
assert_eq!(total_instances, (NUM_ROWS * NUM_INSTANCES) as u32);
341+
342+
group.bench_function("vec/full_copy", |b| {
343+
b.iter(|| {
344+
let vecs = vecs.clone();
345+
assert_eq!(
346+
total_instances,
347+
vecs.iter().map(|vec| vec.len() as u32).sum::<u32>()
348+
);
349+
vecs
350+
});
351+
});
352+
}
353+
354+
{
355+
let vecs = data.into_iter().map(Arc::new).collect_vec();
356+
let total_instances = vecs.iter().map(|vec| vec.len() as u32).sum::<u32>();
357+
assert_eq!(total_instances, (NUM_ROWS * NUM_INSTANCES) as u32);
358+
359+
group.bench_function("vec/wrapped_in_arc", |b| {
360+
b.iter(|| {
361+
let vecs = vecs.clone();
362+
assert_eq!(
363+
total_instances,
364+
vecs.iter().map(|vec| vec.len() as u32).sum::<u32>()
365+
);
366+
vecs
367+
});
368+
});
369+
}
370+
}
371+
}
372+
}
373+
}

0 commit comments

Comments
 (0)