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
|
|
@ -7,10 +7,14 @@
|
|||
//! The epoch counter cancels stale timers automatically.
|
||||
|
||||
use gpui::*;
|
||||
use std::sync::atomic::{AtomicU64, Ordering};
|
||||
use std::time::Duration;
|
||||
|
||||
use crate::theme;
|
||||
|
||||
static RENDER_COUNT: AtomicU64 = AtomicU64::new(0);
|
||||
static BLINK_COUNT: AtomicU64 = AtomicU64::new(0);
|
||||
|
||||
#[derive(Clone, Copy, PartialEq)]
|
||||
pub enum DotStatus {
|
||||
Running,
|
||||
|
|
@ -62,6 +66,7 @@ impl PulsingDot {
|
|||
this.update(cx, |dot, cx| {
|
||||
// Epoch guard: if epoch changed (pause/resume), this timer is stale
|
||||
if dot.blink_epoch == epoch {
|
||||
BLINK_COUNT.fetch_add(1, Ordering::Relaxed);
|
||||
dot.visible = !dot.visible;
|
||||
cx.notify(); // marks ONLY this view dirty
|
||||
dot.schedule_blink(epoch, cx); // recursive schedule
|
||||
|
|
@ -83,6 +88,11 @@ impl PulsingDot {
|
|||
|
||||
impl Render for PulsingDot {
|
||||
fn render(&mut self, _window: &mut Window, _cx: &mut Context<Self>) -> impl IntoElement {
|
||||
let rc = RENDER_COUNT.fetch_add(1, Ordering::Relaxed);
|
||||
if rc % 60 == 0 {
|
||||
let bc = BLINK_COUNT.load(Ordering::Relaxed);
|
||||
eprintln!("[PulsingDot] renders={rc} blinks={bc} (renders should be ~2x blinks)");
|
||||
}
|
||||
let color = self.color();
|
||||
let r = (color.r * 255.0) as u32;
|
||||
let g = (color.g * 255.0) as u32;
|
||||
|
|
|
|||
|
|
@ -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