Game freezes and profile understanding

Hi, I’m trying to fix repeated freezes (jerky camera) in my game, and while I use profile I don’t see any spikes or “weight” frames, but, instead, I see “holes” at every ten frames:


I wander, is this normal behavior? Why this holes doesn’t filled by WaitForTargetFPS? I have this with and without vSync.

I am not sure what you mean by holes, but the dips or empty spaces I am assuming nothing is going on during those times as far as your CPU is concerned.
WaitForTargetFPS I believe is bottlenecked by your GPU and waits for the GPU to handle the graphical processing and is waiting for that to complete.
You appear to be leaking 1.6KB in a frame while the game is running, also your GUI.Repaint so some type of graphical stuff is leaking 4.4KB every frame. So in total it looks like you are leaking a good chunk of KB every frame. Now I am not sure what is causing your “stuttering” but I can safely assume some of your performance drop over time would be caused by the GC collecting the memory.

Yes, I mean dips )))
Hm, in total 6.0KB per frame… yes, it could be a performance drop over time. Thanks you, this is a good point to start.
I always thought, garbage collection is present in profile also…

I found where is leaking 1.5KB each frame: update of player progress (converting float distance, speed, and scores to strings):

return distance.ToString(“0.00”); // every conversion calls NumberFormatter.NumberToString() and takes 500B

In this case I can check if old value == newValue - don’t do anything.
Another leaks are very occasional.

Most of your chart is filled with VSync. The holes are the occasional are where you drop a frame because the previous frame is not yet finished.

Most of the time you want to profile with the VSync not showing. That way script spikes are easier to see.

GC might be the issue. On your long frames you should see a explicit call to GC.Collect.

So, it sounds like Unity doesn’t finish job in time and drop one frame? This could be a reason of freezes?

VSync is disabled. As I understand, WaitForTargetFPS is synchronization for target FPS, it “fills free time”, if I set targetFrameRate to 30 or 60 fps - I get different WaitForTargetFPS fills.

What is a mystery for me, is why Unity generates this empty spaces and is it normal or not )