A modern terminal with a built-in multiplexer: close it and your sessions keep running. Run shells and tons of AI agents across your machines, then pick them up from desktop, browser, TUI and more. Written in Rust with no UI framework: interface drawn straight on the GPU. No Electron, GPUI or webview.
Rust agentagent-orchestrationaiai-agentsclaude-codecodexcoding-agentlinuxmacosmultiplayermultiplexerrustterminalterminal-emulatorterminal-multiplexertmuxtuiweztermwindows
perf(gui): release the Live Overview card previews after five idle minutes
RoversX70217da3bcea
diff --git a/wezterm-gui/src/termwindow/mod.rs b/wezterm-gui/src/termwindow/mod.rsindex 3ef0ea9f..d9162f7f 100644--- a/wezterm-gui/src/termwindow/mod.rs+++ b/wezterm-gui/src/termwindow/mod.rs@@ -2431,6 +2431,9 @@ pub struct TermWindow {/// The one card rebuild currently sliced across frames, if any.preview_rebuild_partial:RefCell<Option<crate::termwindow::render::paint::PreviewRebuildPartial>>,+ /// When a paint last asked for card previews; None once the caches+ /// have been released. Drives the idle release of `preview_quad_cache`.+ preview_cache_last_wanted: Option<Instant>,/// When each card's terminal first showed visible content, keyed like/// `preview_quad_cache`. Drives the blank->content fade-in; survives/// overview closes and atlas repacks so neither replays the fade.@@ -3544,6 +3547,46 @@ impl TermWindow {}}+ /// The card previews outlive the overview on purpose: reopening it+ /// replays them instead of rebuilding every card in the revealing+ /// frame. But an overview closed for good keeps its quads and card+ /// textures resident for the life of the window. Once no paint has+ /// asked for previews for the grace period, and no view or transition+ /// can still be showing them, let them go; the next open rebuilds+ /// them once. Driven from the 1s status heartbeat for the same reasons+ /// as the occlusion release.+ fn maybe_release_idle_preview_cache(&mut self) {+ let showing = self.content_view_foreground() || self.content_view_fade.is_some();+ if !preview_cache_release_due(+ self.preview_cache_last_wanted.map(|since| since.elapsed()),+ showing,+ ) {+ return;+ }+ self.preview_cache_last_wanted = None;+ let footprint = self.preview_cache_footprint();+ if footprint.cards == 0 && footprint.quad_bytes == 0 {+ return;+ }+ log::debug!(+ "overview idle for {PREVIEW_CACHE_RELEASE_SECS}s; releasing {} card previews \+ ({} bytes of quads, {} bytes of card textures)",+ footprint.cards,+ footprint.quad_bytes,+ footprint.texture_bytes+ );+ self.preview_quad_cache.borrow_mut().clear();+ *self.preview_rebuild_partial.borrow_mut() = None;+ // The textures just dropped stay resident until a device maintain+ // runs; a window painting only its terminal may not submit one+ // soon, so poll now, as the occlusion release does.+ if let Some(webgpu) = self.webgpu.as_ref() {+ if let Err(err) = webgpu.device.poll(wgpu::PollType::Poll) {+ log::debug!("device poll after preview cache release: {err:?}");+ }+ }+ }+/// A window nobody can see keeps everything it ever cached. Once it/// has stayed hidden past the grace period, drop the caches that/// rebuild lazily on the reveal repaint: the note and file-preview@@ -4017,6 +4060,7 @@ impl TermWindow {pane_font_cache_tick: Cell::new(0),preview_quad_cache: RefCell::new(HashMap::new()),preview_rebuild_partial: RefCell::new(None),+ preview_cache_last_wanted: None,preview_content_fade: RefCell::new(HashMap::new()),pending_card_renders: RefCell::new(Vec::new()),card_frame_verts: RefCell::new(Vec::new()),@@ -5377,6 +5421,7 @@ impl TermWindow {self.refresh_all_thread_work();self.terminal_render_watchdog();self.maybe_release_occluded_memory();+ self.maybe_release_idle_preview_cache();}TermWindowNotif::OpenProjectPath(path) => {let path = path.to_string_lossy();@@ -11149,6 +11194,51 @@ mod content_view_output_tests {}}+/// How long the Live Overview must stay closed before its card previews+/// are released. Long enough that flipping the overview open and closed+/// while working never pays the rebuild; matches the idle image release.+const PREVIEW_CACHE_RELEASE_SECS: u64 = 5 * 60;++fn preview_cache_release_due(idle_for: Option<Duration>, showing: bool) -> bool {+ match idle_for {+ Some(elapsed) => !showing && elapsed >= Duration::from_secs(PREVIEW_CACHE_RELEASE_SECS),+ None => false,+ }+}++#[cfg(test)]+mod preview_cache_release_tests {+ use super::{preview_cache_release_due, PREVIEW_CACHE_RELEASE_SECS};+ use std::time::Duration;++ fn past_grace() -> Duration {+ Duration::from_secs(PREVIEW_CACHE_RELEASE_SECS + 1)+ }++ #[test]+ fn an_overview_closed_past_the_grace_period_releases() {+ assert!(preview_cache_release_due(Some(past_grace()), false));+ }++ #[test]+ fn a_showing_or_transitioning_overview_never_releases() {+ assert!(!preview_cache_release_due(Some(past_grace()), true));+ }++ #[test]+ fn the_grace_period_is_respected() {+ assert!(!preview_cache_release_due(+ Some(Duration::from_secs(PREVIEW_CACHE_RELEASE_SECS - 1)),+ false+ ));+ }++ #[test]+ fn nothing_to_release_is_never_due() {+ assert!(!preview_cache_release_due(None, false));+ }+}+/// How long a window must stay fully occluded before its lazily-rebuilt/// caches are released. Long enough to survive a glance at another Space/// or a brief cover-up; matches the sidebar's idle-release precedent.diff --git a/wezterm-gui/src/termwindow/render/paint.rs b/wezterm-gui/src/termwindow/render/paint.rsindex a79a55bd..4f6143c8 100644--- a/wezterm-gui/src/termwindow/render/paint.rs+++ b/wezterm-gui/src/termwindow/render/paint.rs@@ -179,6 +179,38 @@ pub(crate) struct CachedPreviewQuads {texture: Option<Rc<crate::termwindow::webgpu::CardRenderTexture>>,}+/// What the card preview caches hold, for accounting.+#[derive(Debug, Default, Clone, Copy)]+pub(crate) struct PreviewCacheFootprint {+ pub cards: usize,+ /// Resident quad bytes, the rebuild in flight included: it owns the+ /// heap it took from its cache entry, so the map alone under-reads+ /// exactly while one is in flight.+ pub quad_bytes: usize,+ /// GPU bytes of the card textures.+ pub texture_bytes: usize,+}++impl crate::TermWindow {+ pub(crate) fn preview_cache_footprint(&self) -> PreviewCacheFootprint {+ let cards = self.preview_quad_cache.borrow();+ let partial = self.preview_rebuild_partial.borrow();+ PreviewCacheFootprint {+ cards: cards.len(),+ quad_bytes: cards+ .values()+ .map(|entry| entry.heap.resident_bytes())+ .chain(partial.as_ref().map(|partial| partial.heap.resident_bytes()))+ .sum(),+ texture_bytes: cards+ .values()+ .filter_map(|entry| entry.texture.as_ref())+ .map(|texture| texture.width as usize * texture.height as usize * 4)+ .sum(),+ }+ }+}+/// A card rebuild in flight, sliced across frames.////// A single slot rather than a map: the per-frame rebuild budget is one card,@@ -922,23 +954,10 @@ impl crate::TermWindow {// quad population nothing else here can see. Capacity only, like// every other figure in this block.{- let cards = self.preview_quad_cache.borrow();- let partial = self.preview_rebuild_partial.borrow();- let card_bytes: usize = cards- .values()- .map(|entry| entry.heap.resident_bytes())- .sum();- // The rebuild owns the heap it took from its cache entry, so- // summing the map alone under-reads exactly while one is in- // flight.- let partial_bytes = partial- .as_ref()- .map_or(0, |partial| partial.heap.resident_bytes());- crate::perf::log_counter("preview_quad_cache_cards", cards.len());- crate::perf::log_counter(- "preview_quad_cache_bytes",- card_bytes.saturating_add(partial_bytes),- );+ let footprint = self.preview_cache_footprint();+ crate::perf::log_counter("preview_quad_cache_cards", footprint.cards);+ crate::perf::log_counter("preview_quad_cache_bytes", footprint.quad_bytes);+ crate::perf::log_counter("preview_texture_bytes", footprint.texture_bytes);}crate::perf::log_counter("content_view_last_frame_bytes",@@ -1862,6 +1881,7 @@ impl crate::TermWindow {// about a closed overview says the cards are gone, and a stale entry// costs one key comparison to reject.if !previews.is_empty() {+ self.preview_cache_last_wanted = Some(Instant::now());let live: HashSet<TabId> = previews.iter().map(|preview| preview.tab_id).collect();self.preview_quad_cache.borrow_mut()