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 (#5793)

### What
Whenever we gc the blueprint, it bumps the generation, which in turn
causes another save. By tracking the last gc, we never re-gc again if
nothing has changed.

### 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:
[rerun.io/viewer](https://rerun.io/viewer/pr/5793)
* Using examples from latest `main` build:
[rerun.io/viewer](https://rerun.io/viewer/pr/5793?manifest_url=https://app.rerun.io/version/main/examples_manifest.json)
* Using full set of examples from `nightly` build:
[rerun.io/viewer](https://rerun.io/viewer/pr/5793?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/5793)
- [Docs
preview](https://rerun.io/preview/b0543dcc9e0c0d9abd4fe67e940bf101794d0566/docs)
<!--DOCS-PREVIEW-->
- [Examples
preview](https://rerun.io/preview/b0543dcc9e0c0d9abd4fe67e940bf101794d0566/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
jleibs authored Apr 4, 2024
1 parent 6de5e14 commit 464f4fc
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 @@ -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());
}
}
}
Expand Down Expand Up @@ -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 {
Expand Down

0 comments on commit 464f4fc

Please sign in to comment.