UPS gets throttled down to FPS

Bugs that are actually features.
evg-zhabotinsky
Inserter
Inserter
Posts: 22
Joined: Wed Dec 09, 2020 3:53 pm
Contact:

UPS gets throttled down to FPS

Post by evg-zhabotinsky »

What am I doing?
Just paying the game with a large enough factory. No mods, pure Vanilla.
To exclude "Your Linux setup sucks" possibility test results are from Windows.
What happens?
The game throttles down UPS to match the FPS it can pump out when graphics can't keep up.
FPS and UPS are pretty much exactly synced in such state.
Update time floats quite a bit below 16 but UPS can drop even below 30 when graphics really lag.

There is more than enough spare CPU time, assuming updates and rendering happen asynchronously and can use separate cores.
Moreover, the problem seems to vanish when I enable show-pollution-values and make graphics lag even more, so it can work properly!

Singleplayer / hosting multiplayer from GUI seems to make no difference.
VSync seems to make no difference.
Render thread count seem to make no or little difference too, I'm probably bottlenecked by GPU.
Cutting down graphics quality partially helps, but not much e.g. on map, and IMHO here 30 FPS at Ultimate is better than 60 FPS at Crappiest.
On my main Linux setup things are even worse. Even with native Steam runtime and fresh if not latest drivers, I usually get max 40 UPS on max zoom in.
Expected behavior:
UPS must be prioritized over FPS, or at least not throttled unnecessarily.
The Factory Must Grow! And as fast as possible. Being able to look at it at highest possible FPS is secondary.
At least let me force the show-pollution-values effect on FPS/UPS without obscuring everything on map and also at close zoom.
Details:
Screenshots are at max graphics settings, with debug options set as required here.

Max zoom in map, note it's pretty much 60 FPS/UPS:
max-zoom-in.png
max-zoom-in.png (3.25 MiB) Viewed 1946 times

Max zoom out map, FPS/UPS is down to 36, update time about the same:
max-zoom-out.png
max-zoom-out.png (1.19 MiB) Viewed 1946 times

Max zoom out map with show-pollution-values, FPS down to 13 but UPS is back at 60:
max-zoom-out-with-pollution.png
max-zoom-out-with-pollution.png (1.15 MiB) Viewed 1946 times

Log:
factorio-current.log
(5.53 KiB) Downloaded 290 times

"Capture performance statistics" result as I slowly zoom out the map and then enable show-pollution-values, just in case:
Save file (External link, >100MB, might get deleted eventually):
https://disk.yandex.ru/d/28M0ELv1U_paMQ
posila
Factorio Staff
Factorio Staff
Posts: 5349
Joined: Thu Jun 11, 2015 1:35 pm
Contact:

Re: UPS gets throttled down to FPS

Post by posila »

Thanks for nicely written up bug report, but this is not a bug.

You can read about the architecture of the main loop in FFF #70
In short, game update and render run in parallel, and if render takes too long, the game can do multiple updates without rendering (as you can see in you example with show-pollution-values enabled). However, there is a step, that collects game state data, that will be used in the renderer - we call this step Render preparation - and while render preparation runs, game update can't run. Unfortunatelly, lot of the map overlays need to go over lot of the game state to collect the data (especially if you are zoomed out all the way), so render preparation will be really slow if you turn on all the overlays at the same time.
evg-zhabotinsky
Inserter
Inserter
Posts: 22
Joined: Wed Dec 09, 2020 3:53 pm
Contact:

Re: UPS gets throttled down to FPS

Post by evg-zhabotinsky »

Thanks for reply.
Image
That last diagram really seems to match what's happening in my case, I get FPS=UPS of approximately 1000/("Update"+"Render preparation")<=60.

In some cases, mostly on map with show-pollution-values, UPS becomes a whole multiple of FPS, i.e. I get approximately FPS*N=UPS=1000/("Update"+"Render preparation"/N)<=60 for a minimum N. That is also consistent with the same diagram. Without show-pollution-values, though, FPS/UPS seem to mostly stay glued together.

I installed RivaTuner to limit FPS manually to 20, and the result is good for now, UPS sticks to 60 most of the time.
Will cobble something together for Linux/Primus later, as there seems to be no ready solution, at least none I could google up.

It would be much nicer to have the FPS limit setting built into the game. Would also help when power usage isn't irrelevant.
Even better would be a setting for lower FPS limit before UPS starts throttling, in addition to upper limit, for smoother graphics when possible.

Do I need to post FPS limits as a feature request for a chance to get it implemented?
evg-zhabotinsky
Inserter
Inserter
Posts: 22
Joined: Wed Dec 09, 2020 3:53 pm
Contact:

Re: UPS gets throttled down to FPS

Post by evg-zhabotinsky »

Found this: viewtopic.php?f=6&t=8280 Reduce FPS while minimized/inactive?

Not quite the same, but one more reason for FPS limiting code. With 3 settings: Normal FPS, Unfocused, and Hidden. FPS is already limited by VSync just fine so nothing should break.

The "Lower FPS limit before UPS throttles" would be a bit trickier. I'd suggest counting how many frames/updates behind the game is, compared to set minimum FPS and real-time UPS. After each update:
* Do "Render preparation" if
- - Frames are behind (try to maintain requested minimum FPS)
- - Nothing is behind (get as high FPS as possible without sacrificing UPS)
* Otherwise skip render and do "Update" right away (maintain desired UPS)
Post Reply

Return to “Not a bug”