-
Notifications
You must be signed in to change notification settings - Fork 373
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
arrow2
erased refcounted clones benchmarks
#1745
Merged
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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,244 @@ | ||
//! Keeping track of performance issues/regressions in `arrow2` that directly affect us. | ||
|
||
#[global_allocator] | ||
static GLOBAL: mimalloc::MiMalloc = mimalloc::MiMalloc; | ||
|
||
use std::sync::Arc; | ||
|
||
use arrow2::array::{Array, PrimitiveArray, StructArray}; | ||
use criterion::{criterion_group, criterion_main, Criterion}; | ||
use itertools::Itertools; | ||
use re_log_types::{ | ||
component_types::{InstanceKey, Point2D}, | ||
datagen::{build_some_instances, build_some_point2d}, | ||
DataCell, | ||
}; | ||
|
||
// --- | ||
|
||
criterion_group!(benches, estimated_size_bytes); | ||
criterion_main!(benches); | ||
|
||
// --- | ||
|
||
#[cfg(not(debug_assertions))] | ||
const NUM_ROWS: usize = 10_000; | ||
#[cfg(not(debug_assertions))] | ||
const NUM_INSTANCES: usize = 100; | ||
|
||
// `cargo test` also runs the benchmark setup code, so make sure they run quickly: | ||
#[cfg(debug_assertions)] | ||
const NUM_ROWS: usize = 1; | ||
#[cfg(debug_assertions)] | ||
const NUM_INSTANCES: usize = 1; | ||
|
||
// --- | ||
|
||
#[derive(Debug, Clone, Copy)] | ||
enum ArrayKind { | ||
/// E.g. an array of `InstanceKey`. | ||
Primitive, | ||
|
||
/// E.g. an array of `Point2D`. | ||
Struct, | ||
} | ||
|
||
impl std::fmt::Display for ArrayKind { | ||
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { | ||
f.write_str(match self { | ||
ArrayKind::Primitive => "primitive", | ||
ArrayKind::Struct => "struct", | ||
}) | ||
} | ||
} | ||
|
||
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(), | ||
} | ||
} | ||
|
||
{ | ||
{ | ||
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 => { | ||
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() | ||
} | ||
|
||
match kind { | ||
ArrayKind::Primitive => bench_std(&mut group, generate_keys()), | ||
ArrayKind::Struct => bench_std(&mut group, generate_points()), | ||
} | ||
|
||
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 | ||
}); | ||
}); | ||
} | ||
} | ||
} | ||
} | ||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
that's really
array/full_copy
, no?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
no full copy here, this is the usual arrow path which ends at
arrow2::Buffer::clone()
which is anArc