Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve performance for Blueprint & Streams Panel for many entities #8808

Open
wants to merge 2 commits into
base: antoine/filt6-blueprint-view-refactor
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 12 additions & 4 deletions crates/viewer/re_blueprint_tree/src/blueprint_tree.rs
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,7 @@ impl BlueprintTree {

let item_response = ui
.list_item()
.render_offscreen(false)
.selected(ctx.selection().contains_item(&item))
.draggable(true) // allowed for consistency but results in an invalid drag
.drop_target_style(self.is_candidate_drop_parent_container(&container_data.id))
Expand Down Expand Up @@ -273,6 +274,7 @@ impl BlueprintTree {
..
} = ui
.list_item()
.render_offscreen(false)
.selected(ctx.selection().contains_item(&item))
.draggable(true)
.drop_target_style(self.is_candidate_drop_parent_container(&container_data.id))
Expand Down Expand Up @@ -361,6 +363,7 @@ impl BlueprintTree {
..
} = ui
.list_item()
.render_offscreen(false)
.selected(ctx.selection().contains_item(&item))
.draggable(true)
.force_hovered(is_item_hovered)
Expand All @@ -376,10 +379,13 @@ impl BlueprintTree {
}

if !view_data.projection_trees.is_empty() {
ui.list_item().interactive(false).show_flat(
ui,
list_item::LabelContent::new("Projections:").italics(true),
);
ui.list_item()
.render_offscreen(false)
.interactive(false)
.show_flat(
ui,
list_item::LabelContent::new("Projections:").italics(true),
);

for projection in &view_data.projection_trees {
self.data_result_ui(ctx, viewport_blueprint, ui, projection, view_visible);
Expand Down Expand Up @@ -482,6 +488,7 @@ impl BlueprintTree {
DataResultKind::OriginProjectionPlaceholder => {
if ui
.list_item()
.render_offscreen(false)
.show_hierarchical(
ui,
list_item::LabelContent::new("$origin")
Expand All @@ -508,6 +515,7 @@ impl BlueprintTree {

let list_item = ui
.list_item()
.render_offscreen(false)
.draggable(true)
.selected(is_selected)
.force_hovered(is_item_hovered);
Expand Down
29 changes: 17 additions & 12 deletions crates/viewer/re_time_panel/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -760,6 +760,7 @@ impl TimePanel {
..
} = ui
.list_item()
.render_offscreen(false)
.selected(is_selected)
.draggable(true)
.force_hovered(is_item_hovered)
Expand Down Expand Up @@ -925,6 +926,7 @@ impl TimePanel {

let response = ui
.list_item()
.render_offscreen(false)
.selected(ctx.selection().contains_item(&item.to_item()))
.force_hovered(
ctx.selection_state()
Expand Down Expand Up @@ -975,18 +977,21 @@ impl TimePanel {
format!("{} times", re_format::format_uint(num_messages))
};

ui.list_item().interactive(false).show_flat(
ui,
list_item::LabelContent::new(format!(
"{kind} component, logged {num_messages}"
))
.truncate(false)
.with_icon(if is_static {
&re_ui::icons::COMPONENT_STATIC
} else {
&re_ui::icons::COMPONENT_TEMPORAL
}),
);
ui.list_item()
.interactive(false)
.render_offscreen(false)
.show_flat(
ui,
list_item::LabelContent::new(format!(
"{kind} component, logged {num_messages}"
))
.truncate(false)
.with_icon(if is_static {
&re_ui::icons::COMPONENT_STATIC
} else {
&re_ui::icons::COMPONENT_TEMPORAL
}),
);

// Static components are not displayed at all on the timeline, so cannot be
// previewed there. So we display their content in this tooltip instead.
Expand Down
23 changes: 23 additions & 0 deletions crates/viewer/re_ui/src/list_item/list_item.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ pub struct ListItem {
force_background: Option<egui::Color32>,
pub collapse_openness: Option<f32>,
height: f32,
render_offscreen: bool,
}

impl Default for ListItem {
Expand All @@ -62,6 +63,7 @@ impl Default for ListItem {
force_background: None,
collapse_openness: None,
height: DesignTokens::list_item_height(),
render_offscreen: true,
}
}
}
Expand Down Expand Up @@ -140,6 +142,18 @@ impl ListItem {
self
}

/// Controls whether [`Self`] calls [`ListItemContent::ui`] when the item is not currently
/// visible.
///
/// Skipping rendering can increase performances for long lists that are mostly out of view, but
/// this will prevent any side effects from [`ListItemContent::ui`] from occurring. For this
/// reason, this is an opt-in optimization.
Comment on lines +148 to +150
Copy link
Member

Choose a reason for hiding this comment

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

to clarify, could such a side-effect change the vertical size of a list array? If not, then wouldn't it be reasonable to expect this to be opt-in? I mean we're passing a closure after all for drawing a thing - if the thing isn't on screen, why would you expect your closure to be called; lotsa place don't do that

Copy link
Member Author

Choose a reason for hiding this comment

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

No, the vertical size is fully determined by ListItem::height. Also, this change only affects the list item itself, not the fact that it might have children in a collapsing section below it. So there cannot be any issue with vertical layout.

And you are probably right that I'm being overly defensive with this opt-in stuff. I really don't have a strong reason to not make it opt-out (or even always on), except of being scared to break things in untested areas 😅

Copy link
Member

@Wumpf Wumpf Jan 24, 2025

Choose a reason for hiding this comment

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

hmmm I'd really like to make it opt-out in that case, but we can also do this maybe just after the next release then if we're too scared of adding regressions

#[inline]
pub fn render_offscreen(mut self, render_offscreen: bool) -> Self {
self.render_offscreen = render_offscreen;
self
}

/// Draw the item as part of a flat list.
///
/// *Important*: must be called while nested in a [`super::list_item_scope`].
Expand Down Expand Up @@ -274,6 +288,7 @@ impl ListItem {
force_background,
collapse_openness,
height,
render_offscreen,
} = self;

let collapse_extra = if collapse_openness.is_some() {
Expand Down Expand Up @@ -329,6 +344,14 @@ impl ListItem {
// allocate past the available width.
response.rect = rect;

let should_render = render_offscreen || ui.is_rect_visible(rect);
if !should_render {
return ListItemResponse {
response,
collapse_response: None,
};
}

// override_hover should not affect the returned response
let mut style_response = response.clone();
if force_hovered {
Expand Down
Loading