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

AnimationPlayer/AnimationTree high process large framedrops #92693

Closed
Duskitten opened this issue Jun 2, 2024 · 6 comments · Fixed by #92838
Closed

AnimationPlayer/AnimationTree high process large framedrops #92693

Duskitten opened this issue Jun 2, 2024 · 6 comments · Fixed by #92838

Comments

@Duskitten
Copy link

Duskitten commented Jun 2, 2024

Tested versions

Confirmed by me:

  • Large frame drops in any build past 4.2.x (4.3 (be56cab))
  • FPS heavily inconsistent in 4.2.2/4.2.1

Confirmed by other people:

  • Godot v4.3.dev5 - Windows 10.0.19045 - Vulkan (Forward+) - dedicated AMD Radeon RX 6600 (Advanced Micro Devices, Inc.; 31.0.24027.1012) - Intel(R) Xeon(R) CPU E5-2637 v2 @ 3.50GHz (16 Threads) - Large frame drops

System information

Windows 10.0.19045 - Vulkan (Forward+) - dedicated NVIDIA GeForce GTX 1080 (NVIDIA; 31.0.15.4629) - AMD Ryzen 5 1600 Six-Core Processor (12 Threads)

Issue description

Upon the creation of many animation players + animation trees (in this case 1024) with animation indexes, but no actual keyframes the engine proceeds to drop frames or fps becomes incredibly unstable due to high process call ms being added (goes from 16ms to 25-30ms)

Steps to reproduce

Create a new object, put give it an AnimationPlayer + AnimationTree (keep the animation running) and animate it, but remove the actual keyframe, and duplicate it 1024 times, fps becomes unstable or process ms doubles and causes consistent framedrops.

Disabling animation playback returns to stable 60fps.

Minimal reproduction project (MRP)

AnimationTimer.zip
This simply duplicates a pre-made character 1024 times to sit in a 3D scene, with an animation with 0 keyframes running and performance begins to hurt in master branch.

Disabling animation playback returns to stable 60fps.

@Calinou
Copy link
Member

Calinou commented Jun 2, 2024

With such an high number of active animation players on characters, you'd need SceneTree multithreading to achieve reasonable performance. However, this isn't finalized yet.

Your best bet for now is to disable animation playback for nodes that are far away, or set their process mode to Manual and step through their animation less often (e.g. once every 2 frames). This is a common approach in AAA games.

VisibilityNotifier3D in 3.x has a Max Distance property that can be used to disable animation playback in the distance automatically. It hasn't been ported to 4.x's VisibleOnScreenNotifier3D yet though.

@Zireael07
Copy link
Contributor

The manual process mode trick should be documented somewhere

@jitspoe
Copy link
Contributor

jitspoe commented Jun 21, 2024

Since I've been delving into performance stuff, here's a shot of Tracy profiling of animations with my fairly simple low-poly enemies in KOOK:
image

So the average _process_animation takes around 40 microseconds. With 100 enemies, that's like 4ms, which isn't super great.

Here's the tracy file if anybody wants to poke around:
kook trace 20240621.zip

Most of the time is spent in AnimationMixer:_blend_process followed by _blend_calc_total_weight. About 20 microseconds and 9 microseconds there.

If manually stepping is the solution, it would be nice to have some sort of built in system to prioritize closer/in view objects so they update every frame and then have a max number of animations played per frame or something.

I do feel like some optimizations could be done, though, outside of that and multithreading.

Edit: Just realized there's a PR to do some optimizations here: #92838 Nice!

@WOLFxxxxxx
Copy link

GLEcxYwW4AA8ufD (1)
GLEcGh1XkAA2-YX (1)

Animation does not support multi-core

@Calinou
Copy link
Member

Calinou commented Jun 29, 2024

Animation does not support multi-core

This is expected for now, as SceneTree multithreading isn't finished yet. Work on this started in 4.1 but it's only applied to a few parts of the engine, so I don't think AnimationTree is able to work in a thread-safe manner currently.

Despite this, it's still possible to optimize AnimationTree significantly as evidenced by the PRs linked above.

@Saul2022
Copy link

GLEcxYwW4AA8ufD (1) GLEcGh1XkAA2-YX (1)

For more performance minimize or close the editor windows as that is alos consuming fps , and also what calinou said and make the debug screen fullscreen , as they are not the same size as flax so it not quite fair as a comparison...

@akien-mga akien-mga added this to the 4.4 milestone Sep 2, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

7 participants