Skip to content

Commit

Permalink
New time panel density graph (#1557)
Browse files Browse the repository at this point in the history
* Refactor: move the data density graph to its own file

* Cleanup: use TimeRange

* Refactor: simplify further

* Replace ball scatterer with density graph

* Tweak

* bug fix

* Small refactor

* Create time_range_from_x_range helper

* Allow-list clippy::manual_range_contains

* objectron-rs fix: only log the base objects once

* Normalize the density graphs

* Smooth normalization, and selection color

* Highlight on hover

* Better hover effect

* Better naming: `Item` is called `item`

* Add a consistent line behind the density graph

* Remove dead code

* Integrate re_int_histogram

* Remove static_assert that trips up rust-analyzer

* Cleanup

* Use saturating functions when casting TimeReal -> TimeInt

* Add some TODO:s

* Fix wrong x-range

* Fix typo

* Fix potential integer overflow

* Fix a TODO

* tweaks

* Tweak colors

* Add some tests

* re_int_histogram: make `range` return tight ranges

* Faster data density graph

* Switch to the faster re_int_histogram

* Smoother density graph using box filter

* Code cleanup

* Make TimeAxis run in logarithmic time

* Fix typos

* Tweak the normalization speed

* Self-review cleanup

* Add feathering anti-aliasing to the density graph painter

* use `mod` instead of comments

* Remove dead static_assertions

* typo

Co-authored-by: Jeremy Leibs <[email protected]>

* nits

* fix docstring link

---------

Co-authored-by: Jeremy Leibs <[email protected]>
  • Loading branch information
emilk and jleibs authored Mar 14, 2023
1 parent beb49b1 commit 1792207
Show file tree
Hide file tree
Showing 22 changed files with 1,159 additions and 709 deletions.
1 change: 1 addition & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ re_build_web_viewer = { path = "crates/re_build_web_viewer", version = "0.3.1" }
re_data_store = { path = "crates/re_data_store", version = "0.3.1" }
re_error = { path = "crates/re_error", version = "0.3.1" }
re_format = { path = "crates/re_format", version = "0.3.1" }
re_int_histogram = { path = "crates/re_int_histogram", version = "0.3.1" }
re_log = { path = "crates/re_log", version = "0.3.1" }
re_log_types = { path = "crates/re_log_types", version = "0.3.1" }
re_memory = { path = "crates/re_memory", version = "0.3.1" }
Expand Down
4 changes: 3 additions & 1 deletion Cranky.toml
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,9 @@ warn = [
]

allow = [
# TODO(emilk): enable more lints
"clippy::manual_range_contains", # this one is just worse imho

# TODO(emilk): enable more of these lints:
"clippy::cloned_instead_of_copied",
"clippy::missing_errors_doc",
"trivial_casts",
Expand Down
1 change: 1 addition & 0 deletions crates/re_data_store/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ serde = ["dep:serde", "re_log_types/serde"]

[dependencies]
re_arrow_store.workspace = true
re_int_histogram.workspace = true
re_log_types.workspace = true
re_log.workspace = true
re_smart_channel.workspace = true
Expand Down
33 changes: 15 additions & 18 deletions crates/re_data_store/src/entity_tree.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,30 +8,31 @@ use re_log_types::{

// ----------------------------------------------------------------------------

/// Number of messages per time
pub type TimeHistogram = re_int_histogram::Int64Histogram;

/// Number of messages per time per timeline
#[derive(Default)]
pub struct TimeHistogramPerTimeline(BTreeMap<Timeline, BTreeMap<TimeInt, usize>>);
pub struct TimeHistogramPerTimeline(BTreeMap<Timeline, TimeHistogram>);

impl TimeHistogramPerTimeline {
pub fn timelines(&self) -> impl ExactSizeIterator<Item = &Timeline> {
self.0.keys()
}

pub fn get(&self, timeline: &Timeline) -> Option<&BTreeMap<TimeInt, usize>> {
pub fn get(&self, timeline: &Timeline) -> Option<&TimeHistogram> {
self.0.get(timeline)
}

pub fn has_timeline(&self, timeline: &Timeline) -> bool {
self.0.contains_key(timeline)
}

pub fn iter(&self) -> impl ExactSizeIterator<Item = (&Timeline, &BTreeMap<TimeInt, usize>)> {
pub fn iter(&self) -> impl ExactSizeIterator<Item = (&Timeline, &TimeHistogram)> {
self.0.iter()
}

pub fn iter_mut(
&mut self,
) -> impl ExactSizeIterator<Item = (&Timeline, &mut BTreeMap<TimeInt, usize>)> {
pub fn iter_mut(&mut self) -> impl ExactSizeIterator<Item = (&Timeline, &mut TimeHistogram)> {
self.0.iter_mut()
}
}
Expand Down Expand Up @@ -239,13 +240,11 @@ impl EntityTree {
self.num_timeless_messages += 1;
} else {
for (timeline, time_value) in time_point.iter() {
*self
.prefix_times
self.prefix_times
.0
.entry(*timeline)
.or_default()
.entry(*time_value)
.or_default() += 1;
.increment(time_value.as_i64(), 1);
}
}

Expand Down Expand Up @@ -293,10 +292,10 @@ impl EntityTree {
components: fields,
} = self;

for (timeline, map) in &mut prefix_times.0 {
for (timeline, histogram) in &mut prefix_times.0 {
crate::profile_scope!("prefix_times");
if let Some(cutoff_time) = cutoff_times.get(timeline) {
map.retain(|time_int, _count| cutoff_time.is_timeless() || cutoff_time <= time_int);
histogram.remove(..cutoff_time.as_i64());
}
}
{
Expand Down Expand Up @@ -349,13 +348,11 @@ impl ComponentStats {
self.num_timeless_messages += 1;
} else {
for (timeline, time_value) in time_point.iter() {
*self
.times
self.times
.0
.entry(*timeline)
.or_default()
.entry(*time_value)
.or_default() += 1;
.increment(time_value.as_i64(), 1);
}
}
}
Expand All @@ -366,9 +363,9 @@ impl ComponentStats {
num_timeless_messages: _,
} = self;

for (timeline, time_counts) in &mut times.0 {
for (timeline, histogram) in &mut times.0 {
if let Some(cutoff_time) = cutoff_times.get(timeline) {
time_counts.retain(|time_int, _count| cutoff_time <= time_int);
histogram.remove(..cutoff_time.as_i64());
}
}
}
Expand Down
Loading

1 comment on commit 1792207

@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: 1792207 Previous: beb49b1 Ratio
datastore/insert/batch/rects/insert 550683 ns/iter (± 3116) 567127 ns/iter (± 4003) 0.97
datastore/latest_at/batch/rects/query 1859 ns/iter (± 1) 1834 ns/iter (± 7) 1.01
datastore/latest_at/missing_components/primary 286 ns/iter (± 0) 286 ns/iter (± 1) 1
datastore/latest_at/missing_components/secondaries 440 ns/iter (± 1) 429 ns/iter (± 5) 1.03
datastore/range/batch/rects/query 151542 ns/iter (± 668) 151517 ns/iter (± 1429) 1.00
mono_points_arrow/generate_message_bundles 50303635 ns/iter (± 936482) 49141442 ns/iter (± 1245108) 1.02
mono_points_arrow/generate_messages 136618493 ns/iter (± 1071045) 134995710 ns/iter (± 1561175) 1.01
mono_points_arrow/encode_log_msg 167944922 ns/iter (± 788902) 163604927 ns/iter (± 1481075) 1.03
mono_points_arrow/encode_total 355510814 ns/iter (± 1545110) 351269150 ns/iter (± 2272101) 1.01
mono_points_arrow/decode_log_msg 187438049 ns/iter (± 1029803) 187327480 ns/iter (± 1840438) 1.00
mono_points_arrow/decode_message_bundles 73438704 ns/iter (± 1034209) 72493986 ns/iter (± 1168794) 1.01
mono_points_arrow/decode_total 259027478 ns/iter (± 2585415) 258001176 ns/iter (± 2283119) 1.00
batch_points_arrow/generate_message_bundles 332638 ns/iter (± 1256) 323964 ns/iter (± 4290) 1.03
batch_points_arrow/generate_messages 6292 ns/iter (± 22) 6309 ns/iter (± 88) 1.00
batch_points_arrow/encode_log_msg 355178 ns/iter (± 3185) 349892 ns/iter (± 3400) 1.02
batch_points_arrow/encode_total 708875 ns/iter (± 3171) 703678 ns/iter (± 7012) 1.01
batch_points_arrow/decode_log_msg 347362 ns/iter (± 2355) 349596 ns/iter (± 3073) 0.99
batch_points_arrow/decode_message_bundles 2110 ns/iter (± 13) 2141 ns/iter (± 24) 0.99
batch_points_arrow/decode_total 354341 ns/iter (± 1521) 349752 ns/iter (± 2472) 1.01
arrow_mono_points/insert 6904330112 ns/iter (± 14106181) 6884632489 ns/iter (± 20106262) 1.00
arrow_mono_points/query 1760917 ns/iter (± 25829) 1769409 ns/iter (± 32427) 1.00
arrow_batch_points/insert 2672911 ns/iter (± 18939) 2625604 ns/iter (± 30741) 1.02
arrow_batch_points/query 16957 ns/iter (± 88) 16549 ns/iter (± 269) 1.02
arrow_batch_vecs/insert 41988 ns/iter (± 257) 41403 ns/iter (± 491) 1.01
arrow_batch_vecs/query 388422 ns/iter (± 2971) 380609 ns/iter (± 6234) 1.02
tuid/Tuid::random 34 ns/iter (± 0) 34 ns/iter (± 0) 1

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

Please sign in to comment.