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

Optimize out unnecessary joins when querying archetypes #3377

Merged
merged 6 commits into from
Sep 20, 2023
Merged
Changes from 1 commit
Commits
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
34 changes: 23 additions & 11 deletions crates/re_query/src/archetype_view.rs
Original file line number Diff line number Diff line change
Expand Up @@ -322,24 +322,36 @@ impl<A: Archetype> ArchetypeView<A> {
let component = self.components.get(&C::name());

if let Some(component) = component {
let primary_instance_key_iter = self.iter_instance_keys();

let mut component_instance_key_iter = component.instance_keys().into_iter();

let component_value_iter = {
re_tracing::profile_scope!("try_from_arrow_opt", C::name());
C::try_from_arrow_opt(component.values.as_arrow_ref())?.into_iter()
};

// NOTE: Autogenerated instance keys are interned: if two or more rows in the store
// share the same keys, then they will literally point to the same memory address.
// Therefore we can compare those addresses, and early out if they match.
let primary_instance_key_buffer = self.required_comp().instance_keys.as_arrow_ref();
let component_instance_key_buffer = component.instance_keys.as_arrow_ref();
if primary_instance_key_buffer == component_instance_key_buffer {
return Ok(itertools::Either::Left(itertools::Either::Left(
component_value_iter,
)));
}

let primary_instance_key_iter = self.iter_instance_keys();
let mut component_instance_key_iter = component.instance_keys().into_iter();

let next_component_instance_key = component_instance_key_iter.next();

Ok(itertools::Either::Left(ComponentJoinedIterator {
primary_instance_key_iter,
component_instance_key_iter,
component_value_iter,
next_component_instance_key,
splatted_component_value: None,
}))
Ok(itertools::Either::Left(itertools::Either::Right(
ComponentJoinedIterator {
primary_instance_key_iter,
component_instance_key_iter,
component_value_iter,
next_component_instance_key,
splatted_component_value: None,
},
)))
} else {
let primary = self.required_comp();
let nulls = (0..primary.len()).map(|_| None);
Expand Down