Move SDL joystick scanning off the main thread#7491
Merged
Conversation
Setting SDL_HINT_JOYSTICK_THREAD=1 before SDL_InitSubSystem(SDL_INIT_JOYSTICK) tells SDL2 to run joystick polling and HID device-detection on a dedicated background thread, rather than processing them inline inside SDL_PollEvent on the main thread. Without this hint, every WM_DEVICECHANGE broadcast (which Windows sends when *any* HID device wakes, sleeps, or pulses the USB bus) causes SDL to walk every HID device class via SetupAPI / cfgmgr32 from inside SDL_PollEvent, stalling the frame loop for multiple seconds on machines with many HID peripherals - especially wireless Logitech mice and keyboards that periodically pulse the bus. Diagnosed via ProcMon stack capture on one affected user's machine, with the slow frame's call chain ending in SDL2.dll -> SETUPAPI.dll -> cfgmgr32.dll -> kernel registry queries against HKLM\System\CurrentControlSet\Enum\HID\*. With the hint enabled, that work happens on SDL's own thread and the main thread just dequeues already-collected events.
notimaginative
approved these changes
Jun 1, 2026
notimaginative
left a comment
Contributor
There was a problem hiding this comment.
Should be fine, assuming that it resolves the reported problem. I don't believe there is any real downside with this for us whether it solves the problem or not.
I should note as well that this is the default setting for SDL3.
Contributor
Author
|
Well according to Joe it does not actually solve the problem. It still looks like a good thing to do though. |
wookieejedi
approved these changes
Jun 1, 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.
Setting SDL_HINT_JOYSTICK_THREAD=1 before SDL_InitSubSystem(SDL_INIT_JOYSTICK) tells SDL2 to run joystick polling and HID device-detection on a dedicated background thread, rather than processing them inline inside SDL_PollEvent on the main thread.
Without this hint, every WM_DEVICECHANGE broadcast (which Windows sends when any HID device wakes, sleeps, or pulses the USB bus) causes SDL to walk every HID device class via SetupAPI / cfgmgr32 from inside SDL_PollEvent, stalling the frame loop for multiple seconds on machines with many HID peripherals - especially wireless Logitech mice and keyboards that periodically pulse the bus. Diagnosed via ProcMon stack capture on one affected user's machine, with the slow frame's call chain ending in SDL2.dll -> SETUPAPI.dll -> cfgmgr32.dll -> kernel registry queries against HKLM\System\CurrentControlSet\Enum\HID*.
With the hint enabled, that work happens on SDL's own thread and the main thread just dequeues already-collected events.
In draft pending confirmation via test.