Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add methods to accurately return the time spent in _process() or _physics_process() for the last frame #6809

Open
Calinou opened this issue May 4, 2023 · 0 comments

Comments

@Calinou
Copy link
Member

Calinou commented May 4, 2023

Describe the project you are working on

Official benchmarks repository for Godot, which will be used for performance testing.

Describe the problem or limitation you are having in your project

godot-benchmarks measures 5 different types of performance metrics:

  • CPU time spent on rendering per frame.
  • GPU time spent on rendering per frame.
  • Idle time per frame.
  • Physics time per frame.
  • Main thread time. This is time spent initializing the benchmark scene, which is also the execution time for GDScript tests.

As I noted in godotengine/godot-benchmarks#32 description, we currently lack a method that accurately reports the time spent processing idle or physics in real-time. While we have Performance.get_monitor(Performance.TIME_PROCESS) and Performance.get_monitor(Performance.TIME_PHYSICS_PROCESS), these are only updated once per second, which is insufficient for godot-benchmarks' needs.

Describe the feature / enhancement and how it helps to overcome the problem or limitation

Add methods to accurately return the time spent in _process() or _physics_process() for the last frame, rather than an average value over the last second.

Describe how your proposal will work, with code, pseudo-code, mock-ups, and/or diagrams

Right now, the values reported by the Performance singleton are set here: https://github.com/godotengine/godot/blob/8c729f0f34a92b92a1a8204e1d56b6ad05cfd27b/main/main.cpp#L3289-L3291

I suggest adding methods and properties in the Engine singleton to store the values, but do so every frame instead of once per second. The current mechanism can be kept to keep the monitors' behavior intact.

If this enhancement will not be used often, can it be worked around with a few lines of script?

For godot-benchmarks' use cases, the workaround I use is:

results.idle = maxf(results.idle, Performance.get_monitor(Performance.TIME_PROCESS) * 1000)
results.physics = maxf(results.physics, Performance.get_monitor(Performance.TIME_PHYSICS_PROCESS) * 1000)

This is much less accurate though, as it will only keep the "worst" measurement reported during the benchmark's runtime. Each benchmark runs for 5 seconds, and the previous/next benchmarks may "bleed" over the measurement, causing it to be even less accurate.

Is there a reason why this should be core and not an add-on in the asset library?

This is about improving the built-in performance measurement tools, which gives developers more ways to optimize their projects.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant