perf(ui-gpui): cache SharedStrings, remove diagnostics, zero alloc per render frame
This commit is contained in:
parent
b557aeb833
commit
5dbf5bd43c
3 changed files with 44 additions and 69 deletions
|
|
@ -68,16 +68,30 @@ fn tab_button(label: &str, active: bool, accent: Rgba) -> Div {
|
|||
|
||||
pub struct ProjectBox {
|
||||
pub project: Project,
|
||||
/// Entity handle for the embedded AgentPane (Model tab)
|
||||
pub agent_pane: Option<Entity<crate::components::agent_pane::AgentPane>>,
|
||||
/// Entity handle for the embedded terminal (Model tab)
|
||||
pub terminal_view: Option<Entity<crate::terminal::renderer::TerminalView>>,
|
||||
pub status_dot: Option<Entity<PulsingDot>>,
|
||||
// Cached strings to avoid allocation on every render
|
||||
id_project: SharedString,
|
||||
id_model: SharedString,
|
||||
id_resize: SharedString,
|
||||
id_docs: SharedString,
|
||||
id_files: SharedString,
|
||||
cached_name: SharedString,
|
||||
cached_cwd: SharedString,
|
||||
}
|
||||
|
||||
impl ProjectBox {
|
||||
pub fn new(project: Project) -> Self {
|
||||
let id = &project.id;
|
||||
Self {
|
||||
id_project: SharedString::from(format!("project-{id}")),
|
||||
id_model: SharedString::from(format!("model-{id}")),
|
||||
id_resize: SharedString::from(format!("resize-{id}")),
|
||||
id_docs: SharedString::from(format!("docs-{id}")),
|
||||
id_files: SharedString::from(format!("files-{id}")),
|
||||
cached_name: SharedString::from(project.name.clone()),
|
||||
cached_cwd: SharedString::from(project.cwd.clone()),
|
||||
project,
|
||||
agent_pane: None,
|
||||
terminal_view: None,
|
||||
|
|
@ -117,23 +131,16 @@ impl ProjectBox {
|
|||
}
|
||||
}
|
||||
|
||||
static PB_RENDERS: std::sync::atomic::AtomicU64 = std::sync::atomic::AtomicU64::new(0);
|
||||
|
||||
impl Render for ProjectBox {
|
||||
fn render(&mut self, _window: &mut Window, _cx: &mut Context<Self>) -> impl IntoElement {
|
||||
let pbc = PB_RENDERS.fetch_add(1, std::sync::atomic::Ordering::Relaxed);
|
||||
if pbc % 10 == 0 { eprintln!("[ProjectBox] render #{pbc}"); }
|
||||
let accent = accent_color(self.project.accent_index);
|
||||
let name = self.project.name.clone();
|
||||
let cwd = self.project.cwd.clone();
|
||||
let status = self.project.agent.status;
|
||||
let active_tab = self.project.active_tab;
|
||||
|
||||
// Build content area based on active tab
|
||||
let content = match active_tab {
|
||||
ProjectTab::Model => {
|
||||
let mut model_content = div()
|
||||
.id(SharedString::from(format!("model-content-{}", self.project.id)))
|
||||
.id(self.id_model.clone())
|
||||
.flex_1()
|
||||
.w_full()
|
||||
.flex()
|
||||
|
|
@ -152,7 +159,7 @@ impl Render for ProjectBox {
|
|||
// Resize handle
|
||||
model_content = model_content.child(
|
||||
div()
|
||||
.id(SharedString::from(format!("resize-{}", self.project.id)))
|
||||
.id(self.id_resize.clone())
|
||||
.w_full()
|
||||
.h(px(4.0))
|
||||
.bg(theme::SURFACE0)
|
||||
|
|
@ -174,7 +181,7 @@ impl Render for ProjectBox {
|
|||
}
|
||||
ProjectTab::Docs => {
|
||||
div()
|
||||
.id(SharedString::from(format!("docs-content-{}", self.project.id)))
|
||||
.id(self.id_docs.clone())
|
||||
.flex_1()
|
||||
.w_full()
|
||||
.flex()
|
||||
|
|
@ -186,7 +193,7 @@ impl Render for ProjectBox {
|
|||
}
|
||||
ProjectTab::Files => {
|
||||
div()
|
||||
.id(SharedString::from(format!("files-content-{}", self.project.id)))
|
||||
.id(self.id_files.clone())
|
||||
.flex_1()
|
||||
.w_full()
|
||||
.flex()
|
||||
|
|
@ -223,7 +230,7 @@ impl Render for ProjectBox {
|
|||
};
|
||||
|
||||
div()
|
||||
.id(SharedString::from(format!("project-{}", self.project.id)))
|
||||
.id(self.id_project.clone())
|
||||
.flex_1()
|
||||
.min_w(px(400.0))
|
||||
.min_h(px(300.0))
|
||||
|
|
@ -262,7 +269,7 @@ impl Render for ProjectBox {
|
|||
div()
|
||||
.text_size(px(13.0))
|
||||
.text_color(theme::TEXT)
|
||||
.child(name),
|
||||
.child(self.cached_name.clone()),
|
||||
)
|
||||
.child(div().flex_1())
|
||||
// CWD (ellipsized)
|
||||
|
|
@ -273,7 +280,7 @@ impl Render for ProjectBox {
|
|||
.max_w(px(200.0))
|
||||
.overflow_hidden()
|
||||
.whitespace_nowrap()
|
||||
.child(cwd),
|
||||
.child(self.cached_cwd.clone()),
|
||||
),
|
||||
)
|
||||
// ── Tab Bar ─────────────────────────────────────────
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue