Exploring SwiftUI Apple Watch Performance

I’m deep in the midst of a major new project for the Apple Watch. We got a whole host of new capabilities in watchOS 6 and I’ve been feverishly working on trying to take full advantage of them. By far the most significant thing added in watchOS 6 was the addition of SwiftUI, which allows for full, proper animations.

Previously WatchKit only allowed for crude animations that involved creating a series of pre-rendered animation frames and then displaying them in sequence to the user. Now with SwiftUI we can do actual animation that fluidly transitions from one state to another.

If you’ve used Geneva Moon you have seen this in action. Turn the digital crown and see how the moon can smoothly move through the night sky.

For my next project I’m hoping to do things that are a bit more ambitious than simply moving a single image across the screen. I want to be able to create interfaces that are lively and interactive. So I set out to explore the limits of SwiftUI, and especially its performance on the Series 2 Apple Watch (as it is the slowest supported device).

The idea I came up with was to create a little game of circular Pong, where you use the digital crown to rotate your paddle around the screen. This serves as a good test case as it requires the ball to move fluidly across the screen while concurrently, and interactively, shifting the paddle around to meet it. (It was also just a lot of fun to make)

I built this entirely using SwiftUI and the result was very promising. The interaction is fluid and the animations are smooth. This performance honestly feels like it exceeds using SpriteKit on watchOS, which previously was the only way to approximate this kind of visual experience. I’ve gone down this road before and the results were workable, but using SpriteKit comes with a whole host of problems that SwiftUI avoids.

Of course the next thing I had to do was to crank up the game to really see where the limits are reached. So I made an alternative version that kept adding new balls to the play area until things were visually slipping. Getting Instruments to reliably connect to an Apple Watch is a difficult thing, so instead I just eye-balled when it seemed the FPS started to fall. On a Series 5 Apple Watch this didn’t happen until around 400 balls. For a Series 2, this happened at 60 (which is significantly lower, but still workable for what I have in mind).

Overall I’m very encouraged by these results, as they open up a wide world of possibilities.

David Smith