[Gambas-user] sdl Draw event overhead is killing frame rate

Benoît Minisini gambas at ...1...
Wed Jan 15 04:19:42 CET 2014


Le 15/01/2014 03:33, Kevin Fishburne a écrit :
> I noticed a month or two ago that the frame rate on the server side of
> my game went from around 300 to 50. I assumed it was an OpenGL driver
> issue or that I'd added some really inefficient code. It appears this is
> not the case, but rather it seems the Draw event raised by opening a
> screen using SDL is executing some heavy (and hopefully unnecessary)
> lifting that it wasn't previously.
>
> I've attached a project which is essentially an empty SDL screen draw
> event loop that calculates a frame rate once per second and outputs the
> results to the console. Any idea what's going on here? Any empty loop on
> my reasonably modern PC and brand new video card running the binary
> NVIDIA drivers should be producing frame rates in the thousands, at least.
>

You must know that the event loop of the SDL library cannot be shared, 
so you get instead a busy waiting loop that repeatedly checks SDL events 
and calls one loop of the Gambas event loop with a 10 ms timeout.

Each time that loop is run, the "Draw" event is raised. Unless you call 
"Stop Event" during the Draw event handler, gb.sdl assumes that 
something has be drawn, and so refreshes the window.

Refreshing a window takes a lot of CPU, depending on its size and what 
your window manager is.

If the window is refreshed, your framerate may be limited by the GPU 
(through the monitor vsync, which is emultated now on LCD monitors), 
check that.

If you call Stop Event, the Draw event will be called again and again 
without refreshing, and so the CPU will be spent most of the time there. 
Note that a small CPU time is given back to the OS then, so that not 
100% of the CPU is used.

Just check the CPU usage and the framerate in the different cases (small 
window, big window, with a 3D window manager, without...), and report!

-- 
Benoît Minisini




More information about the User mailing list