perf: reuse rendered elements across repaints
Rust / build (macos-latest, stable) (push) Canceled after 0s
Rust / build (ubuntu-latest, stable) (push) Canceled after 0s
Rust / build (windows-latest, stable) (push) Canceled after 0s

This commit is contained in:
2026-11-25 05:00:06 +07:00
parent 3f64b36ff4
commit bf06d29c2e
21 changed files with 603 additions and 316 deletions
+11 -6
View File
@@ -75,18 +75,18 @@ impl ExploreView {
let search_subscription = cx.subscribe(&search, |this, _search, event, cx| {
if matches!(event, InputStateEvent::TextChanged) {
this.rebuild_rows(cx);
this.rebuild_rows(false, cx);
}
});
let store_subscription = cx.observe(&store, |this, _store, cx| {
this.rebuild_rows(cx);
this.rebuild_rows(true, cx);
});
// The root and the stack are still being updated while this view is built.
cx.defer(move |cx| {
if let Err(error) = weak.update(cx, |this, cx| {
this.rebuild_rows(cx);
this.rebuild_rows(false, cx);
this.watch_stack(cx);
}) {
log::warn!("failed to set up the explore panel: {error}");
@@ -107,7 +107,8 @@ impl ExploreView {
}
}
fn rebuild_rows(&mut self, cx: &mut Context<Self>) {
/// `anchor` keeps the scroll position while the row count is unchanged.
fn rebuild_rows(&mut self, anchor: bool, cx: &mut Context<Self>) {
let filter = self.filter;
let query = self.search.read(cx).value().to_string();
let store = self.store.read(cx);
@@ -125,7 +126,11 @@ impl ExploreView {
directory.track(owners, cx);
});
self.scroll_handle.reset(self.item_count());
let count = self.item_count();
if !anchor || count != self.scroll_handle.item_count() {
self.scroll_handle.reset(count);
}
cx.notify();
}
@@ -223,7 +228,7 @@ impl ExploreView {
.on_change(move |filter, _, cx| {
if let Err(error) = weak.update(cx, |this, cx| {
this.filter = filter;
this.rebuild_rows(cx);
this.rebuild_rows(false, cx);
}) {
log::warn!("failed to change explore filter: {error}");
}