From 226ec9d4041e587e99eede79d13954b0bd095fd1 Mon Sep 17 00:00:00 2001 From: Piotr Osiewicz <24362066+osiewicz@users.noreply.github.com> Date: Tue, 27 Aug 2024 12:23:00 +0200 Subject: [PATCH] gpui: Fix performance of app menu opening with large # of windows (#16939) This is officially my weirdest performance fix to date; With large # of windows opening app menu could take a lot of time (we're talking few seconds with 9 windows, a minute with 10 windows). The fix is to make one method pub(crate).. What? image We were spending most of the time on clear_pending_keystrokes, which - funnily enough - called itself recursively. It turned out we have two methods; `AppContext::clear_pending_keystrokes` and WindowContext::clear_pending_keystrokes. The former calls the latter, but - due to the fact that `WindowContext::clear_pending_keystrokes` is private and `WindowContext` derefs to `AppContext` - `AppContext` one ended up actually calling itself! The fix is plain and simple - marking WindowContext one as pub(crate), so that it gets picked up as a method to call over `AppContext::clear_pending_keystrokes`. Closes #16895 Release Notes: - Fixed app menu performance slowdowns when there are multiple windows open. --- crates/gpui/src/window.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/crates/gpui/src/window.rs b/crates/gpui/src/window.rs index 7aae3708d1..877e4654f4 100644 --- a/crates/gpui/src/window.rs +++ b/crates/gpui/src/window.rs @@ -3389,7 +3389,7 @@ impl<'a> WindowContext<'a> { self.window.pending_input.is_some() } - fn clear_pending_keystrokes(&mut self) { + pub(crate) fn clear_pending_keystrokes(&mut self) { self.window.pending_input.take(); }