Skip to content

Commit

Permalink
Prevent gratuitous blueprint saves by not gc'ing when the blueprint h…
Browse files Browse the repository at this point in the history
…asn't changed.
  • Loading branch information
jleibs committed Apr 4, 2024
1 parent 77d6a29 commit 0afe50c
Showing 1 changed file with 14 additions and 1 deletion.
15 changes: 14 additions & 1 deletion crates/re_viewer_context/src/store_hub.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<StoreId, StoreGeneration>,

/// The [`StoreGeneration`] from when the [`EntityDb`] was last garbage collected
blueprint_last_gc: HashMap<StoreId, StoreGeneration>,
}

/// Load a blueprint from persisted storage, e.g. disk.
Expand Down Expand Up @@ -128,6 +131,7 @@ impl StoreHub {
was_recording_active: false,

blueprint_last_save: Default::default(),
blueprint_last_gc: Default::default(),
}
}

Expand Down Expand Up @@ -539,9 +543,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());
}
}
}
Expand Down Expand Up @@ -571,6 +582,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 {
Expand Down

0 comments on commit 0afe50c

Please sign in to comment.