I noticed recently that keydown events were sometimes causing my engine to miss frames. After drilling down a bit, I found that the issue was with the first SDL_PollEvent, and even more specifically SDL_PumpEvents if I call it separately before my poll event loop. For keys that map to a character, I found that SDL_PumpEvents would consistently block for 10 ms. Even worse, if I press two keys simultaneously, it blocks for 20 ms, and up to 77 ms for 10 simultaneous keypresses. Enough to miss 5 entire frames! I didn’t see any such blocking when processing mouse or gamepad events.
This eventually led me to check SDL_IsTextInputActive, which I found to be enabled by default. So, I called SDL_StopTextInput once to disable it and… now keyboard events are processed in a reasonable amount of time. It’ll still block for 2-3 ms if I press 10 keys simultaneously, which seems a bit odd, but at least it’s not enough to drop a frame.
This makes me wonder though: is it a known issue that the TextInput mode can introduce significant latencies into the event polling loop? Also, why is/should the TextInput mode be enabled by default? Is this just a weird quirk with my system?
I’m running OS X 10.11 and, since it might affect the text input mode, I have English, Japanese, and Korean layouts selected in my input sources menu, though all of this was observed with the English layout.