[SOLVED] Garbage collection on iOS

We’ve been struggling with performance drops in our game caused by the garbage collector kicking in, but so far we’ve been unable to determine what is generating the garbage.

To get to the bottom of this, I created a new project and ran it on an iPhone XS using the Web Inspector in Safari on my Mac to profile it. For some reason, the garbage collector is kicking in every 10th second – and this is just the sample scene with the cube on a plane and nothing else going on.

Why is this happening? Why is PlayCanvas generating garbage and/or running the garbage collector every 10th second? :cry:

Just to check that there are no browser extensions on the iOS device (eg adblockers etc?)

No, just vanilla Safari

In addition to the iPhone XS, we’ve also tested on an iPhone X, iPhone 6S and iPhone 6. They all exhibit the same behaviour.

Any comment from the devs?

Even the most minimal of JavaScript programs will generate garbage. It’s almost impossible to write even small applications that generate no garbage. So for something as big and complex as the PlayCanvas engine and the games created on top of it, it’s to be expected that the garbage collector will be called every several seconds.

The idea is that the garbage collector should be able to run without it causing any problems. This is typically the case if the amount of garbage that accumulates does so slowly. But if you accumulate a lot of garbage quickly, a minor GC stall can become a major stall. That’s something you should be able to avoid if your project manages memory well.

The trace you have looks kind of odd to me. If I have created an app with a spinning cube and run it on an iPhone XS, I don’t notice ~50ms GC stalls affecting framerate.

You’re right, I just tested a spinning cube and that runs smoothly on iOS despite the trace. Interesting.