High CPU usage in empty application regardless of control flow
Hi, I'm getting ~30% CPU usage (as reported by Task Manager) for an empty application in release mode on Windows 10. The code is just the "event loop" example from the crate documentation; it doesn't matter which ControlFlow I use. I'm not moving the mouse or interacting with the window in any way.
Same on Debian 12 XFCE
I am seeing 100 % CPU usage on macOS and when running in the browser using winit 0.30.8.
I assume this is the same example mentioned above, but I will paste what I used here for reference:
use winit::application::ApplicationHandler;
use winit::event::WindowEvent;
use winit::event_loop::{ActiveEventLoop, ControlFlow, EventLoop};
use winit::window::{Window, WindowId};
#[derive(Default)]
struct App {
window: Option<Window>,
}
impl ApplicationHandler for App {
fn resumed(&mut self, event_loop: &ActiveEventLoop) {
self.window = Some(event_loop.create_window(Window::default_attributes()).unwrap());
}
fn window_event(&mut self, event_loop: &ActiveEventLoop, id: WindowId, event: WindowEvent) {
match event {
WindowEvent::CloseRequested => {
println!("The close button was pressed; stopping");
event_loop.exit();
},
WindowEvent::RedrawRequested => {
self.window.as_ref().unwrap().request_redraw();
}
_ => (),
}
}
}
fn main() {
let event_loop = EventLoop::new().unwrap();
// both ControlFlow options result in 100 %
// event_loop.set_control_flow(ControlFlow::Poll);
event_loop.set_control_flow(ControlFlow::Wait);
let mut app = App::default();
event_loop.run_app(&mut app);
}
On macOS It runs at 100 % CPU usage even when commenting out the call to request_redraw() and with either ControlFlow::Poll and ControlFlow::Wait.
Edit: On web, it runs with low CPU usage with ControlFlow::Wait or by switching to PollStrategy::IdleCallback.
I stumbled upon the issue when noticing the high CPU usage in the browser in a new project. I compared it to a different project that I have and does not show such high CPU usage. The other project uses winit 0.26, so I suspect there has been a regression in performance between the two versions.
I am seeing 100 % CPU usage on macOS and when running in the browser using winit 0.30.8.
Please open a new issue, that's for a different platform (and none of them share implementation details).
FWIW, I get the same behavior running examples/application.rs when continuous redraw is toggled on (with Shift+R), even though redraws only seem to be requested at 56 Hz (my display runs at 75 Hz).
Edit: I guess in that case the low frame rate is a consequence of slow software pixel-pushing, and in cases where the pixel-pushing is faster or removed it becomes an issue of unlimited frame rate.