Skip to content

Throttle WM_MOUSEMOVE messages to avoid being overwhelmed by them with high-frequency mice#3

Open
filipppavlov wants to merge 1 commit into
mainfrom
PLAT-11600-throttle-mouse-move
Open

Throttle WM_MOUSEMOVE messages to avoid being overwhelmed by them with high-frequency mice#3
filipppavlov wants to merge 1 commit into
mainfrom
PLAT-11600-throttle-mouse-move

Conversation

@filipppavlov

Copy link
Copy Markdown
Contributor

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.

…h high-frequency mice.

Stop Windows event processing if there are no other messages in the queue aside from mouse moves
Comment thread src/BlueOS.cpp
// Stop processing messages if only mouse move messages are left in the queue
if( !GetQueueStatus( QS_ALLINPUT & ~QS_MOUSEMOVE ) )
{
break;

@ccptoebeans ccptoebeans Jul 7, 2026

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No. The message will stay in the queue until we get to process it on the next frame.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants