fix(win32): game-loop pacing so the event loop isn't starved#79
Open
KoalaHao wants to merge 1 commit into
Open
fix(win32): game-loop pacing so the event loop isn't starved#79KoalaHao wants to merge 1 commit into
KoalaHao wants to merge 1 commit into
Conversation
ReadConsoleInputW is a blocking native call. In the old code, the Dart event loop had no chance to run between input events, so periodic redraws (cursor blink, animations, status ticks) never fired. The framework appeared frozen on Windows until an event arrived. Switched to game-loop pacing: capture a 16ms deadline at the start of each pass, drain the console queue, then sleep only for the remaining time. A slow pass (big redraw, burst of events) skips the sleep entirely and runs the next pass immediately, so we never double-charge a 16ms wait on top of work and the input loop stays responsive regardless of workload. GetNumberOfConsoleInputEvents is a non-blocking peek, used to size the drain loop. Subsequent ReadConsoleInputW calls return immediately when events are pending, so the isolate is never blocked waiting for input. The drain loop also means a burst of events (fast typing, fast mouse) is processed in a single tick instead of throttled to one record per poll. 16ms ~= 60Hz, matching the Linux path's responsiveness. Idle CPU is ~0% because Future.delayed is timer-backed, not busy-polled.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
ReadConsoleInputW is a blocking native call. In the old code, the Dart event loop had no chance to run between input events, so periodic redraws (cursor blink, animations, status ticks) never fired. The framework appeared frozen on Windows until an event arrived.
Switched to game-loop pacing: capture a 16ms deadline at the start of each pass, drain the console queue, then sleep only for the remaining time. A slow pass (big redraw, burst of events) skips the sleep entirely and runs the next pass immediately, so we never double-charge a 16ms wait on top of work and the input loop stays responsive regardless of workload.
GetNumberOfConsoleInputEvents is a non-blocking peek, used to size the drain loop. Subsequent ReadConsoleInputW calls return immediately when events are pending, so the isolate is never blocked waiting for input. The drain loop also means a burst of events (fast typing, fast mouse) is processed in a single tick instead of throttled to one record per poll.
16ms ~= 60Hz, matching the Linux path's responsiveness. Idle CPU is ~0% because Future.delayed is timer-backed, not busy-polled.