We are using UE 4.4 for a small Twin Stick Shooter type game. I noticed regular slow-downs every 60 seconds that originate from the Garbage Collection. For testing purposes I was neither moving nor shooting, so only a few enemies where spawned and a few effect particle systems. These are the results from the log:
[2014.10.14-07.41.24:746][ 25]LogGarbage: Collecting garbage
[2014.10.14-07.41.24:775][ 25]LogGarbage: 28.265290 ms for GC
[2014.10.14-07.41.24:777][ 25]LogGarbage: 2.145622 ms for unhashing unreachable objects
[2014.10.14-07.41.24:813][ 28]LogGarbage: GC purged 161 objects (81728 -> 81567)
To be sure we are not using it completely wrong I created a blank project and logged the Garbage Collection. These are the results for doing “nothing” in an empty project:
[2014.10.14-09.01.38:079]LogGarbage: Collecting garbage
[2014.10.14-09.01.38:089]LogGarbage: 10.050900 ms for GC
[2014.10.14-09.01.38:089]LogGarbage: 0.324074 ms for unhashing unreachable objects
[2014.10.14-09.01.38:096]LogGarbage: GC purged 0 objects (22981 -> 22981)
I haven’t even tested this on consoles but I expect them to be about half as fast as my workstation pc.
So what can I do to maintain a steady 60 FPS in a small game without the Garbage Collection producing a slow-down every 60 seconds?
Just tested the blank project with UE 4.5 and it does not seem to make a difference.:
[2014.10.17-07.45.59:271][ 0]LogGarbage: Collecting garbage
[2014.10.17-07.45.59:282][ 0]LogGarbage: 11.001803 ms for GC
[2014.10.17-07.45.59:282][ 0]LogGarbage: 0.211988 ms for unhashing unreachable objects
[2014.10.17-07.45.59:282][ 0]LogGarbage: GC purged 0 objects (22913 -> 22913)
I checked it on console, too. It is about 15% slower. Not as bad as I expected, though. Still this is 75%+ of a frame coming on top every minute. A guaranteed slow-down…
Looking through other questions on this topic, most of the people that have experienced slowdowns were creating many actors (over 100) and destroying them every minute. The solution is to reuse actors (instead of destroying and recreating them).
Are you creating/destroying many actors?
As you can see from the log, there are not too many actors to be deleted. 161 objects (not necessarily actors) in the “real game” case, 0 objects in the “blank project” case.
The “blank project” case still needs 10+ms which is more than 10 times as much as I want to spend on memory maintance ever.
Also, creating / destroying 100 actors per minutes is nothing in my point of view. Spawning / destroying a dozend actors per frame should not bring down an current gen engine on current PCs and consoles.
Anyways, we do “prespawn” (and reuse) actors as much as possible now - actually more than 10000. But that only solves the problem of spawning itself being slow. It does not make the GC any faster, it makes it a lot slower since the GC needs to check many, many more object for possible clean-up.
The current plan is to stop the GC completely until the level is cleared and then do a manual clean-up. But my actual complaint would be: Why in the world is there a GC at the heart of a game engine?
And still we are experiencing same issue… Hello from 2020