Ive been programming an emulator as a side project and am at a point now where I am tackling efficiency. Ive managed to get rid of all the slow things that I was doing like lots of SDL_RenderDrawPoint's, but now I'm stuck.
Ive managed to narrow it down to SDL_PollEvent. Ive simplified my main loop and event loop so that they look similar to a simple SDL tutorial. When I comment out the event loop, the emulator runs super fast. Ive also used the visual studio performance profiler to check, and sure enough, SDL_PollEvent is taking up ~94% of the cpu time.

The place where my emulator does all its stuff is in ppuNptr->cycle() which is taking up only 1.48% .
Unfortunately I can't replicate this in another project so I'm at a loss.
Is there something that I should be doing before polling for events?
How else could I debug this?
Currently im on windows 10 with visual studio 2019 and sdl 2.0.10 .
I too ran across this when profiling my emulator. The answer for me was to downgrade the version of SDL2 to 2.0.8.
I was running SDL2 version 2.0.12 and I took keltar's suggestion in the comments, and downgraded to 2.0.8 and I was no longer having the issue with the SDL_PollEvent causing slow performance. This fixed the issue for me as I no longer having low FPS issues with my emulator.
I will see if this issue has been reported in the bug ticketing system and report it if not to the SDL2 as this issue starts occurring from version 2.0.9.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With