Skip to content

Commit

Permalink
Primary cache: per-component size statistics (#4890)
Browse files Browse the repository at this point in the history
Before:

![image](https://github.com/rerun-io/rerun/assets/2910679/bec3e40a-529c-443d-9803-9581bfc977da)

After:

![image](https://github.com/rerun-io/rerun/assets/2910679/b1507279-7ca3-4c43-b47d-12b88864fdbc)


- Fix #4857
- DNR: requires #4856

### Checklist
* [x] I have read and agree to [Contributor
Guide](https://github.com/rerun-io/rerun/blob/main/CONTRIBUTING.md) and
the [Code of
Conduct](https://github.com/rerun-io/rerun/blob/main/CODE_OF_CONDUCT.md)
* [x] I've included a screenshot or gif (if applicable)
* [x] I have tested the web demo (if applicable):
* Using newly built examples:
[app.rerun.io](https://app.rerun.io/pr/4890/index.html)
* Using examples from latest `main` build:
[app.rerun.io](https://app.rerun.io/pr/4890/index.html?manifest_url=https://app.rerun.io/version/main/examples_manifest.json)
* Using full set of examples from `nightly` build:
[app.rerun.io](https://app.rerun.io/pr/4890/index.html?manifest_url=https://app.rerun.io/version/nightly/examples_manifest.json)
* [x] The PR title and labels are set such as to maximize their
usefulness for the next release's CHANGELOG

- [PR Build Summary](https://build.rerun.io/pr/4890)
- [Docs
preview](https://rerun.io/preview/06db01a65d711ec7ba802169845e3b79337a91af/docs)
<!--DOCS-PREVIEW-->
- [Examples
preview](https://rerun.io/preview/06db01a65d711ec7ba802169845e3b79337a91af/examples)
<!--EXAMPLES-PREVIEW-->
- [Recent benchmark results](https://build.rerun.io/graphs/crates.html)
- [Wasm size tracking](https://build.rerun.io/graphs/sizes.html)
  • Loading branch information
teh-cmc authored Jan 25, 2024
1 parent 50671b2 commit 7fcdb1d
Show file tree
Hide file tree
Showing 4 changed files with 50 additions and 11 deletions.
2 changes: 1 addition & 1 deletion crates/re_query_cache/src/cache.rs
Original file line number Diff line number Diff line change
Expand Up @@ -756,7 +756,7 @@ impl CacheBucket {
.or_insert_with(|| Box::new(FlatVecDeque::<C>::new()));

// The `FlatVecDeque` will have to collect the data one way or another: do it ourselves
// instead, that way we can efficiently computes its size while we're at it.
// instead, that way we can efficiently compute its size while we're at it.
let added: FlatVecDeque<C> = arch_view
.iter_required_component::<C>()?
.collect::<VecDeque<C>>()
Expand Down
29 changes: 27 additions & 2 deletions crates/re_query_cache/src/cache_stats.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use std::collections::BTreeMap;

use re_log_types::{EntityPath, TimeRange, Timeline};
use re_types_core::{ComponentName, SizeBytes as _};
use re_types_core::{components::InstanceKey, ComponentName, Loggable as _, SizeBytes as _};

use crate::{cache::CacheBucket, Caches, LatestAtCache, RangeCache};

Expand Down Expand Up @@ -62,6 +62,7 @@ impl CachedEntityStats {
pub struct CachedComponentStats {
pub total_rows: u64,
pub total_instances: u64,
pub total_size_bytes: u64,
}

impl Caches {
Expand All @@ -75,11 +76,35 @@ impl Caches {
per_component: &mut BTreeMap<ComponentName, CachedComponentStats>,
bucket: &CacheBucket,
) {
for (component_name, data) in &bucket.components {
let CacheBucket {
data_times,
pov_instance_keys,
components,
total_size_bytes: _,
} = bucket;

{
let stats: &mut CachedComponentStats =
per_component.entry("<timepoints>".into()).or_default();
stats.total_rows += data_times.len() as u64;
stats.total_instances += data_times.len() as u64;
stats.total_size_bytes += data_times.total_size_bytes();
}

{
let stats: &mut CachedComponentStats =
per_component.entry(InstanceKey::name()).or_default();
stats.total_rows += pov_instance_keys.num_entries() as u64;
stats.total_instances += pov_instance_keys.num_values() as u64;
stats.total_size_bytes += pov_instance_keys.total_size_bytes();
}

for (component_name, data) in components {
let stats: &mut CachedComponentStats =
per_component.entry(*component_name).or_default();
stats.total_rows += data.dyn_num_entries() as u64;
stats.total_instances += data.dyn_num_values() as u64;
stats.total_size_bytes += data.dyn_total_size_bytes();
}
}

Expand Down
27 changes: 19 additions & 8 deletions crates/re_query_cache/src/range.rs
Original file line number Diff line number Diff line change
Expand Up @@ -180,9 +180,13 @@ macro_rules! impl_query_archetype_range {
{
re_tracing::profile_scope!("fill");

// Grabbing the current time is quite costly on web.
#[cfg(not(target_arch = "wasm32"))]
let now = web_time::Instant::now();

#[cfg(not(target_arch = "wasm32"))]
let mut added_entries = 0u64;

let mut added_size_bytes = 0u64;

for arch_view in arch_views {
Expand All @@ -193,16 +197,23 @@ macro_rules! impl_query_archetype_range {
}

added_size_bytes += bucket.[<insert_pov$N _comp$M>]::<A, $($pov,)+ $($comp,)*>(data_time, &arch_view)?;
added_entries += 1;

#[cfg(not(target_arch = "wasm32"))]
{
added_entries += 1;
}
}

let elapsed = now.elapsed();
::re_log::trace!(
archetype=%A::name(),
added_size_bytes,
"cached {added_entries} entries in {elapsed:?} ({:0.3} entries/s)",
added_entries as f64 / elapsed.as_secs_f64()
);
#[cfg(not(target_arch = "wasm32"))]
{
let elapsed = now.elapsed();
::re_log::trace!(
archetype=%A::name(),
added_size_bytes,
"cached {added_entries} entries in {elapsed:?} ({:0.3} entries/s)",
added_entries as f64 / elapsed.as_secs_f64()
);
}

Ok(added_size_bytes)
}
Expand Down
3 changes: 3 additions & 0 deletions crates/re_viewer/src/ui/memory_panel.rs
Original file line number Diff line number Diff line change
Expand Up @@ -425,17 +425,20 @@ impl MemoryPanel {
ui.label(egui::RichText::new("Component").underline());
ui.label(egui::RichText::new("Rows").underline());
ui.label(egui::RichText::new("Instances").underline());
ui.label(egui::RichText::new("Size").underline());
ui.end_row();

for (component_name, stats) in per_component {
let &CachedComponentStats {
total_rows,
total_instances,
total_size_bytes,
} = stats;

ui.label(component_name.to_string());
ui.label(re_format::format_number(total_rows as _));
ui.label(re_format::format_number(total_instances as _));
ui.label(re_format::format_bytes(total_size_bytes as _));
ui.end_row();
}
});
Expand Down

0 comments on commit 7fcdb1d

Please sign in to comment.