Ramsay Consulting
Ramsay Consulting

Reputation: 593

How can I save CPU effort in SceneKit rendering delegates?

SceneKit calls its rendering delegates sixty times a second to allow a host application to adjust parameters in the contained scene to provide animation, physics, etc.

My scene is large (360,000 vertices). Almost all (~95%) of the scene is rotated slightly every minute (every 3,600 delegate calls). A very small remainder of the scene (about 300 nodes ~ 15,000 vertices) is moved once a second (every 60 delegate calls); all the nodes are created and their properties set before the application 'starts' (in viewDidLoad) and then only their positions are changed, as described above, in the delegate calls.

My frame refresh rate only just keeps at 60 fps and CPU usage is about 30% according to Xcode. All that effort is being expended in the rendering loop (there's no interaction; no other work) so I have two questions:

1) does 30% CPU seems reasonable, given this general description of my app? More specifically, since my delegate code seems simple and invoked from <2% of the rendering loops, could I really be driving SceneKit to its limits?

2) if so, are there any SceneKit tricks to clawing back some CPU? Can the delegate call rate be slowed, for example?

This is with macOS 10.12.3 and Xcode 8 (Swift 3) on a 2.8GHz/i7 2015 MacBook Pro

Upvotes: 2

Views: 895

Answers (2)

sambro
sambro

Reputation: 816

How about trying to flatten the nodes and it's children using flattenedClone.

Upvotes: 2

Hal Mueller
Hal Mueller

Reputation: 7646

Creating SCNLevelOfDetail objects for your geometries is worth a try.

Is anything else moving? Can you reduce your view's preferredFramesPerSecond?

Upvotes: 1

Related Questions