From b0543dcc9e0c0d9abd4fe67e940bf101794d0566 Mon Sep 17 00:00:00 2001 From: Jeremy Leibs Date: Thu, 4 Apr 2024 12:18:07 -0400 Subject: [PATCH] Prevent gratuitous blueprint saves by not gc'ing when the blueprint hasn't changed. --- crates/re_viewer_context/src/store_hub.rs | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/crates/re_viewer_context/src/store_hub.rs b/crates/re_viewer_context/src/store_hub.rs index afcf64a1667a..763f07dbf57f 100644 --- a/crates/re_viewer_context/src/store_hub.rs +++ b/crates/re_viewer_context/src/store_hub.rs @@ -45,8 +45,11 @@ pub struct StoreHub { /// Was a recording ever activated? Used by the heuristic controlling the welcome screen. was_recording_active: bool, - // The [`StoreGeneration`] from when the [`EntityDb`] was last saved + /// The [`StoreGeneration`] from when the [`EntityDb`] was last saved blueprint_last_save: HashMap, + + /// The [`StoreGeneration`] from when the [`EntityDb`] was last garbage collected + blueprint_last_gc: HashMap, } /// Load a blueprint from persisted storage, e.g. disk. @@ -128,6 +131,7 @@ impl StoreHub { was_recording_active: false, blueprint_last_save: Default::default(), + blueprint_last_gc: Default::default(), } } @@ -547,9 +551,16 @@ impl StoreHub { .chain(self.default_blueprint_by_app_id.values()) { if let Some(blueprint) = self.store_bundle.get_mut(blueprint_id) { + if self.blueprint_last_gc.get(blueprint_id) == Some(&blueprint.generation()) { + continue; // no change since last gc + } + // TODO(jleibs): Decide a better tuning for this. Would like to save a // reasonable amount of history, or incremental snapshots. blueprint.gc_everything_but_the_latest_row(); + + self.blueprint_last_gc + .insert(blueprint_id.clone(), blueprint.generation()); } } } @@ -579,6 +590,8 @@ impl StoreHub { if app_options.blueprint_gc { blueprint.gc_everything_but_the_latest_row(); + self.blueprint_last_gc + .insert(blueprint_id.clone(), blueprint.generation()); } if let Some(saver) = &self.persistence.saver {