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

New data APIs 16 (final?!): introduce non-cacheable components #6037

Merged
merged 2 commits into from
Apr 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
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
19 changes: 13 additions & 6 deletions crates/re_query/src/latest_at/query.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,12 +33,19 @@ impl Caches {

for component_name in component_names {
let key = CacheKey::new(entity_path.clone(), query.timeline(), component_name);
let cache = Arc::clone(
self.latest_at_per_cache_key
.write()
.entry(key.clone())
.or_insert_with(|| Arc::new(RwLock::new(LatestAtCache::new(key.clone())))),
);

let cache = if crate::cacheable(component_name) {
Arc::clone(
self.latest_at_per_cache_key
.write()
.entry(key.clone())
.or_insert_with(|| Arc::new(RwLock::new(LatestAtCache::new(key.clone())))),
)
} else {
// If the component shouldn't be cached, simply instantiate a new cache for it.
// It will be dropped when the user is done with it.
Arc::new(RwLock::new(LatestAtCache::new(key.clone())))
};

let mut cache = cache.write();
cache.handle_pending_invalidation();
Expand Down
31 changes: 31 additions & 0 deletions crates/re_query/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -117,3 +117,34 @@ impl From<(RangeQuery, RangeResults)> for Results {
Self::Range(query, results)
}
}

// ---

/// Returns `true` if the specified `component_name` can be cached.
///
/// Used internally to avoid unnecessarily caching components that are already cached in other
/// places, for historical reasons.
pub fn cacheable(component_name: re_types::ComponentName) -> bool {
use std::sync::OnceLock;
static NOT_CACHEABLE: OnceLock<re_types::ComponentNameSet> = OnceLock::new();

use re_types_core::Loggable as _;
let not_cacheable = NOT_CACHEABLE.get_or_init(|| {
[
// TODO(#5303): instance keys are on their way out anyhow.
re_types::components::InstanceKey::name(),
// TODO(#5974): tensors might already be cached in the ad-hoc JPEG cache, we don't
// want yet another copy.
re_types::components::TensorData::name(),
// TODO(#5974): meshes are already cached in the ad-hoc mesh cache, we don't
// want yet another copy.
re_types::components::MeshProperties::name(),
// TODO(#5974): blobs are used for assets, which are themselves already cached in
// the ad-hoc mesh cache -- we don't want yet another copy.
re_types::components::Blob::name(),
]
.into()
});

!component_name.is_indicator_component() && !not_cacheable.contains(&component_name)
}
18 changes: 12 additions & 6 deletions crates/re_query/src/range/query.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,12 +33,18 @@ impl Caches {
for component_name in component_names {
let key = CacheKey::new(entity_path.clone(), query.timeline(), component_name);

let cache = Arc::clone(
self.range_per_cache_key
.write()
.entry(key.clone())
.or_insert_with(|| Arc::new(RwLock::new(RangeCache::new(key.clone())))),
);
let cache = if crate::cacheable(component_name) {
Arc::clone(
self.range_per_cache_key
.write()
.entry(key.clone())
.or_insert_with(|| Arc::new(RwLock::new(RangeCache::new(key.clone())))),
)
} else {
// If the component shouldn't be cached, simply instantiate a new cache for it.
// It will be dropped when the user is done with it.
Arc::new(RwLock::new(RangeCache::new(key.clone())))
};

let mut cache = cache.write();
cache.handle_pending_invalidation();
Expand Down
Loading