gpui: Reduce window.refresh
to improve cache hit of the cached views (#25009)
Release Notes: - Improved performance when using the scroll wheel and some other mouse interactions. Based on some cache details about GPUI `AnyView::cached` that I found in the discussion of https://github.com/zed-industries/zed/discussions/24260#discussioncomment-12135749, and combined with the optimization points found in actual applications. This change may have some scenarios that I have not considered, so I just make a draft to put forward my ideas first for discussion. From my analysis, `AnyView::cached` will always invalid by Div's mouse events, because of it called `window.refresh`. I understand that (mouse move event) this is because the interface changes related to hover and mouse_move will be affected style, so `window.refresh` is required. Since Div does not have the `entity_id` of View, it is impossible to know which View should be refreshed, so the entire window can only be refreshed. With this change, we can reduce a lot of `render` method calls on ScrollWheel or Mouse Event.
This commit is contained in:
parent
89ae4ca9a3
commit
985ac4e5f2
4 changed files with 38 additions and 22 deletions
|
@ -265,6 +265,8 @@ mod uniform_list {
|
|||
window: &mut Window,
|
||||
_cx: &mut App,
|
||||
) {
|
||||
let current_view = window.current_view();
|
||||
|
||||
match prepaint {
|
||||
IndentGuidesElementPrepaintState::Static => {
|
||||
for indent_guide in self.indent_guides.as_ref() {
|
||||
|
@ -326,7 +328,7 @@ mod uniform_list {
|
|||
window.on_mouse_event({
|
||||
let prev_hovered_hitbox_id = hovered_hitbox_id;
|
||||
let hitboxes = hitboxes.clone();
|
||||
move |_: &MouseMoveEvent, phase, window, _cx| {
|
||||
move |_: &MouseMoveEvent, phase, window, cx| {
|
||||
let mut hovered_hitbox_id = None;
|
||||
for hitbox in hitboxes.as_ref() {
|
||||
if hitbox.is_hovered(window) {
|
||||
|
@ -339,15 +341,11 @@ mod uniform_list {
|
|||
match (prev_hovered_hitbox_id, hovered_hitbox_id) {
|
||||
(Some(prev_id), Some(id)) => {
|
||||
if prev_id != id {
|
||||
window.refresh();
|
||||
cx.notify(current_view)
|
||||
}
|
||||
}
|
||||
(None, Some(_)) => {
|
||||
window.refresh();
|
||||
}
|
||||
(Some(_), None) => {
|
||||
window.refresh();
|
||||
}
|
||||
(None, Some(_)) => cx.notify(current_view),
|
||||
(Some(_), None) => cx.notify(current_view),
|
||||
(None, None) => {}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue