Hello,
I'm currently trying to optimize my Spine objects in Unity and am seeking some recommendations. My approach to using Spine in my game is pretty complex:
Heavy use of mix/match attachments - 2k attachments with 600 constraints to configure them. About 80 constraints are active at once.
Several concurrent animations with blending—I'm making a 2.5D twin-stick shooter, and I am blending a forward/back movement animation with a strafing animation at all times to ensure fluid movement of the legs in 360 degrees. I also have two more tracks for handling animations on each arm.
If I put 10 of these characters in a scene and have the AI fight each other, SkeletonAnimation takes up about 40-60% of the CPU time. Which is not surprising, a lot is going on with these skeletons. However, there's one process that caught my eye which takes up over 20% of the CPU - AnimationState::ComputeHold(). Specifically, the looped usage of AddAll() on the HashSet of strings - O(n2) worst case. I determined I get around 860 IDs - so 740k string-compares per skeleton seems like a lot. And because I'm constantly blending animations, this function is being called every frame. I actually found an issue (#1462) where someone had already asked about this in regards to HasTimeline. I also noticed that back then ints were used instead of strings (this was changed in 4.0). So that can easily increase it's cost many times over from what it was back then. I don't understand too well what's going on in this function - just the tiny bit I comprehended from the discussion in #1462. Is there are way I can avoid this call or reduce iterations? I don't totally understand what a timeline ID even means, other than it's made up of an attachment and slot ID. I've included an image of my project metrics with one of the movement animations selected (so two of these are always blended). Would appreciate any recommendations on which numbers I should try to work down that could be causing cyclic performance hits. There's definitely room for me to reduce mesh vertices - but the attachment, slot, and constraint count are pretty critical to my character structure. Much appreciated!