We are currently migrating Bugzilla to GitHub issues.
Any changes made to the bug tracker now will be lost, so please do not post new bugs or make changes to them.
When we're done, all bug URLs will redirect to their equivalent location on the new bug tracker.

Bug 4897 - SDL_PollEvent performance decreased in 2.0.10 compared to 2.0.8
Summary: SDL_PollEvent performance decreased in 2.0.10 compared to 2.0.8
Status: RESOLVED FIXED
Alias: None
Product: SDL
Classification: Unclassified
Component: events (show other bugs)
Version: 2.0.10
Hardware: x86_64 Windows (All)
: P2 blocker
Assignee: Sam Lantinga
QA Contact: Sam Lantinga
URL:
Keywords: target-2.0.12
Depends on:
Blocks:
 
Reported: 2019-12-13 22:40 UTC by Dennis Felsing
Modified: 2020-03-01 20:25 UTC (History)
4 users (show)

See Also:


Attachments
Visual Studio debugging output, left side SDL 2.0.8, right side SDL 2.0.10 (204.52 KB, image/png)
2020-02-12 12:57 UTC, Dennis Felsing
Details

Note You need to log in before you can comment on or make changes to this bug.
Description Dennis Felsing 2019-12-13 22:40:47 UTC
Hi,

SDL_PollEvent seems to be having worse performance on Windows (confirmed in Win10 and Wine), causing lower fps in SDL version 2.0.10 compared to 2.0.8. To confirm this I simply replaced the SDL2.dll in https://ddnet.tw/downloads/DDNet-12.7.3-win64.zip with the one from SDL 2.0.8.

This has been in reported in https://github.com/ddnet/ddnet/issues/1997 and I could confirm it. For now we will downgrade to 2.0.8 (again) because of this issue.

I have tried setting

	SDL_EventState(SDL_JOYAXISMOTION, SDL_IGNORE);
	SDL_EventState(SDL_SENSORUPDATE, SDL_IGNORE);

but that had no affect.

I see in the code in events/SDL_events.c that event logging is now handled at runtime by SDL_DoEventLogging instead of with #ifdef SDL_DEBUG_EVENTS, which might explain the overhead.

Best regards
Dennis
Comment 1 Sylvain 2019-12-18 06:29:15 UTC
Hello, 
Maybe you could re-compile latest version and see if this is really the case ? The logging seems only checking one variable, which should be fair, provided logging isn't actually enabled.
Comment 2 Cameron Gutman 2019-12-22 21:59:54 UTC
It looks like you don't have PDBs for the SDL builds you're using, which is probably why you aren't having much luck with the VS profiler. If you build SDL yourself using the VS projects, you should get the PDBs you need to make the profiler output useful data for functions inside SDL2.dll.

It's not surprising that SDL_WaitEventTimeout() is showing up hot in the profiles. It internally calls SDL_PumpEvents() which triggers basically all of the logic used to generate SDL_Events (processing OS window messages, polling for new input on input devices, polling for newly attached or detached joysticks, etc.)
Comment 3 Sam Lantinga 2020-02-09 21:58:18 UTC
Do you have a way of showing FPS?

Also, there was a known issue in 2.0.10 release, does it work better if you try a newer DLL?
http://www.libsdl.org/tmp/SDL-win64.zip
Comment 4 Dennis Felsing 2020-02-10 07:17:23 UTC
(In reply to Cameron Gutman from comment #2)
> It looks like you don't have PDBs for the SDL builds you're using, which is
> probably why you aren't having much luck with the VS profiler. If you build
> SDL yourself using the VS projects, you should get the PDBs you need to make
> the profiler output useful data for functions inside SDL2.dll.

Unfortunately I don't have Windows/VS in order to build myself. But thanks for the explanation.

(In reply to Sam Lantinga from comment #3)
> Do you have a way of showing FPS?

F1, cl_show_fps 1

(In reply to Sam Lantinga from comment #3)
> Also, there was a known issue in 2.0.10 release, does it work better if you
> try a newer DLL?
> http://www.libsdl.org/tmp/SDL-win64.zip

I will give this a try later today, thanks for the hint.
Comment 5 Dennis Felsing 2020-02-10 17:12:18 UTC
(In reply to Dennis Felsing from comment #4)
> (In reply to Sam Lantinga from comment #3)
> > Also, there was a known issue in 2.0.10 release, does it work better if you
> > try a newer DLL?
> > http://www.libsdl.org/tmp/SDL-win64.zip
> 
> I will give this a try later today, thanks for the hint.

Unfortunately no difference.
Comment 6 Sam Lantinga 2020-02-11 15:47:35 UTC
I'm not able to reproduce this. I get 790-800 FPS with 2.0.8, 2.0.10, and 2.0.11 DLLs.
Comment 7 Sam Lantinga 2020-02-11 17:47:13 UTC
Can whoever is doing the profiling download the latest SDL code and build it themselves with Visual Studio so you can get more detailed profiling information?
http://www.libsdl.org/tmp/SDL-2.0.zip

Thanks!
Comment 8 Dom 2020-02-11 19:36:19 UTC
Since this was relevant to me I just tested it on the SDL implementation of imgui and also cannot see any performance regression between SDL 2.0.8 and SDL 2.0.10 when compiled as release build with MSVC on Win10. I had no periphericals other than a wireless USB mouse connected to my laptop.
Comment 9 Konrad 2020-02-12 12:21:46 UTC
No issues here either. I'm reaching 3500 fps in my game resulting in about 285 us per frame during which SDL_PollEvent is called.
Comment 10 Dennis Felsing 2020-02-12 12:57:03 UTC
Created attachment 4208 [details]
Visual Studio debugging output, left side SDL 2.0.8, right side SDL 2.0.10
Comment 11 Sam Lantinga 2020-02-12 20:17:38 UTC
That's perfect, thank you!

I believe this was just fixed in the latest snapshot:
http://www.libsdl.org/tmp/SDL-2.0.zip
Comment 12 Konrad 2020-02-12 23:00:35 UTC
Under what circumstances this could be replicated? I've been using SDL2 in a highly responsive application (game) and I had no reports of such issue.
Comment 13 Sam Lantinga 2020-02-13 17:51:38 UTC
This would happen if you have the mouse grabbed or in relative mode.
Comment 14 Sam Lantinga 2020-03-01 20:25:19 UTC
Tested, verified fixed.