godot
godot copied to clipboard
AnimationTree causes performance drops even if no animation is running
Tested versions
v4.3.beta2.mono.official [b75f0485b]
System information
Godot v4.3.beta2.mono - Windows 10.0.19045 - Vulkan (Forward+) - dedicated NVIDIA GeForce RTX 3060 Ti (NVIDIA; 31.0.15.3623) - AMD Ryzen 7 3700X 8-Core Processor (16 Threads)
Issue description
Whenever using Animation Tree (adding it to scene) even if no animation is running, it drops the FPS by ~50, so if you have 20, that is not much it will drop 1000 FPS.
Without Animation Tree
With Animation Tree (20 nodes)
Steps to reproduce
I have a sample project that reproduces it run with the AnimationTrees and press F3 (Thanks @Calinou for the awesome plugin)
And after that delete the AnimationsTrees node and run it again and press F3.
Minimal reproduction project (MRP)
FPS is not a linear measurement. For example, a drop of 1,000 FPS isn't the same thing at all if you drop from 1050 to 50 FPS (19 mspf difference) compared to dropping from 3050 to 2050 FPS (0.16 mspf difference).
This is why graphics programmers generally never refer to rendering measurements as FPS and always talk in frametime instead (milliseconds per frame, also known as "mspf"). This is a proper linear measurement.
Can you reproduce this issue with an inactive AnimationPlayer node (instead of AnimationTree)?
Thanks for clarification, although this concept is still weird to me, I will learn more about it before making more assumptions. If you mean setting this to false, yes I still can reproduce the FPS drop and the increase of mspf.
I can even remove the AnimationPlayer and I will have the same result. The problem is definitely the AnimationTree.
What calinou is saying is if enabling AnimationTree drops the frame time from 30 milliseconds to 60 milliseconds it is a very different problem than dropping 30 millisecond to 31 millisecond.
Since you mentioned frame drops one possible interpretation is a 0.3 ms drop to a 0.5 ms drop which is hard to justify work so we need to check in milliseconds per frame units.
So I think we need some justification this drop is too slow for your game.
What calinou is saying is if enabling AnimationTree drops the frame time from 30 milliseconds to 60 milliseconds it is a very different problem than dropping 30 millisecond to 31 millisecond.
While the FPS drop might be small here, it has the potential to be larger in a game that has a lot of animated characters, even if you disable animation processing when far away. That's the issue we should aim to resolve if possible :slightly_smiling_face:
I ran some profiles with HotSpot using an optimized (optimize=speed lto=full) editor build:
Top-down view with AnimationTree processing expanded
Flamegraph (full view)
Flamegraph zoomed on AnimationTree::_blend_pre_process()
Flamegraph zoomed on AnimationTree::_blend_apply_()
I usually have around 1k FPS without any AnimationTree
My game has a few creatures in the screen, and its enought to notice that frame time is going up. I aim to publish it to mobile, so I was procupied that this could hit the performance on this low end graphic cards devices.
Just to notice thats how I've setup my AnimationTree using AnimationNodeBlendTree with a StateMachine