perf: fix WaitUntil being bypassed by request_redraw in AboutToWait

Calling request_redraw() inside AboutToWait immediately woke the event
loop on every iteration, making WaitUntil a no-op and producing a
busy-loop (98% CPU). Move request_redraw to NewEvents(ResumeTimeReached)
so the thread actually sleeps between frames.
This commit is contained in:
kilyabin
2026-06-18 02:33:23 +04:00
parent 4b30a1d260
commit 0c5a6d565c
+7 -2
View File
@@ -4,7 +4,7 @@ use std::time::{Duration, Instant};
use anyhow::Result;
use winit::{
event::{ElementState, Event, KeyEvent, WindowEvent},
event::{ElementState, Event, KeyEvent, StartCause, WindowEvent},
event_loop::{ControlFlow, EventLoop},
keyboard::{KeyCode, PhysicalKey},
window::{Fullscreen, WindowBuilder},
@@ -139,9 +139,14 @@ pub fn run(config: Config, monitor_idx: usize) -> Result<()> {
}
}
// Timer expired or first run — schedule a redraw
Event::NewEvents(StartCause::ResumeTimeReached { .. } | StartCause::Init) => {
window.request_redraw();
}
// All events processed — sleep until next frame
Event::AboutToWait => {
elwt.set_control_flow(ControlFlow::WaitUntil(Instant::now() + frame_time));
window.request_redraw();
}
_ => {}