Skip to content

Commit

Permalink
Only compute store/caching stats when the memory panel is opened (#5274)
Browse files Browse the repository at this point in the history
Computing stats for the store and caches is a very costly process.

We do so every frame because the memory panel's data gets updated
whether it is opened or not, so that the memory graphs are not missing
any data when you _eventually_ open it.

In the case of the store, we've added a lot of complexity a long time
ago to make that process fast enough (although in a big enough scene, it
will still take a non-trivial amount of time).
I've recently gone through the process of adding the same kind of
complexity to the caches, but it gets absolutely insane -- so insane
that it's just not worth it.

So, instead of making the caches even more complicated than they already
are just so the memory panel can get updated in the background, we've
decided to just _not_ updated the mempanel stats when it's hidden.

Before:

![image](https://github.com/rerun-io/rerun/assets/2910679/432515df-728d-4ba8-87be-a9545dc3a0b1)


After (mempanel opened):

![image](https://github.com/rerun-io/rerun/assets/2910679/0d1253c4-c3b6-4254-8555-c85c58994a8b)


After (mempanel hidden):

![image](https://github.com/rerun-io/rerun/assets/2910679/3bcd8757-a5dd-40e5-ade6-69f08f6ddada)


### 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/5274/index.html)
* Using examples from latest `main` build:
[app.rerun.io](https://app.rerun.io/pr/5274/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/5274/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
* [x] If applicable, add a new check to the [release
checklist](https://github.com/rerun-io/rerun/blob/main/tests/python/release_checklist)!

- [PR Build Summary](https://build.rerun.io/pr/5274)
- [Docs
preview](https://rerun.io/preview/678312328257b8c29d802aee693e630850fcd741/docs)
<!--DOCS-PREVIEW-->
- [Examples
preview](https://rerun.io/preview/678312328257b8c29d802aee693e630850fcd741/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 Feb 26, 2024
1 parent 22210f9 commit e3d49d5
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 31 deletions.
18 changes: 13 additions & 5 deletions crates/re_viewer/src/app.rs
Original file line number Diff line number Diff line change
Expand Up @@ -750,7 +750,7 @@ impl App {
&mut self,
ui: &mut egui::Ui,
gpu_resource_stats: &WgpuResourcePoolStatistics,
store_stats: &StoreHubStats,
store_stats: Option<&StoreHubStats>,
) {
let frame = egui::Frame {
fill: ui.visuals().panel_fill,
Expand Down Expand Up @@ -807,7 +807,7 @@ impl App {
app_blueprint: &AppBlueprint<'_>,
gpu_resource_stats: &WgpuResourcePoolStatistics,
store_context: Option<&StoreContext<'_>>,
store_stats: &StoreHubStats,
store_stats: Option<&StoreHubStats>,
) {
let mut main_panel_frame = egui::Frame::default();
if re_ui::CUSTOM_WINDOW_DECORATIONS {
Expand Down Expand Up @@ -1220,8 +1220,11 @@ impl eframe::App for App {
}
}

// NOTE: GPU resource stats are cheap to compute so we always do.
// TODO(andreas): store the re_renderer somewhere else.
let gpu_resource_stats = {
re_tracing::profile_scope!("gpu_resource_stats");

let egui_renderer = {
let render_state = frame.wgpu_render_state().unwrap();
&mut render_state.renderer.read()
Expand All @@ -1235,10 +1238,15 @@ impl eframe::App for App {
render_ctx.gpu_resources.statistics()
};

let store_stats = store_hub.stats(self.memory_panel.primary_cache_detailed_stats_enabled());
// NOTE: Store and caching stats are very costly to compute: only do so if the memory panel
// is opened.
let store_stats = self
.memory_panel_open
.then(|| store_hub.stats(self.memory_panel.primary_cache_detailed_stats_enabled()));

// do early, before doing too many allocations
self.memory_panel.update(&gpu_resource_stats, &store_stats);
self.memory_panel
.update(&gpu_resource_stats, store_stats.as_ref());

self.check_keyboard_shortcuts(egui_ctx);

Expand Down Expand Up @@ -1276,7 +1284,7 @@ impl eframe::App for App {
&app_blueprint,
&gpu_resource_stats,
store_context.as_ref(),
&store_stats,
store_stats.as_ref(),
);

if re_ui::CUSTOM_WINDOW_DECORATIONS {
Expand Down
2 changes: 2 additions & 0 deletions crates/re_viewer/src/store_hub.rs
Original file line number Diff line number Diff line change
Expand Up @@ -412,6 +412,8 @@ impl StoreHub {
// TODO(jleibs): We probably want stats for all recordings, not just
// the currently selected recording.
pub fn stats(&self, detailed_cache_stats: bool) -> StoreHubStats {
re_tracing::profile_function!();

// If we have an app-id, then use it to look up the blueprint.
let blueprint = self
.selected_application_id
Expand Down
54 changes: 28 additions & 26 deletions crates/re_viewer/src/ui/memory_panel.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,17 +28,17 @@ impl MemoryPanel {
pub fn update(
&mut self,
gpu_resource_stats: &WgpuResourcePoolStatistics,
store_stats: &StoreHubStats,
store_stats: Option<&StoreHubStats>,
) {
re_tracing::profile_function!();
self.history.capture(
Some(
(gpu_resource_stats.total_buffer_size_in_bytes
+ gpu_resource_stats.total_texture_size_in_bytes) as _,
),
Some(store_stats.recording_stats.total.num_bytes as _),
Some(store_stats.recording_cached_stats.total_size_bytes() as _),
Some(store_stats.blueprint_stats.total.num_bytes as _),
store_stats.map(|stats| stats.recording_stats.total.num_bytes as _),
store_stats.map(|stats| stats.recording_cached_stats.total_size_bytes() as _),
store_stats.map(|stats| stats.blueprint_stats.total.num_bytes as _),
);
}

Expand All @@ -61,7 +61,7 @@ impl MemoryPanel {
re_ui: &re_ui::ReUi,
limit: &MemoryLimit,
gpu_resource_stats: &WgpuResourcePoolStatistics,
store_stats: &StoreHubStats,
store_stats: Option<&StoreHubStats>,
) {
re_tracing::profile_function!();

Expand All @@ -88,7 +88,7 @@ impl MemoryPanel {
re_ui: &re_ui::ReUi,
limit: &MemoryLimit,
gpu_resource_stats: &WgpuResourcePoolStatistics,
store_stats: &StoreHubStats,
store_stats: Option<&StoreHubStats>,
) {
ui.strong("Rerun Viewer resource usage");

Expand All @@ -102,28 +102,30 @@ impl MemoryPanel {
Self::gpu_stats(ui, gpu_resource_stats);
});

ui.separator();
ui.collapsing("Datastore Resources", |ui| {
Self::store_stats(
ui,
&store_stats.recording_config,
&store_stats.recording_stats,
);
});
if let Some(store_stats) = store_stats {
ui.separator();
ui.collapsing("Datastore Resources", |ui| {
Self::store_stats(
ui,
&store_stats.recording_config,
&store_stats.recording_stats,
);
});

ui.separator();
ui.collapsing("Primary Cache Resources", |ui| {
self.caches_stats(ui, re_ui, &store_stats.recording_cached_stats);
});
ui.separator();
ui.collapsing("Primary Cache Resources", |ui| {
self.caches_stats(ui, re_ui, &store_stats.recording_cached_stats);
});

ui.separator();
ui.collapsing("Blueprint Resources", |ui| {
Self::store_stats(
ui,
&store_stats.blueprint_config,
&store_stats.blueprint_stats,
);
});
ui.separator();
ui.collapsing("Blueprint Resources", |ui| {
Self::store_stats(
ui,
&store_stats.blueprint_config,
&store_stats.blueprint_stats,
);
});
}
}

fn cpu_stats(ui: &mut egui::Ui, re_ui: &re_ui::ReUi, limit: &MemoryLimit) {
Expand Down

0 comments on commit e3d49d5

Please sign in to comment.