So I am having an issue with there being a huge and visible performance spike about once per second; where a single frame seems to last 2-3 times longer than the others and it’s easy to notice. The profiler reveals the problem, but I’m unsure what is cause:
- As you can see at the top there are two sets of green (rendering) spikes; smaller and more common spikes and less common but larger spikes.
- In the memory row you can see that there an increase in mesh memory (orange) - right as the smaller set of spikes occurs, and that the mesh memory doesn’t stay in memory for very long.
- Meanwhile the larger green spikes match up with garbage collection (gc allocated - the purple line in the memory column).
- All spikes are being taken up by Gfx.WaitForPresent; which is really just a way for the system to wait until critically important things to finish before the CPU/GPU can continue and work on the next frame.
So it seems that the cause of the problem is that for some reason some mesh memory is being allocated more than once per second and then garbage collection has to clean it up, causing the huge spikes. But why?
I am 99% sure that nothing is being allocated by my scripts during run time. I am sure to never use the ‘new’ keyword (except for simple structs like Vector3) or Instantiate(…) in run time methods, instead I put my objects that appear & disappear during run time into object pools and have them all allocated at the start with Awake. And I definitely don’t have new models loaded during runtime. The memory row doesn’t state where the increase in mesh memory comes from unfortunately. My game doesn’t even use rig animations; in fact all meshes are unchanging atm. Is it some setting in my mesh imports? I am using .blend files in my project. When the little spikes happen it says that there are about 65 more objects in the scene. Also why does the mesh memory allocation decrease before the ‘GC Allocated’ spikes is that is when garbage collection happens?
But I am still unsure what could be causing this issue, and thought I would ask here to see if anyone more experienced than me has any ideas. While it really seems that the spikes line up with memory allocation and garbage collection could I be wrong with that being the issue?
