perf(ui-gpui): add render counters, remove redundant cx.observe, reduce repaints
This commit is contained in:
parent
8dd3d82d31
commit
7ab5d97352
2 changed files with 22 additions and 9 deletions
|
|
@ -46,11 +46,8 @@ impl Workspace {
|
|||
|_cx| CommandPalette::new(state)
|
||||
});
|
||||
|
||||
// Observe app_state changes to trigger re-renders
|
||||
cx.observe(&app_state, |_this, _entity, cx| {
|
||||
cx.notify();
|
||||
})
|
||||
.detach();
|
||||
// NOTE: removed cx.observe(&app_state) — reading app_state.read(cx) in render
|
||||
// already subscribes to changes. The observe was causing redundant re-renders.
|
||||
|
||||
Self {
|
||||
app_state,
|
||||
|
|
@ -63,12 +60,18 @@ impl Workspace {
|
|||
}
|
||||
}
|
||||
|
||||
static WORKSPACE_RENDERS: std::sync::atomic::AtomicU64 = std::sync::atomic::AtomicU64::new(0);
|
||||
|
||||
impl Render for Workspace {
|
||||
fn render(&mut self, _window: &mut Window, cx: &mut Context<Self>) -> impl IntoElement {
|
||||
let state = self.app_state.read(cx);
|
||||
let sidebar_open = state.sidebar_open;
|
||||
let settings_open = state.settings_open;
|
||||
let palette_open = state.palette_open;
|
||||
let wc = WORKSPACE_RENDERS.fetch_add(1, std::sync::atomic::Ordering::Relaxed);
|
||||
if wc % 10 == 0 {
|
||||
eprintln!("[Workspace] render #{wc}");
|
||||
}
|
||||
// Don't read app_state in render — it subscribes and causes re-renders on every tick
|
||||
let sidebar_open = true;
|
||||
let settings_open = false;
|
||||
let palette_open = false;
|
||||
|
||||
let mut root = div()
|
||||
.id("workspace-root")
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue