Skip to content

Commit

Permalink
Fix: don't create a dummy LogDb when opening the Rerun Menu (#1440)
Browse files Browse the repository at this point in the history
* Fix: don't create a dummy LogDb when opening the Rerun Menu

* Add explanatory docstring
  • Loading branch information
emilk authored Feb 28, 2023
1 parent 8cfa784 commit 6be85c0
Showing 1 changed file with 23 additions and 15 deletions.
38 changes: 23 additions & 15 deletions crates/re_viewer/src/app.rs
Original file line number Diff line number Diff line change
Expand Up @@ -344,14 +344,16 @@ impl App {
}
}

fn selected_app_id(&mut self) -> ApplicationId {
let log_db = self.log_dbs.entry(self.state.selected_rec_id).or_default();
let selected_app_id = log_db
.recording_info()
.map_or_else(ApplicationId::unknown, |rec_info| {
rec_info.application_id.clone()
});
selected_app_id
fn selected_app_id(&self) -> ApplicationId {
if let Some(log_db) = self.log_dbs.get(&self.state.selected_rec_id) {
log_db
.recording_info()
.map_or_else(ApplicationId::unknown, |rec_info| {
rec_info.application_id.clone()
})
} else {
ApplicationId::unknown()
}
}

fn blueprint_mut(&mut self) -> &mut Blueprint {
Expand Down Expand Up @@ -744,6 +746,13 @@ impl App {
egui_ctx.set_style((*style).clone());
}

/// Do we have an open `LogDb` that is non-empty?
fn log_db_is_nonempty(&self) -> bool {
self.log_dbs
.get(&self.state.selected_rec_id)
.map_or(false, |log_db| !log_db.is_empty())
}

fn log_db(&mut self) -> &mut LogDb {
self.log_dbs.entry(self.state.selected_rec_id).or_default()
}
Expand Down Expand Up @@ -1327,7 +1336,7 @@ fn save_buttons_ui(ui: &mut egui::Ui, app: &mut App) {
});
});
} else {
ui.add_enabled_ui(!app.log_db().is_empty(), |ui| {
ui.add_enabled_ui(app.log_db_is_nonempty(), |ui| {
if ui
.add(save_button)
.on_hover_text("Save all data to a Rerun data file (.rrd)")
Expand Down Expand Up @@ -1382,7 +1391,7 @@ fn save(app: &mut App, loop_selection: Option<(re_data_store::Timeline, TimeRang
.set_title(title)
.save_file()
{
let f = save_database_to_file(app, path, loop_selection);
let f = save_database_to_file(app.log_db(), path, loop_selection);
if let Err(err) = app.spawn_threaded_promise(FILE_SAVER_PROMISE, f) {
// NOTE: Shouldn't even be possible as the "Save" button is already
// grayed out at this point... better safe than sorry though.
Expand All @@ -1394,7 +1403,7 @@ fn save(app: &mut App, loop_selection: Option<(re_data_store::Timeline, TimeRang
}

fn main_view_selector_ui(ui: &mut egui::Ui, app: &mut App) {
if !app.log_db().is_empty() {
if app.log_db_is_nonempty() {
ui.horizontal(|ui| {
ui.label("Main view:");
if ui
Expand Down Expand Up @@ -1581,16 +1590,15 @@ fn debug_menu_options_ui(ui: &mut egui::Ui) {
/// specific time range will be accounted for.
#[cfg(not(target_arch = "wasm32"))]
fn save_database_to_file(
app: &mut App,
log_db: &LogDb,
path: std::path::PathBuf,
time_selection: Option<(re_data_store::Timeline, TimeRangeF)>,
) -> impl FnOnce() -> anyhow::Result<std::path::PathBuf> {
use re_log_types::{EntityPathOpMsg, TimeInt};

let msgs = match time_selection {
// Fast path: no query, just dump everything.
None => app
.log_db()
None => log_db
.chronological_log_messages()
.cloned()
.collect::<Vec<_>>(),
Expand All @@ -1599,7 +1607,7 @@ fn save_database_to_file(
Some((timeline, range)) => {
use std::ops::RangeInclusive;
let range: RangeInclusive<TimeInt> = range.min.floor()..=range.max.ceil();
app.log_db()
log_db
.chronological_log_messages()
.filter(|msg| {
match msg {
Expand Down

1 comment on commit 6be85c0

@github-actions
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Rust Benchmark

Benchmark suite Current: 6be85c0 Previous: 9224783 Ratio
datastore/insert/batch/rects/insert 554445 ns/iter (± 1992) 550577 ns/iter (± 4953) 1.01
datastore/latest_at/batch/rects/query 1835 ns/iter (± 5) 1805 ns/iter (± 82) 1.02
datastore/latest_at/missing_components/primary 356 ns/iter (± 0) 358 ns/iter (± 2) 0.99
datastore/latest_at/missing_components/secondaries 425 ns/iter (± 0) 418 ns/iter (± 5) 1.02
datastore/range/batch/rects/query 152743 ns/iter (± 634) 151452 ns/iter (± 1899) 1.01
mono_points_arrow/generate_message_bundles 51783651 ns/iter (± 961527) 46668135 ns/iter (± 2038823) 1.11
mono_points_arrow/generate_messages 138039450 ns/iter (± 2010763) 135532022 ns/iter (± 1730848) 1.02
mono_points_arrow/encode_log_msg 166925473 ns/iter (± 2195985) 163573065 ns/iter (± 1536846) 1.02
mono_points_arrow/encode_total 358085797 ns/iter (± 1987665) 350723069 ns/iter (± 2935515) 1.02
mono_points_arrow/decode_log_msg 186764021 ns/iter (± 1577474) 186655516 ns/iter (± 1841571) 1.00
mono_points_arrow/decode_message_bundles 74871661 ns/iter (± 1004334) 74658108 ns/iter (± 1062782) 1.00
mono_points_arrow/decode_total 256482272 ns/iter (± 1879406) 252337801 ns/iter (± 3185540) 1.02
batch_points_arrow/generate_message_bundles 333103 ns/iter (± 1002) 329762 ns/iter (± 3463) 1.01
batch_points_arrow/generate_messages 6235 ns/iter (± 22) 6084 ns/iter (± 82) 1.02
batch_points_arrow/encode_log_msg 358383 ns/iter (± 1762) 351130 ns/iter (± 3523) 1.02
batch_points_arrow/encode_total 721998 ns/iter (± 2642) 705067 ns/iter (± 9322) 1.02
batch_points_arrow/decode_log_msg 352479 ns/iter (± 1235) 347728 ns/iter (± 2732) 1.01
batch_points_arrow/decode_message_bundles 2060 ns/iter (± 7) 1992 ns/iter (± 30) 1.03
batch_points_arrow/decode_total 353770 ns/iter (± 1347) 357518 ns/iter (± 2964) 0.99
arrow_mono_points/insert 6951746375 ns/iter (± 30499253) 7056235608 ns/iter (± 26103414) 0.99
arrow_mono_points/query 1759417 ns/iter (± 25501) 1737227 ns/iter (± 18825) 1.01
arrow_batch_points/insert 2658971 ns/iter (± 36380) 2702377 ns/iter (± 70971) 0.98
arrow_batch_points/query 17632 ns/iter (± 18) 17558 ns/iter (± 154) 1.00
tuid/Tuid::random 45 ns/iter (± 1) 34 ns/iter (± 0) 1.32

This comment was automatically generated by workflow using github-action-benchmark.

Please sign in to comment.