Guidance when optimizing, minimizing Idle Time, and reading the profiler

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By jarlowrey

At certain points I spawn a lot of enemies onto the screen. I captured the performance hit on the profiler and it looks like this:

enter image description here

I can see that my script time has gone up dramatically, but it looks like Idle time is the biggest contributor. What is Idle time, and why is it slowing things down so much? Why is Physics Frame Time always 100%? What are some good optimization techniques for Godot/general tips & tricks when reading the Profiler?


Guess: Idle time is processor waiting for things to happen. Likely, the processor is waiting on memory to load, allocate, or deallocate. Pooling and maybe Sprite sheets (instead of separate PNGs) would help lower this.

Any update on this ?
really cant seem to use profiler info to hunt down my performance issue :frowning:

GameVisitor | 2019-09-14 08:09

i’ll tell what i know;
physics frame is always 100% because you measure Physics Frame %, it took 1/60 second, or 0.016 second per frame (using 60 fps, in 1second there are 60 frame ). it always constant as it was supposed to be

ruruarchy | 2020-06-22 06:55

:bust_in_silhouette: Reply From: ProggerParrot

When the idle-time is too high, then your _process() is waiting for something to finish… maybe vsync or any other timer-consuming function.
This video will definitely helps you.

:bust_in_silhouette: Reply From: Yuminous

As you guessed, the engine is waiting for something to happen.

For those large spikes, a lot of something has happened in that frame which the engine has to finish working on before it starts the next frame.
If you’re trying to limit these spikes, you’ll need to think carefully about what you strictly need to have in your scripts or what rendering tasks you could batch or improve (if any) and optimise from there. Check out the performance/optimisation guides in the docs for lots of more interesting stuff. There is also certain “best practices” for other programming languages that can apply to GDScript, such as basic math being extraordinarily cheap, and although it sounds weird you could also look at optimisation techniques used by developers in other game engines which may give you clues as to how you could improve your own code.

But the most basic thing will restrict performance in Godot: V-Sync is enabled by default in your Project Settings, which is the likely culprit of high idle times and far lower-than-expected framerates due to it literally “idling” between frames to try to sync the framerate with what it thinks is the monitor refresh rate.

Apart from V-Sync, there may be other settings activated in your default Project Settings which you may want to browse through, change and/or disable as necessary. Very few will have the same drastic effect that V-Sync does but it’s important to check out and know what options you have available.

Keep in mind that Idle Time represents everything else besides physics, including rendering, print functions and even the profiler that you are looking at, as well as the game engine main loop which will happen regardless of your own code. So there will always be some idle time, but it certainly can be a lot lower.

As for the Physics Frame, it represents the Physics Servers attempt to maintain a constant frame time. This doesn’t affect your rendering performance, but excessive physics simulation/code may cause your idle time to come up.