Skip to content

Commit

Permalink
introduce non-cacheable components
Browse files Browse the repository at this point in the history
  • Loading branch information
teh-cmc committed Apr 25, 2024
1 parent d90df58 commit 01eefe9
Show file tree
Hide file tree
Showing 3 changed files with 56 additions and 12 deletions.
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()
});

!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

0 comments on commit 01eefe9

Please sign in to comment.