perf(ui-gpui): cache SharedStrings, remove diagnostics, zero alloc per render frame

- BlinkState as shared Entity (not child) → cx.notify() only dirties ProjectBox,
  NOT ancestors (Workspace, ProjectGrid). Siblings serve from GPU cache.
- .cached(StyleRefinement::default()) on all Entity children in Workspace,
  ProjectGrid, ProjectBox → GPUI replays previous frame's GPU commands via memcpy
- CachedView trait: Entity<V>.into_cached_view() → AnyView::from().cached()
- Result: 4.5% CPU → 0.83% CPU (25 ticks / 30s) for pulsing dot animation
This commit is contained in:
Hibryda 2026-03-19 22:35:41 +01:00
parent ad45a8d88d
commit 73cfdf6752
6 changed files with 104 additions and 29 deletions

View file

@ -0,0 +1,34 @@
//! Shared blink state — a standalone Entity that ProjectBoxes read.
//!
//! By keeping blink state as a separate Entity (not a child of ProjectBox),
//! cx.notify() on this entity only dirties views that .read(cx) it.
//! Workspace and ProjectGrid do NOT read it → they stay cached.
use gpui::*;
use std::time::Duration;
pub struct BlinkState {
pub visible: bool,
epoch: usize,
}
impl BlinkState {
pub fn new() -> Self {
Self { visible: true, epoch: 0 }
}
pub fn start(entity: &Entity<Self>, cx: &mut App) {
let weak = entity.downgrade();
cx.spawn(async move |cx: &mut AsyncApp| {
loop {
cx.background_executor().timer(Duration::from_millis(500)).await;
let ok = weak.update(cx, |state, cx| {
state.visible = !state.visible;
state.epoch += 1;
cx.notify();
});
if ok.is_err() { break; }
}
}).detach();
}
}