From 0e568ea161b292d2878b0381646cc1adfd67127a Mon Sep 17 00:00:00 2001 From: Wez Furlong Date: Fri, 27 Dec 2019 08:48:00 -0800 Subject: [PATCH] wayland: reduce CPU utilization by correctly handling Refresh On a Fedora 31 system running Wayland I noticed that wezterm and the compositor were running pretty hot on their respective CPU cores. It turned out that we had a lot of [Refresh](https://docs.rs/smithay-client-toolkit/0.6.4/smithay_client_toolkit/window/enum.Event.html#variant.Refresh) events being generated and consumed. We were treating this as needing a full paint so we'd be effectively continually running the opengl paint cycle over and over. The docs for that event say that it is intended to refresh the client decorations so let's focus it towards that instead. This does bring the CPU usage back down to intended levels. I believe this hot CPU usage to be compositor-dependent: this is the first I've seen of it out of 4 different Wayland environments! --- window/src/os/wayland/window.rs | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/window/src/os/wayland/window.rs b/window/src/os/wayland/window.rs index b6d40cec8..f36f78717 100644 --- a/window/src/os/wayland/window.rs +++ b/window/src/os/wayland/window.rs @@ -106,7 +106,7 @@ pub struct WaylandWindowInner { #[derive(Default, Clone, Debug)] struct PendingEvent { close: bool, - refresh: bool, + refresh_decorations: bool, configure: Option<(u32, u32)>, dpi: Option, } @@ -123,8 +123,8 @@ impl PendingEvent { } } Event::Refresh => { - if !self.refresh { - self.refresh = true; + if !self.refresh_decorations { + self.refresh_decorations = true; true } else { false @@ -136,8 +136,8 @@ impl PendingEvent { changed = self.configure.is_none(); self.configure.replace(new_size); } else { - changed = !self.refresh; - self.refresh = true; + changed = !self.refresh_decorations; + self.refresh_decorations = true; } changed } @@ -469,11 +469,11 @@ impl WaylandWindowInner { } self.refresh_frame(); - pending.refresh = true; + self.do_paint().unwrap(); } } - if pending.refresh && self.window.is_some() { - self.do_paint().unwrap(); + if pending.refresh_decorations && self.window.is_some() { + self.refresh_frame(); } }