Monogame Version: 22.214.171.1240 (09th February 2018)
OS: Windows 7 x64
Today I noticed that for some reason the sprite movement on screen seems to be stuttering for a few seconds every now and then. It feels like the framerate suddenly drops to about half the normal rate for no obvious reason.
A rock solid 60fps all the time, no drops or stuttering. Measured with Fraps and Intel GPA.
–> Not a framerate but a frame pacing problem?
Garbage collection blocking the cpu:
I added a GC.Collect() call to the Update() function.
–> No change at all.
Tested on another system (Windows 10 x64):
Issue is gone!
–> Maybe a Windows 7 related problem?
Frame stuttering gets triggered if I move the mouse cursor around at the minimize, maximize, close buttons.
Or if the game runs at fullscreened window mode. At true fullscreen mode it’s gone.
Measure frame times:
Update Function takes about 0.9-1.2ms per frame at 1% cpu load.
Drawing takes about 0.2ms per frame at 6% gpu load.
–> So I’m quite sure its not a performance related issue.
So I measured the time between the end of Draw() and the next Update() it’s about 15-16ms.
Obviously to wait for the next 60fps refresch tick.
But as soon as the stuttering kicks in the wait time strarts to alternate betwenn 30 and 0ms…
A few seconds later everything is back to normal 15-16ms times.
–> Two frames get rendered right after another, becaus monogame is running slow?
–> Windows window refresch and game drawing runs out of sync?
–> Monogame is waiting for windows to update the window content?
–> Maybe vsync?
So I tried to disable Vsync and setup a target frame time myself:
graphics.SynchronizeWithVerticalRetrace = false; TargetElapsedTime = TimeSpan.FromMilliseconds(1000d / 60d); IsFixedTimeStep = true;
The stuttering issues persists! But the wait time alternating between 30ms and 0ms is gone. It now stays at normal 15-16ms.
–> Monogame pushes the rendered screen to Windows but does not wait for it to complete?
Frame gets stuck at Windows updating the window?
–> If I setup a target framerate of 100fps, the stuttering gets less noticable.
Most likely becaus the actual framerate gets halfed if the stuttering kicks in? 100/50fps.
I’m out of ideas. Is it a windows issues, or is it on my side? I don’t know. Last resort might be to include the monogame source into my project and step into everything that happens between Draw() and Update() to track down the culprit.
Or hopefully someone else knows what is going on. So far thank you for reading.