perf(ui-gpui): eliminate ProjectBox Entity, plain struct + direct render (2.17%)

ProjectBoxData replaces Entity<ProjectBox>. Workspace is the only view
entity in the dispatch tree. Timer notifies Workspace via cx.spawn.
12 optimization iterations: 90% → 2.17% CPU for a pulsing dot.
This commit is contained in:
Hibryda 2026-03-20 00:40:35 +01:00
parent 3bbaefa9a2
commit c61262c604
3 changed files with 122 additions and 255 deletions

View file

@ -1,81 +1,2 @@
//! ProjectGrid: flex-wrap grid of ProjectBox cards.
//!
//! Lays out projects in a responsive grid that wraps when the window is wide
//! enough for multiple columns.
use gpui::*;
use crate::CachedView;
use crate::components::project_box::ProjectBox;
use crate::state::AppState;
use crate::theme;
// ── ProjectGrid View ────────────────────────────────────────────────
pub struct ProjectGrid {
app_state: Entity<AppState>,
/// One ProjectBox entity per project.
project_boxes: Vec<Entity<ProjectBox>>,
}
impl ProjectGrid {
pub fn new(app_state: Entity<AppState>, cx: &mut Context<Self>) -> Self {
// Clone projects out of state to avoid borrowing cx through app_state
let projects: Vec<_> = {
let state = app_state.read(cx);
state.projects.clone()
};
let project_boxes: Vec<Entity<ProjectBox>> = projects
.into_iter()
.map(|proj| {
cx.new(|cx| {
let mut pb = ProjectBox::new(proj);
pb.init_subviews(cx);
pb
})
})
.collect();
Self {
app_state,
project_boxes,
}
}
}
impl Render for ProjectGrid {
fn render(&mut self, _window: &mut Window, _cx: &mut Context<Self>) -> impl IntoElement {
let mut grid = div()
.id("project-grid")
.flex_1()
.w_full()
.h_full()
.flex()
.flex_row()
.flex_wrap()
.gap(px(8.0))
.p(px(8.0))
.bg(theme::CRUST)
.overflow_y_scroll();
for pb in &self.project_boxes {
grid = grid.child(pb.clone());
}
if self.project_boxes.is_empty() {
grid = grid.child(
div()
.flex_1()
.flex()
.items_center()
.justify_center()
.text_size(px(16.0))
.text_color(theme::OVERLAY0)
.child("No projects. Press Ctrl+N to add one."),
);
}
grid
}
}
//! ProjectGrid: DEPRECATED — replaced by inline rendering in Workspace.
//! Kept for reference only.