Closed ceski-1 closed 3 weeks ago
Good cleanup, thank you. I'm curious, does it improve input latency/performance for you?
I didn't measure any difference with benchmark tools, but calling SDL_PumpEvents()
once then SDL_PeepEvents()
in batches until the queue is empty is faster than SDL_PollEvent()
which constantly calls SDL_PumpEvents()
and SDL_PeepEvents()
(one by one). It seems more important for gamepads.
Here's 1000 iterations of each approach on an old laptop (i5-2520M):
SDL_PollEvent() SDL_PeepEvents()
1.803 ms 0.034 ms
1.851 ms 0.034 ms
2.320 ms 0.034 ms
1.822 ms 0.034 ms
1.767 ms 0.034 ms
1.978 ms 0.041 ms
1.844 ms 0.034 ms
1.794 ms 0.050 ms
1.786 ms 0.034 ms
3.950 ms 0.043 ms
I_OpenController: Found a valid game controller, named: Xbox One S Controller
16.940 ms 0.057 ms
15.411 ms 0.055 ms
14.261 ms 0.041 ms
11.128 ms 0.041 ms
12.866 ms 0.058 ms
9.189 ms 0.042 ms
10.073 ms 0.041 ms
11.766 ms 0.041 ms
9.862 ms 0.042 ms
9.909 ms 0.042 ms
35.929 ms 0.039 ms
9.244 ms 0.038 ms
9.586 ms 0.056 ms
So, it's definitely faster, but not really noticeable in practice.
35.929 ms 0.039 ms
Wow, I think it's possible to notice such a difference! That's a nice improvement.
That's 1000 iterations though. In practice, I've never seen more than 8 events at a time (~60 before this PR, due to gamepad). Anyway, all of this will have to be reevaluated for SDL3 since it has added raw input for keyboards (there are 1kHz gamer keyboards now...) and mouse input handling was improved, which runs on a separate thread now.
Some small changes I made while reviewing the input code. SDL events are now grabbed in batches, up to 32 at a time, instead of one by one. Also, gamepads don't spam as many events.