kkc0923's picture

CPU usage is higher than 15% even empty window.

Hi. I'm working on developing 3D application with OpenTK. I have simple problem about performance issue in using GameWindow class.

When I make empty GameWindow class, the application uses CPU over than 15%! my application is modeling tool, so I want to minimize CPU usage when no user interaction. But Idle application consumed 15% of CPU resource.

I checked other design application, like blender or unity3d, they consumed less than 1% CPU usage in idle state. What is difference of that applications and OpenTK GameWindow application? and How to handle this problem?

Thanks.


Comments

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
Frassle's picture

OpenTK's default parameters make it run as fast as it can, if you want different behaviour pass different options (see https://github.com/opentk/opentk/issues/137).

kkc0923's picture

Thanks for reply. But I tested variable framerate parameters, they are not worked for me. (even framerate 1!)

So I will try to change WinForm + GLControl options. It seems to be use a smaller CPU resource than GameWindow in idle state.

Frassle's picture

Did you try adding Thread.Sleep in Update?

winterhell's picture

There is a trick to Thread.Sleep, and that is if your framerate is vsynced (and in general) you dont know how much time to sleep. If your game is simple and can go to 1000 fps when unlocked, or taking 1ms per frame, and you Thread.Sleep(1), at 60fps vsync you'd have still have 16.6-(1+1)=14.6ms fake-idle, or 88% of a single core went to waste. On the other hand you can oversleep partly the next frame.

Is there a way that does not involve manually timing each frame and then having variable Sleep at the end?

kkc0923's picture

Thanks for reply guys.

I tested GameWindow.Run with no parameters and Thread.Sleep in every frame if elapsed time is smaller than 1 / 60 second. Then, It looks works successfully :) App uses less than 1% of CPU in idle.

But I found something strange result. If I use Threasd.Sleep with sleep timing for about 200 fps, it used CPU 1% even GameWindow.Run with 60 fps option used 15% CPU!

------------------------------------------
GameWindow.Run(60) : 60 fps, about 16% cpu usage in idle.
GameWindow.Run() + custom Thread.Sleep in OnUpdateFrame() : about 200 fps, about 1% cpu usage in idle.
------------------------------------------

Why GameWindow.Run with fixed framerate parameters consume more CPU resource than manual Thread.Sleep method which has even much more FPS?

Actually, my application is not a game, but 3D design software. Ultimate goal is developing 3D modeling soft like blender. Blender used OpenGL internally to draw every drawable object (UI, scene, and so on).

Solution of using Thread.Sleep is best choice in this case?

Thanks.

the Fiddler's picture

GameWindow.Run(60) does not call sleep on its own, but rather spins the CPU. This achieves extremely accurate timing (sub-millisecond), but wastes a lot of CPU time. The solution is to call Thread.Sleep(...) inside the RenderFrame event, after SwapBuffers.

Note that GameWindow.Run(60) only controls the UpdateFrame rate. To control the RenderFrame rate, you can set VSync = VSyncMode.On and/or call Thread.Sleep(...).

GameWindow is optimized for games that perform redraw the window every frame. It can certainly be used for UIs, such as a 3d modeler, but it is missing some UI-centric functionality such as clipboard access (planned for a future version) or event-based redrawing (easy to add, provided there is enough interest). On the upside, GameWindow is extremely cross-platform, so your UI would run pretty much everywhere out of the box - much more so than going for System.Windows.Forms or something similar.