Is it worth to using Timer or self-made interval to improve performance?

Godot Version

4.x

Question

Is it worth to using Timer or self-made interval to improve performance?

I always disable v-sync and put FPS on screen in development to keep an eye on performance. My general thought is higher FPS, better performance. Whenever I found FPS is down more than 20%, I use Profiler to look for which script causes the down (let’s ignore physics performance for now).

If some scripts do run a lot and consume large amount of CPU, I will try to move script into Timer or a self-made interval as long as I don’t need it to run more than 50 (can be a different number) times per second. Usually this gives me good performance gain and FPS goes back to a higher number.

But recently I find this might not be as useful as I thought. As I disabled v-sync, the FPS is quite flexible depends on the script. When more and more logic added, those which consumes large amount of CPU will consume less naturally so using Timer will be less useful until your FPS hit a lower threshold like 60.

In other words, the performance gain by using Timer or self-made interval to have less runs per second is an illusion unless your FPS hits observable rendering lag.

I’d like to know other’s thoughts.

Thanks!

Yeah, don’t do that.

Never optimize unless you have to. Otherwise you’ll end up caught in a premature optimization trap.

Also, sporting some general optimization strategy is mostly useless. Always adapt your optimization approach to each specific bottleneck. Running every N-th frame may be appropriate only for a small specific subset of actual bottlenecks.

6 Likes

While I mostly agree with what’s said above, I do a lot of “less that every frame calls” in my game. Though I don’t do any “call 50 times per second, instead of 60“, but I do a lot of ‘call once a second’ or so..

I did a lot of Read Dead 2 modding, in that game there is a short, medium and long update cycle, the short being once a second call, and the long is like once every 15 seconds (I might be off, it’s been a while..).

There can be a lot of things that don’t need to be called every frame, I think it’s a commonly used thing in gamedev to improve performance.

Just my two cents generally speaking about call intervals, but again, as for this specific case, I don’t really know if 50 instead of 60 calls worth it…

3 Likes

I think we all agree that running every N-th frame can improve performance. What I want to bring to the table is that doing this may not be very useful when your game still have a good performance, like first replier said.

I have a spacecraft building simulation game. The air flow is simulated in chunked space in the spacecraft. In default, this simulation runs every frame. When more and more chucked spaces are added by building the spacecraft, the FPS goes down steadily. To understand where the limit is, I added hundreds of spaces and found FPS downed from 500 to 80. Then I added interval to run the airflow logic only 10 times per second, the FPS is back to 500 and there’s no observable issue to see how floating objects are moved along with the air flow.

So it looks I saved a lot performance (80 to 500 measured by FPS). BUT, it may actually mean nothing, as the FPS is still above 60 (let’s assume this is the threshold I can bare with). When more and more stuff added into game, the current FPS, whether 500 or 80, may not be very different as the air flow cycles will be automatically reduced to give more resources to other stuff.

Well, thing can be different when FPS is below 60 (or 120 or any number depends on what’s the requirement). But until that time, I don’t think we need this running every N-th frame a lot.

1 Like