400ms lag spikes in build - profiler doesn't help - how to troubleshoot?

I am getting lag spikes in my game that uses Unity 2022.1.19f1 and HDRP. The spikes seem to happen on random functions that get called throughout the frame - it’s as if it has nothing to do with the individiual function and the whole runtime has just frozen for 400ms.
(I also tested this on the latest LTS and found the same issue to happen, but it broke other stuff, so I reverted back to 2022.1.19f1)

Does anyone know any way to troubleshoot this? I am using await at rare times in my C# code, maybe that has something to do with it? But certainly not as frequently as these spikes are happening.

If anyone knows about any 3rd party profiling tools that will be more helpful than this unity profiler, or know what could cause freezes like this where the unity profiler is useless, let me know.

Note: These spikes don’t happen in the editor.

Seems like it was just a GC allocation issue.

If you switch to the Timeline view, it would probably show you exactly that, i.e. that some other thread is running GC.Collect at that point. The Boehm GC in Unity does a StopTheWorld garbage collection when run non iteratively so all threads are paused.

Besides that’s there is a list of native and platform specific profilers in our manual pages for profiling :wink: