Skip to content

Commit

Permalink
re_query: up to date with latest data types and structures (#1828)
Browse files Browse the repository at this point in the history
* No more raw arrays for primary components

* Don't need to carry around component names no more

* Cluster keys are now raw-array-less and _not_ optional anymore

* that is done indeed

* helpers
  • Loading branch information
teh-cmc committed Apr 12, 2023
1 parent 6bec48e commit 1e2515c
Show file tree
Hide file tree
Showing 9 changed files with 183 additions and 163 deletions.
6 changes: 6 additions & 0 deletions crates/re_log_types/src/component_types/instance_key.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,12 @@ impl InstanceKey {
/// for example all points in a point cloud entity.
pub const SPLAT: Self = Self(u64::MAX);

#[allow(clippy::should_implement_trait)]
#[inline]
pub fn from_iter(it: impl IntoIterator<Item = impl Into<Self>>) -> Vec<Self> {
it.into_iter().map(Into::into).collect::<Vec<_>>()
}

/// Are we referring to all instances of the entity (e.g. all points in a point cloud entity)?
///
/// The opposite of [`Self::is_specific`].
Expand Down
30 changes: 30 additions & 0 deletions crates/re_log_types/src/data_cell.rs
Original file line number Diff line number Diff line change
Expand Up @@ -371,6 +371,36 @@ impl DataCell {
{
self.try_to_native().unwrap()
}

/// Returns the contents of the cell as an iterator of native optional components.
///
/// Fails if the underlying arrow data cannot be deserialized into `C`.
//
// TODO(#1694): There shouldn't need to be HRTBs (Higher-Rank Trait Bounds) here.
#[inline]
pub fn try_to_native_opt<C: DeserializableComponent>(
&self,
) -> DataCellResult<impl Iterator<Item = Option<C>> + '_>
where
for<'a> &'a C::ArrayType: IntoIterator,
{
use arrow2_convert::deserialize::arrow_array_deserialize_iterator;
arrow_array_deserialize_iterator(&*self.inner.values).map_err(Into::into)
}

/// Returns the contents of the cell as an iterator of native optional components.
///
/// Panics if the underlying arrow data cannot be deserialized into `C`.
/// See [`Self::try_to_native_opt`] for a fallible alternative.
//
// TODO(#1694): There shouldn't need to be HRTBs here.
#[inline]
pub fn to_native_opt<C: DeserializableComponent>(&self) -> impl Iterator<Item = Option<C>> + '_
where
for<'a> &'a C::ArrayType: IntoIterator,
{
self.try_to_native_opt().unwrap()
}
}

impl DataCell {
Expand Down
13 changes: 5 additions & 8 deletions crates/re_query/src/dataframe_util.rs
Original file line number Diff line number Diff line change
Expand Up @@ -135,18 +135,17 @@ impl ComponentWithInstances {
where
for<'a> &'a C0::ArrayType: IntoIterator,
{
if C0::name() != self.name {
if C0::name() != self.name() {
return Err(QueryError::TypeMismatch {
actual: self.name,
actual: self.name(),
requested: C0::name(),
});
}

let instance_keys: Vec<Option<InstanceKey>> =
self.iter_instance_keys()?.map(Some).collect_vec();

let values =
arrow_array_deserialize_iterator::<Option<C0>>(self.values.as_ref())?.collect_vec();
let values = self.values.try_to_native_opt()?.collect_vec();

df_builder2::<InstanceKey, C0>(&instance_keys, &values)
}
Expand All @@ -160,8 +159,7 @@ where
pub fn as_df1(&self) -> crate::Result<DataFrame> {
let instance_keys = self.primary.iter_instance_keys()?.map(Some).collect_vec();

let primary_values =
arrow_array_deserialize_iterator(self.primary.values.as_ref())?.collect_vec();
let primary_values = self.primary.values.try_to_native_opt()?.collect_vec();

df_builder2::<InstanceKey, Primary>(&instance_keys, &primary_values)
}
Expand All @@ -173,8 +171,7 @@ where
{
let instance_keys = self.primary.iter_instance_keys()?.map(Some).collect_vec();

let primary_values =
arrow_array_deserialize_iterator(self.primary.values.as_ref())?.collect_vec();
let primary_values = self.primary.values.try_to_native_opt()?.collect_vec();

let c1_values = self.iter_component::<C1>()?.collect_vec();

Expand Down
Loading

1 comment on commit 1e2515c

@github-actions
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Rust Benchmark

Benchmark suite Current: 1e2515c Previous: 6bec48e Ratio
datastore/num_rows=1000/num_instances=1000/packed=false/insert/default 2798053 ns/iter (± 49459) 2842972 ns/iter (± 25927) 0.98
datastore/num_rows=1000/num_instances=1000/packed=false/latest_at/default 371 ns/iter (± 2) 370 ns/iter (± 1) 1.00
datastore/num_rows=1000/num_instances=1000/packed=false/latest_at_missing/primary/default 263 ns/iter (± 1) 266 ns/iter (± 1) 0.99
datastore/num_rows=1000/num_instances=1000/packed=false/latest_at_missing/secondaries/default 419 ns/iter (± 4) 420 ns/iter (± 14) 1.00
datastore/num_rows=1000/num_instances=1000/packed=false/range/default 2955186 ns/iter (± 42069) 3001804 ns/iter (± 38422) 0.98
datastore/num_rows=1000/num_instances=1000/gc/default 2360531 ns/iter (± 7742) 2368199 ns/iter (± 12972) 1.00
mono_points_arrow/generate_message_bundles 28137558 ns/iter (± 1145599) 28343388 ns/iter (± 1132556) 0.99
mono_points_arrow/generate_messages 123496964 ns/iter (± 1152016) 123779205 ns/iter (± 1227028) 1.00
mono_points_arrow/encode_log_msg 155039628 ns/iter (± 1412968) 152161471 ns/iter (± 1851945) 1.02
mono_points_arrow/encode_total 310448162 ns/iter (± 2250264) 304911868 ns/iter (± 10247443) 1.02
mono_points_arrow/decode_log_msg 189541902 ns/iter (± 1918086) 188575914 ns/iter (± 1564068) 1.01
mono_points_arrow/decode_message_bundles 67210424 ns/iter (± 792212) 63791473 ns/iter (± 1627698) 1.05
mono_points_arrow/decode_total 253322604 ns/iter (± 1974248) 250518231 ns/iter (± 2152746) 1.01
mono_points_arrow_batched/generate_message_bundles 18836640 ns/iter (± 1976435) 19931838 ns/iter (± 1441319) 0.95
mono_points_arrow_batched/generate_messages 4104733 ns/iter (± 141087) 3998187 ns/iter (± 108772) 1.03
mono_points_arrow_batched/encode_log_msg 1348043 ns/iter (± 6276) 1319356 ns/iter (± 17082) 1.02
mono_points_arrow_batched/encode_total 28143662 ns/iter (± 1433702) 25097628 ns/iter (± 828664) 1.12
mono_points_arrow_batched/decode_log_msg 778172 ns/iter (± 4235) 775021 ns/iter (± 5927) 1.00
mono_points_arrow_batched/decode_message_bundles 7562054 ns/iter (± 97282) 7391948 ns/iter (± 116499) 1.02
mono_points_arrow_batched/decode_total 9586152 ns/iter (± 711385) 8622423 ns/iter (± 341676) 1.11
batch_points_arrow/generate_message_bundles 239887 ns/iter (± 353) 239233 ns/iter (± 864) 1.00
batch_points_arrow/generate_messages 5050 ns/iter (± 18) 5045 ns/iter (± 53) 1.00
batch_points_arrow/encode_log_msg 265905 ns/iter (± 2538) 257552 ns/iter (± 2375) 1.03
batch_points_arrow/encode_total 528194 ns/iter (± 1674) 523252 ns/iter (± 2262) 1.01
batch_points_arrow/decode_log_msg 213243 ns/iter (± 2000) 213745 ns/iter (± 2814) 1.00
batch_points_arrow/decode_message_bundles 1831 ns/iter (± 19) 1789 ns/iter (± 21) 1.02
batch_points_arrow/decode_total 215967 ns/iter (± 2134) 219062 ns/iter (± 1480) 0.99
arrow_mono_points/insert 2473011849 ns/iter (± 57619355) 2495906822 ns/iter (± 7150643) 0.99
arrow_mono_points/query 1218937 ns/iter (± 16820) 1578487 ns/iter (± 20840) 0.77
arrow_batch_points/insert 1141669 ns/iter (± 14681) 1150211 ns/iter (± 9059) 0.99
arrow_batch_points/query 14152 ns/iter (± 87) 16773 ns/iter (± 164) 0.84
arrow_batch_vecs/insert 26391 ns/iter (± 896) 26368 ns/iter (± 171) 1.00
arrow_batch_vecs/query 321244 ns/iter (± 4311) 388258 ns/iter (± 2342) 0.83
tuid/Tuid::random 34 ns/iter (± 0) 34 ns/iter (± 0) 1

This comment was automatically generated by workflow using github-action-benchmark.

Please sign in to comment.