Skip to content
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

Introduce codegen optimizations for primitives and fixed-sized-arrays #2970

Merged
merged 26 commits into from
Aug 15, 2023
Merged
Show file tree
Hide file tree
Changes from 19 commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
4bc9c7a
Add ArrowBuffer to optimize serialization
jleibs Aug 11, 2023
5692b2b
codegen
jleibs Aug 11, 2023
441b8a7
ArrowBuffer support for deserializer
jleibs Aug 11, 2023
2789dc1
Make it possible to bypass Opt / unwrap
jleibs Aug 9, 2023
0e9e856
Set up optimization pathway for primitives and fixed-sized-arrays
jleibs Aug 11, 2023
4ea9590
Optimization for primitive types
jleibs Aug 11, 2023
938ffa8
Further optimization for fixed sized arrays
jleibs Aug 12, 2023
6b1010d
codegen
jleibs Aug 12, 2023
ab95c49
Clean up is_primitive naming
jleibs Aug 14, 2023
d0e56b8
More naming cleanup and streamline serialization
jleibs Aug 14, 2023
5032aa6
Doclink and comments
jleibs Aug 14, 2023
e158b4a
Codegen
jleibs Aug 14, 2023
0db57e5
Enforce validity
jleibs Aug 14, 2023
1c17d9d
Merge branch 'main' into jleibs/codegen_optimizations
jleibs Aug 14, 2023
3b836c1
Add unit test to ensure validity checks do the right thing
jleibs Aug 14, 2023
5531509
Marking util as dead until we bring back extension logic
jleibs Aug 14, 2023
0387ab8
Doclink
jleibs Aug 14, 2023
3319915
can't doclink without a dependency
jleibs Aug 14, 2023
41edfb4
Source_hash
jleibs Aug 14, 2023
e6159fb
Rename ArrowBuffer len -> num_instances
jleibs Aug 15, 2023
449301e
Remove unused mod
jleibs Aug 15, 2023
7f12dcb
Replace bool with InnerRepr enum
jleibs Aug 15, 2023
14378b5
Add comment about FixedSizeList
jleibs Aug 15, 2023
9179095
Merge branch 'main' into jleibs/codegen_optimizations
jleibs Aug 15, 2023
da4791c
More comments and renames
jleibs Aug 15, 2023
0a3ae47
More naming
jleibs Aug 15, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 4 additions & 13 deletions crates/re_log_types/src/data_cell.rs
Original file line number Diff line number Diff line change
Expand Up @@ -362,17 +362,8 @@ impl DataCell {
pub fn try_to_native<'a, C: Component + Default + 'a>(
&'a self,
) -> DataCellResult<impl Iterator<Item = C> + '_> {
Ok(C::try_iter_from_arrow(self.inner.values.as_ref())?
.map(C::convert_item_to_self)
.map(|v| {
// TODO(#2523): This unwrap and the `Default` bounds should go away once we move to fallible iterators
v.unwrap_or_else(|| {
re_log::warn_once!(
"Unexpected missing data when iterating non-optional data-cell. Falling back on Default value."
);
C::default()
})
}))
re_tracing::profile_function!(C::name().as_str());
Ok(C::try_iter_from_arrow(self.inner.values.as_ref())?.map(C::convert_item_to_self))
}

/// Returns the contents of an expected mono-component as an `Option<C>`.
Expand All @@ -381,7 +372,7 @@ impl DataCell {
#[inline]
pub fn try_to_native_mono<'a, C: Component + 'a>(&'a self) -> DataCellResult<Option<C>> {
let mut iter =
C::try_iter_from_arrow(self.inner.values.as_ref())?.map(C::convert_item_to_self);
C::try_iter_from_arrow(self.inner.values.as_ref())?.map(C::convert_item_to_opt_self);

let result = match iter.next() {
// It's ok to have no result from the iteration: this is what we
Expand Down Expand Up @@ -420,7 +411,7 @@ impl DataCell {
pub fn try_to_native_opt<'a, C: Component + 'a>(
&'a self,
) -> DataCellResult<impl Iterator<Item = Option<C>> + '_> {
Ok(C::try_iter_from_arrow(self.inner.values.as_ref())?.map(C::convert_item_to_self))
Ok(C::try_iter_from_arrow(self.inner.values.as_ref())?.map(C::convert_item_to_opt_self))
}

/// Returns the contents of the cell as an iterator of native optional components.
Expand Down
2 changes: 1 addition & 1 deletion crates/re_log_types/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -485,7 +485,7 @@ macro_rules! component_legacy_shim {
}

#[inline]
fn convert_item_to_self(item: Self::Item<'_>) -> Option<Self> {
fn convert_item_to_opt_self(item: Self::Item<'_>) -> Option<Self> {
<Self as arrow2_convert::deserialize::ArrowDeserialize>::arrow_deserialize(item)
}
}
Expand Down
2 changes: 1 addition & 1 deletion crates/re_types/source_hash.txt

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

30 changes: 30 additions & 0 deletions crates/re_types/src/arrow_buffer.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
use arrow2::buffer::Buffer;

/// Convenience-wrapper around an arrow [`Buffer`] that is known to contain a
/// a primitive type.
///
/// The arrow2 [`Buffer`] object is internally reference-counted and can be
/// easily converted back to a `&[T]` referencing the underlying storage.
/// This avoids some of the lifetime complexities that would otherwise
/// arise from returning a `&[T]` directly, but is significantly more
/// performant than doing the full allocation necessary to return a `Vec<T>`.
#[derive(Clone, Debug, Default, PartialEq)]
pub struct ArrowBuffer<T>(pub Buffer<T>);

impl<T> ArrowBuffer<T> {
#[inline]
pub fn len(&self) -> usize {
self.0.len()
}
jleibs marked this conversation as resolved.
Show resolved Hide resolved

#[inline]
pub fn is_empty(&self) -> bool {
self.0.is_empty()
}
}

impl<T> From<Vec<T>> for ArrowBuffer<T> {
fn from(value: Vec<T>) -> Self {
Self(value.into())
}
}
4 changes: 2 additions & 2 deletions crates/re_types/src/components/annotation_context.rs

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

45 changes: 41 additions & 4 deletions crates/re_types/src/components/class_id.rs

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

45 changes: 41 additions & 4 deletions crates/re_types/src/components/color.rs

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

4 changes: 2 additions & 2 deletions crates/re_types/src/components/disconnected_space.rs

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

44 changes: 40 additions & 4 deletions crates/re_types/src/components/draw_order.rs

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

Loading