• Runtimes
  • Need advice on how to improve performances

Hi,

In our Unity project we need to display hundreds of Skeleton Animations at the same time and I'm facing performance issues.

I've read the performance hints in the documentation and it says that there is many potential reasons for performances to be impacted by Skeleton Animations at runtime. After some investigations I noticed that the CPU usage is very high (that does not really surprised me actually). So I was wondering if there is any tips / advice on how to setup skeletons in Spine the "smartest" way, knowing that hundreds of them will be updated simultaneously in the game.

On the other hand maybe there is also things that I'm not aware of, like useful parameters / options to choose within the Unity components to make animations updates "lighter", or code related stuff I could try to do as well ?

For now I did the base stuff like activating / deactivating the Skeleton Animations depending on if they are on screen or not. It works really fine but does not fix my problems when those 300 Skeleton Animations are actually on screen (this is not the most common case, but it can happen during a game session ...)

The Skeleton Animation instances are all using the same Skeleton Data, but can have different skins and attachments.

From the lighter one :

To the heaviest one :

My first guess was trying to reduce the amount of bones ...
I know that there is a risk that we need to reduce our level of details, but we would like to know more on "best practices" before starting to cut down 😛.

What do you think ?

Related Discussions
...

I would suggest to have a look at what the Unity profiler actually displays as the most problematic factor, and then decide accordingly.

Feel free to post any screenshots of the profiler run here if you need help with it. Then please with the following settings: Enable deep profile mode, click on the CPU usage block and in the window below change from Timeline view to Hierarchy to display a more useful sorted view.

In case the animation update is the bottleneck: we have parallelization and other optimization steps on the roadmap, so things will improve without needing any action by you in the future.

However it is always very very helpful to reduce animation complexity and vertex count as much as possible!

Thanks a lot !

I'll deep-profile this in the next few days and post some results 😉

By parallelization you mean multi-threading ? (that would be great actually)
Is it something planned for the next months, or is it more for the far future ?

I also precise that we are targeting PCs for now (no mobile devices for instance).

Yes, by parallelization I mean multithreading. Any ETA I would provide will be very unreliable, since these features are prioritized after the urgent and important bugfixes and features. Any of the two could be true - in the following months or later.

Hi !

So here is what I get when I deep profile the game :

https://ibb.co/X2VMQxY

Bottlenecks seem to be SkeletonAnimation.Update and SkeletonRenderer.LateUpdate, taking more than 60% of the CPU when I have around 190 updated / rendered skeletons.

The curve you can see about the frame-rate through time is actually depending on if the camera is showing lots of skeletons or not (because I deactivate those who are not on screen, so when I leave the "heavy" area the frame-rate goes back to a descent value).

Thanks for posting the profiler image!

Actually after posting the recommendation to enable Deep Profile I discovered that this setting distorts the resulting output far too much to be reliable when profiling the Spine runtime [1].

Nevertheless your output shows that rendering takes roughly 4ms, which is sufficient information to say that most likely the animation- and mesh updates are the bottleneck here. If you want to have a more reliable view on the subject, you could again post the same profiler window with Deep Profile disabled - it should then be at least closer to reality.


[1] When profiling with Deep Profile disabled, the ratio of SkeletonRenderer.LateUpdate to SkeletonAnimation.Update is e.g. 4.8 : 4.2, when it's enabled it is 11 : 21! Therefore deep profile cannot be trusted and shall be disabled.

Here is the result without deep profile :

Thanks for posting the screenshot.

Unfortunately it does not show the milliseconds but only the percentage. In this case there is nothing unexpected shown here, but also no additional insight gained.

19일 후

Hi

Sorry for the late reply. Here is a more detailed profiling view :

No problem, thanks for posting it.

As I asumed, the animation- and mesh updates seem to be the bottleneck here.

So as I posted earlier, it is always very very beneficial to reduce animation complexity and vertex count as much as possible.

4일 후

Is there a way to deactivate the automatic updates of skeleton animations ?

I was thinking that instead of letting them update every frame I could do it manually every N frames (with an offset per instance, so I can reduce the CPU load).

Yes, there is the SkeletonAnimationFixedTimestep class included in the Spine Unity runtime.

For your purpuse, maybe you might need to create your own copy with similar adapted functionality, if the component is not sufficient out of the box.