diff --git a/crates/re_viewer/src/app.rs b/crates/re_viewer/src/app.rs index d7616968a58d..9701ee2b56c5 100644 --- a/crates/re_viewer/src/app.rs +++ b/crates/re_viewer/src/app.rs @@ -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, @@ -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 { @@ -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() @@ -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); @@ -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 { diff --git a/crates/re_viewer/src/store_hub.rs b/crates/re_viewer/src/store_hub.rs index 5cb6ff9c6f8b..ca263ed8293c 100644 --- a/crates/re_viewer/src/store_hub.rs +++ b/crates/re_viewer/src/store_hub.rs @@ -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 diff --git a/crates/re_viewer/src/ui/memory_panel.rs b/crates/re_viewer/src/ui/memory_panel.rs index 2401bbd9816d..b4fe6692b852 100644 --- a/crates/re_viewer/src/ui/memory_panel.rs +++ b/crates/re_viewer/src/ui/memory_panel.rs @@ -28,7 +28,7 @@ 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( @@ -36,9 +36,9 @@ impl MemoryPanel { (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 _), ); } @@ -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!(); @@ -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"); @@ -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) {