Skip GPUI's paint while the window is minimised (#32)
CI / core (push) Successful in 1m37s

GPUI's vsync thread invalidates the window at every vsync, minimised too,
and each WM_PAINT went through GPUI, which has no frame to draw then, and
DefWindowProc: the UI thread spent more minimised than visible (budget 3).
A subclass validates the paint while the window is iconic. On the manual
checks machine (240 Hz), minimised: 3.03 % of one core before, 0.22 %
after; the window draws again on restore.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_0192He3DgZBggc9wJG9c1nqA
This commit is contained in:
nessarandClaude Opus 5.5 committed 2026-11-23 10:17:10 +01:00
1 parent 6311f01b49
commit f53db09d3e
4 files changed
+48 -1

No files matched your search

+1
View File
@@ -17,6 +17,7 @@ image = { version = "0.25.10", default-features = false, features = ["jpeg"] }
[target.'cfg(windows)'.dependencies]
raw-window-handle = "0.6"
windows = { version = "0.62", features = [
"Win32_Graphics_Gdi",
"Win32_Security",
"Win32_System_LibraryLoader",
"Win32_System_Registry",
+2
View File
@@ -8,6 +8,7 @@ mod card_lift;
mod card_order;
mod champion_table;
mod logon;
mod minimized;
mod motion;
mod page;
#[cfg(feature = "profile")]
@@ -342,6 +343,7 @@ fn main() {
gpui_kit::open_window(options, cx, |window, cx| {
single_instance::accept_relaunches(window);
motion::follow_windows_setting(window, cx);
minimized::skip_paint_while_minimized(window);
// The settings form installs the tray that hides the window.
let root = cx.new(|cx| RootView::new(setup, at_logon, window, cx));
if at_logon {
+44
View File
@@ -0,0 +1,44 @@
//! A minimised window draws nothing, yet GPUI's vsync thread invalidates it at each vsync, and
//! each WM_PAINT went through GPUI, which has no frame to draw while minimised, then
//! DefWindowProc: the UI thread spent more minimised than visible (budget 3,
//! `docs/performance.md`). The paint is validated here instead, before GPUI sees it.
use gpui_kit::Window;
use windows::Win32::Foundation::{HWND, LPARAM, LRESULT, WPARAM};
use windows::Win32::Graphics::Gdi::ValidateRect;
use windows::Win32::UI::Shell::{DefSubclassProc, RemoveWindowSubclass, SetWindowSubclass};
use windows::Win32::UI::WindowsAndMessaging::{IsIconic, WM_NCDESTROY, WM_PAINT};
use crate::tray::window_hwnd;
/// Subclass ids are per procedure.
const MINIMIZED_SUBCLASS: usize = 0;
pub(crate) fn skip_paint_while_minimized(window: &Window) {
if let Some(hwnd) = window_hwnd(window) {
// Without the subclass, GPUI handles these paints as before.
let _ = unsafe { SetWindowSubclass(hwnd, Some(paint_proc), MINIMIZED_SUBCLASS, 0) };
}
}
unsafe extern "system" fn paint_proc(
hwnd: HWND,
message: u32,
wparam: WPARAM,
lparam: LPARAM,
_id: usize,
_data: usize,
) -> LRESULT {
match message {
// GPUI gives its frame callback back at the restore's WM_SIZE, and draws then.
WM_PAINT if unsafe { IsIconic(hwnd) }.as_bool() => {
let _ = unsafe { ValidateRect(Some(hwnd), None) };
return LRESULT(0);
}
WM_NCDESTROY => {
let _ = unsafe { RemoveWindowSubclass(hwnd, Some(paint_proc), MINIMIZED_SUBCLASS) };
}
_ => {}
}
unsafe { DefSubclassProc(hwnd, message, wparam, lparam) }
}