+10 votes

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?

Thanks!

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.

in Engine by (684 points)
edited by

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

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

2 Answers

0 votes

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.

https://youtu.be/-b1dylw9v2o

enter image description here

by (128 points)
0 votes

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.

by (998 points)
edited by
Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read How to use this Q&A? before posting your first questions.
Social login is currently unavailable. If you've previously logged in with a Facebook or GitHub account, use the I forgot my password link in the login box to set a password for your account. If you still can't access your account, send an email to webmaster@godotengine.org with your username.