Unity Random Frame Drops Every 1-2 seconds in build

We have a multiplayer game that works on both windows and android. It’s using Unity Netcode for GameObjects. We’ve been looking into some optimization issues and have noticed that our game runs fine in terms of a constant frame rate, but there are significant frame drops on both platforms.

I’m getting close to 300 FPS on windows, so I didn’t notice FPS drops are occurring frequently. When I profiled the windows build, there seems to be no single culprit. I’ve already spent many hours optimizing all our code and our asset team has optimized all our environments, so I’m not sure what could be causing this.

It’s worth noting, this does not happen when I profile the editor. It only happens in builds. There is no one function that repeatedly causes frame drops. It’s always a random call.

Look at this with the Timeline view. I’m 99% sure you’ll see a GC.Collect happening on some thread in parallel to the main thread stalling.

That’s because the Boehm GC is a stop-the-World GC that pauses all threads. It only shows up on the main thread as GC.Collect when that’s where the last allocation was made that needed a heap expansion.

Try turning on incremental GC or if you already have, reduce the amount of GC.Alloc as you’re likely allocating faster than it can collect and needs to fall back to a synchronous collection.

In order to help could be usefull to also past profiler result with DeepProfile. If you not use it enable it. And maybe will show you where you loosing your 900+ ms

If you had 7kb per frame, its loots of garbage collected an you should deel with it.

Maybe consider droping down expanded deep profile results of you BotUpdater, and could check out what creates this dellays…