Skip to content

armgit / zed

Public Imported from GitHub
0

Code at the speed of thought – Zed is a high-performance, multiplayer code editor from the creators of Atom and Tree-sitter.

gpui(windows): Prioritize system messages when exceeding main thread task budget (#43682)

Lukas Wirth64633bade4ca
diff --git a/crates/gpui/src/platform/windows/platform.rs b/crates/gpui/src/platform/windows/platform.rs
index 548b08eca8f..14b9511581a 100644
--- a/crates/gpui/src/platform/windows/platform.rs
+++ b/crates/gpui/src/platform/windows/platform.rs
@@ -819,17 +819,16 @@ impl WindowsPlatformInner {
loop {
loop {
if start.elapsed().as_millis() >= MAIN_TASK_TIMEOUT {
- // requeue main thread dispatch and bail, allowing more system messages to be processed
- unsafe {
- PostMessageW(
- Some(self.dispatcher.platform_window_handle.as_raw()),
- WM_GPUI_TASK_DISPATCHED_ON_MAIN_THREAD,
- WPARAM(self.validation_number),
- LPARAM(0),
- )
- .log_err();
+ // we spent our budget on gpui tasks, we likely have a lot of work queued so drain system events first
+ // before returning to main thread task work
+ let mut msg = MSG::default();
+ let peek_msg_type = PM_REMOVE | PM_QS_INPUT | PM_QS_PAINT;
+ while unsafe { PeekMessageW(&mut msg, None, 0, 0, peek_msg_type) }.as_bool() {
+ if translate_accelerator(&msg).is_none() {
+ _ = unsafe { TranslateMessage(&msg) };
+ unsafe { DispatchMessageW(&msg) };
+ }
}
- return Some(0);
}
match self.main_receiver.try_recv() {
Err(_) => break,