Throttle WM_MOUSEMOVE messages to avoid being overwhelmed by them with high-frequency mice#3
Open
filipppavlov wants to merge 1 commit into
Open
Throttle WM_MOUSEMOVE messages to avoid being overwhelmed by them with high-frequency mice#3filipppavlov wants to merge 1 commit into
filipppavlov wants to merge 1 commit into
Conversation
…h high-frequency mice. Stop Windows event processing if there are no other messages in the queue aside from mouse moves
ccptoebeans
reviewed
Jul 7, 2026
| // Stop processing messages if only mouse move messages are left in the queue | ||
| if( !GetQueueStatus( QS_ALLINPUT & ~QS_MOUSEMOVE ) ) | ||
| { | ||
| break; |
Member
There was a problem hiding this comment.
I may be missunderstanding the processing of windows events here, but messages are being removed by PeekMessageW being called with PM_REMOVE here. If we simply stop processing mouse events, is this not a memory leak?
Contributor
Author
There was a problem hiding this comment.
No. The message will stay in the queue until we get to process it on the next frame.
ccptoebeans
approved these changes
Jul 7, 2026
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.
When the client processes Windows messages it tries to process all of them until the message queue is empty.
When the player is using high-frequency polling mouse, it is possible that new mouse move message will be generated while the client processes the previous mouse move message, and this can happen repeatedly. As a result, the framerate in the client noticeably drops when a player is moving the mouse.
Normally, Windows will coallesce mouse move messages, so that there are no subsequent WM_MOUSEMOVE messages in the queue. The slowdown issue only appears when the client removes the mouse move message, and processes it, and in the meantime the new one arrives.
This change is a safest workaround for the situation I found. If the client has just processed a mouse move message, and there are no other messages in the queue aside from a new mouse move message, stop event processing for the frame. The leftover mouse move message will be processed on the next frame.
This way the client still processes any other messages that come in during the previous frame or generated while processing other messages in this iteration, only postponing the last mouse move message.