What causes an increase in editor GUI garbage collection?
Asked Answered
W

4

0

In editor, I see massive and regular spikes from GC.Collect which freeze the game for anywhere from 200ms to over 1000ms. These spikes do not register in the normal profiler mode, only when profiling the editor itself. These spikes (and game freezing) also do not occur in standalone builds at all, only when testing in-editor, and always related to GUI in some way. I do not have any UI in the scene, only a camera and meshes. Do you know what might be causing these huge spikes, and/or how I might fix this?

Full disclosure: this is part of a procedural, voxel prototype, which I know are prone to performance and memory management issues. I’ve done my best to structure the code to be performant, and limit unnecessary GC parsing of the heap, thanks to the profiler - that said, I can’t rule out that something from gameplay isn’t increasing the workload for the editor in some way, leading to this issue. I’m hoping that someone might be able to shed some light.

Sorry in advance if the formatting is bad, new lines aren’t showing up in the preview…

Wend answered 8/11, 2023 at 9:7 Comment(2)

It looks as though the GC calls are under IMGUI for the Unity Editor itself; in particular the game view panel. I would imagine it's just part of how the game view is drawn/maybe even the profiler. Do you still get these spikes when running the scene normally, or only when profiling the game view?

Selffertilization

No matter what windows I leave open or close, the spikes don't change. Even with the profiler not recording and closed. I did notice that changing my world's size (like "view distance" in Minecraft) changes the severity of the spikes, but I just can't see/understand the connection between world size and editor GUI. Still runs perfectly in a build, but it makes testing in editor a challenge.

Wend
W
0

I hope it’s okay to answer my own question.

I tried testing with “Maximize on Play” enabled, and the hitches disappeared. This led me to realize that the panels themselves are triggering GC.Collect. More panels meant a more frequent spike. so it’s not that it’s not that I don’t have the issue in a build, it’s that the garbage collector simply isn’t being triggered because the heap doesn’t change after the initial load. I added a script to manually trigger GC.Collect, and sure enough, I get the same spike. I guess my code isn’t as optimized as it could be. I hope this helps someone else seeing this issue!

Wend answered 6/6, 2023 at 2:35 Comment(0)
F
0

Hello,

I am specifically noticing this on Unity 2020 LTS on editor while I have the Animation Transition GUI window open.

I guess there is no really a solution but close/open the specific GUI window to reset the memory if the hiccup is getting bad?

Festal answered 6/6, 2023 at 4:47 Comment(0)
R
0

Lol same thing. In 2022.3.8 it was ok, but after updating to 2022.3.12f1 I faced spikes caused by internal editor gc collection under IMGUIContainer.

Reputed answered 8/11, 2023 at 9:6 Comment(0)
C
0

Same problem in Unity 2022.3.4f1 (3D URP template).


Project is almost empty (a few 3d primitives and player movement script)
Capias answered 24/2 at 23:53 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.