Thread assignment inconsistent iOS11 / Spritekit / Physicsbody meaning low FPS

54 views Asked by At

I have been running a simple, many body (800) 2x2 pixel SpriteKit simulation using the PhysicsWorld under iOS11 / Swift4 - a rudimentary particle system.

It contains a simple radial gravity node, with 800 objects orbiting it with no collision or contact detection employed.

On my test hardware, an iPhone6S - I have been really impressed with attaining 60FPS and super smooth simulation - which opens the way for much more exploration.

The only problem I have been running up against is that the performance is really inconsistent.

If I switch the gravity node's field strength to a high value mid run (meaning objects move around a lot faster) - in about 25% of runs, the simulation can get 60FPS no problems, but on the other 3 out of 4 runs, the framerate drops to 3-4FPS

If I revert to a low field strength (slower movements) then it always gets 60FPS again.

I have profiled in XCode - and can see that SOMETIMES 3 or 4 threads are given to the app, giving 60FPS, but the other times only a single thread is being given to the task - meaning gnarly performance

I have experimented with Grand Central Dispatch, and thread priorities - to no avail - the only code that is running each frame is the PhysicsWorld anyway, nothing I'm doing frame to frame.

Any ideas out there how I can get consistent 60FPS - as clearly the hardware is capable of it - but just when it feels like it!

Additional note: if the device is plugged into the dev Mac / on charge / USB / with XCode running etc - the performance is more often good with all threads utilised. But trying the exact same app, say the next day, running standalone on the device (not attached to dev machine) - nearly always very poor performance - MAJOR HEADSCRATCH!

1

There are 1 answers

0
Arthur Macpherson On

Performance issues regarding nodes are common when physics bodies are used, if you have used a physics body use the standardised bodies instead of the custom one. Hope this helps.