Skip to content

Backends: Win32: Optimized the Gamepad input processing part#8556

Closed
MidTerm-CN wants to merge 1 commit intoocornut:masterfrom
MidTerm-CN:CONTRIBUTING
Closed

Backends: Win32: Optimized the Gamepad input processing part#8556
MidTerm-CN wants to merge 1 commit intoocornut:masterfrom
MidTerm-CN:CONTRIBUTING

Conversation

@MidTerm-CN
Copy link

According to the official documentation of Xinput, I found that there is code that can be optimized and done.

The point of the optimization is that there is no need to add events when there is no Gamepad input, and the new code does not add events for unupdated data

Document: https://learn.microsoft.com/en-us/windows/win32/api/XInput/ns-xinput-xinput_state

@ocornut
Copy link
Owner

ocornut commented Apr 7, 2025

Hello,

Thanks for the PR. I am not sure this would be meaningful optimization given the added complexity. Did you profile the code to measure how much there was to gain? AddInputEvent() already does a backward search for the value.

However the dwPacketNumber compare seems useful and very easy to add.

ocornut added a commit that referenced this pull request Sep 23, 2025
…acket number has not changed. (#8556)

To be honest I don't believe this is valuable as an optimization, but it makes debug stepping a little nicer.
@ocornut
Copy link
Owner

ocornut commented Sep 23, 2025

I have pushed the dwPacketNumber early out with 5f6eaa5. To be honest I don't think it's valuable as an optimization at all but in some rare case of input queue congestion it wouldn't hurt not relying on io.AddKeyAnalogEvent() deduplication, and make debug stepping a little more natural. I'm only adding it because it is +4 lines. Thanks!

@ocornut
Copy link
Owner

ocornut commented Oct 29, 2025

I have reverted this change with 0ba9fed.
It is problematic e.g. when Alt+Tabbing triggers io.AddFocusEvent(event) by default we clear keys with io.ClearInputKeys(), and gamepad data is not properly restored afterwards when holding a button.

@ocornut
Copy link
Owner

ocornut commented Jan 28, 2026

Reimplemented as 960aff2

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants