I'm experiencing a huge FPS drop in the scene with a few static SKSpriteNode
nodes that have bodies defined with SKPhysicsBody
init(polygonFrom: CGPath)
and some simple, dynamic SKSpriteNode
nodes with bodies defined with init(rectangleOf: CGSize)
.
Dynamic nodes are fired across the scene and eventually rested, depending on the physics. Every dynamic node is colliding with other dynamic nodes and also with static nodes mentioned before.
The game runs smooth at 60fps, until the number of dynamic nodes on screen is around ~30 or more. After that, the FPS starts dropping drastically to around 10fps.
Note 1:The problem is not present on iOS 10, only iOS 9 (I haven't tested iOS 8 since I'm not supporting it).
Note 2: draw calls do not increase because of increased number of dynamic nodes, so there seem to be no problem on the OpenGL side.
Note 3: I disabled contactTestBitMask
to ensure that this is not the cause of the problem.
I ran Instruments with Time Profiler, focused on segment where the FPS drop and found the following strange thing:
What's strange is that more than 50% of the time in problematic segment is spent in PhysicsKit
. Note that it doesn't matter if the collisions are happening at the moment or if the dynamic nodes are just resting in place. The results are always the same.
This has to be the cause of it but since all of this is happening in the system libraries (PhysicsKit
), I don't really have an idea where to look for the problem in my codebase.
Thanks for any help!