- Đã chỉnh sửa
[Unity3d] SkeletonRenderer heap memory allocations per frame
Hi,
We're developing an online multiplayer racing game, which is quite sensitive on frame rates. But recently we have run into problems where GC takes too much time, so we started some profiling to see our total memory allocations per frame. Surprisingly, we found out that SkeletonRendered.LateUpdate is causing some amount of memory allocations each frame. The total amount of allocations is 2.3 KB for each frame (24 calls).
Frequent memory allocations could easily lead to unnecessary GC activity. Is there any way to avoid this? All our characters are using Spine animator so we're really looking forward to bring down this.
I wish I could help but I don't have a pro license. Does the profiler have the ability to tell which specific things/methods/lines are causing heap allocations?
Pharan đã viếtI wish I could help but I don't have a pro license. Does the profiler have the ability to tell which specific things/methods/lines are causing heap allocations?
Unfortunately no...but it should be showing the allocation is from the main loop of the LateUpdate method.
After some digging, we found out that this only happens on animation using Free-Form Deformation feature. For animations not using this feature, we're not seeing any heap allocations. One of my wild guess - could it be count of vertices keep changing on Free-Form Deformation animation? (shown as attachments)
And after I added some "Debug.Log" statements to SkeletonRenderer.LateUpdate method, I found that the allocation is happening here for SkinnedMeshAttachment:
if (tempVertices.Length < meshVertexCount) {
Debug.Log("[SkinnedMeshAttachment] allocatioin temp vertices");
tempVertices = new float[meshVertexCount];
}
The output of this debug log is also attached.
Please help with this. I think this should be a common problem for Unity runtime whenever Free-Form Deformation is used.
Some follow-up...I did some temporary change myself and resolved the memory allocation!
This is what I did:
if (tempVertices.Length < meshVertexCount) {
tempVertices = new float[meshVertexCount];
// We should remember and reuse the new tempVertices array to avoid future allocation
this.tempVertices = tempVertices;
}
Please help review whether this change will have any side effect.
Wish I had seen this earlier. This was fixed a few days ago in latest runtime. [Unity] Small bug causing garbage for meshes each frame viewtopic.php?f=9&t=3814
Updating to latest runtime would have sovled the issue...
@[đã xóa]
Git Commit: https://github.com/EsotericSoftware/spi ... c0857b0fe3
Is this the same place you were getting problems from?
If not, can you submit a pull request to the github repo?
Great, thanks guys! @ProudLittlePinwheel @[đã xóa]
My runtime was downloaded from the link providing .unitypackage and never did a pull from github. Now I believe pulling latest source from github will resolve it.
luxel đã viếtGreat, thanks guys! @ProudLittlePinwheel @[đã xóa]
My runtime was downloaded from the link providing .unitypackage and never did a pull from github. Now I believe pulling latest source from github will resolve it.
Myyyy bad. I'm supposed to be maintaining that unitypackage