Hi all - is this yet another Unity bug? I have a nearly empty scene and in 2021.3.2f1 and the framerate tanks after about a minute. The profiler says the editor loop is causing this. HOWEVER, a standalone build experiences this huge degradation too - both in debug and non-debug mode. What’s going on?
Pretty severe issue compounded by lack of clarity from the profiler.
Try enabling deep profile, this gives you more info in the profiler. I bet it‘s a custom (editor) script or a downloaded asset causing this.
1 Like
Yep, was Obi cloth, thanks!
1 Like
Bad news, was not obicloth. Still happening after a brief hiatus. @MartinTilo any ideas? To my knowledge I have no editor scripts running.
Unity basically does not work in this condition. I can’t use playmode for more than 30-60 seconds. And, this issue happens every time.
leaving a scene open in playmode with nothing going on (just sitting there) leads to this huge decrease in performance after 2 mins or so. Things just get gradually worse and then shoot up to infinity. Pausing the editor and then unpausing immediately returns things to 60 fps. What is going on here?
Here’s a video showing the degradation. Looks like things get worse, then build up and recover, then worsen again.
I’ll add that I also see physics.fixedupdate swelling. I thought this might be related to the cloth I’m using so I turned that off - no dice.
It could be (or at least be made drastically worse by) the physics/fixed update special of death. I.e. as your frame rate gets worse, fixed update needs to run more times within the frame to make up for the longer frame time, in turn making the frame time longer.
This can be combatted via the Time Settings, i.e. adjusting the Max Allowed Time Step and the regular FixedUpdate time step. And also by optimizing your code that executes as part of FixedUpdate and only doing the bare minimum necessary to be executed in fixed time in there and doing everything else in Update or friends.
Also, you might want to flip hierarchy view through the different threads, or look for magenta in Timeline View. Only 6.4 KB of the 18 KB of GC.Alloc in the frame shown in the screenshot are happening on the main thread. (Though, since you’re profiling the editor, it may also be allocated in the Editor Loop so maybe profiling the Editor instead of Playmode might also reveal their source)
This is not a memory leak, but “just” bad performance. The profiler clearly shows 17 calls to FixedUpdate per frame (normally, there should be 0 or 1 FixedUpdate() per frame) so the culprit is death spiralling as Martin pointed out.
Easiest way to test if this is the case: set both your maximum fixed timestep and your fixed timestep to 0.02 (50 hz) If the issue goes away, the problem is that the physics engine cannot keep up with the demands of the game. Investigating deeper what your game does during each frame would be the best way to keep performance problems at bay.
In your video, when the game is running it’s taking > 33ms/frame with peaks of > 60 ms/frame, most of it spent on rendering. With a fixed timestep of 0.02, that means you might need to take 0.06/0.02 = 3 physics steps (calls to FixedUpdate) some frames, this will make your performance sink lower, making the next frame take longer to render (say, 100 ms) and forcing Unity to make more calls to FixedUpdate(). As frames progressively take longer to render and simulate, physics needs to be updated more times per frame to catch up. This is what is commonly referred to as the spiral of death, can happen to all fixed-tilmestep physics engines. Unity will only stop updating physics when it hits the value of your maximum fixed timestep setting.
This is the reason why when you pause the editor, it temporarily runs faster again: pausing allows the engine to recover, once you resume the game, over time the physics engine gets behind rendering and needs to catch up, entering a downwards performance spiral. Ways to fix it:
- Optimize your game, overall.
- Use a longer fixed timestep (will yield worse quality physics).
- Use a smaller max fixed timestep (will keep the spiral from going as deep, but won’t prevent it)
I’d recommend reading about fixed timestep and the death spiral to really understand this and take action accordingly. Fix your timestep! is probably the best article on the subject, but it’s a bit technical.
1 Like