Some time ago my game aquiered weird stutters on thin air, after looking into profiler I noticed that unity randomly decides to update random things longer than normal, both on filled and almost empty scenes. It take like 4 seconds to do empty Update fnctions in my old scripts, random render sruff etc. which take not more than 0.5 ms in normal frame. All these spike appear no matter if game handling active gameplay, pause menu or just idle standing in one place not doing anything.
What can cause these strange freezes? (And btw, what exactly is UpdateFunction.Invoke()?)
Are you profiling editor playmode? If so, try profiling a build to see if this has the same issue. The editor might do some tasks that block the main thread and cause hiccups in playmode.
You can also enable Edit mode profiling to see whether anything “EditorApplication” related is taking up a lot of time.
I am profiling the build on remote system (mine doesn’t have this weird freezes and they appear on 75% of systems with different length, frequency and places where they appear, and this doesn’t follow overeall computer power, they are completly random). Since sending data from remote system to profiler causes more freezes, I disabled their visibility in Profiler (“other” tab). If anything, freezes appear in builds without profiler, so they are not caused by profiler.
These look suspiciously like stalls caused by the Profiler as it can’t stream out the quantity of profiler data with the buffer size it has without freezing up the generation of new data (aka code executing). You could try increasing the buffer size it has available via the command line option-profiler-maxusedmemory as you start that Player.
Alternatively there might be a GC.Collect happening on a thread other than the main thread but I couldn’t immediately spot one in the screenshots, though they are somewhat cut off/ not showing all threads.