Swift and Watch Performance Improvements
14 Apr 2016One slightly strange and irritating issue with Count The Days Left is the app has a small but noticeable delay on startup.
I added a ton of instrumentation to help figure out what was going on, and was then able to make some micro-improvements which have helped a little. However this small decrease in loading time makes the app FEEL a lot quicker on startup.
Changes made:
- Move the Watch communication initialization code off a background queue onto the main thread
- Removed an additional and unnecessary call to update the badge number
- Moved updating of control settings into viewDidAppear() from viewWillAppear()
- Optimised watch app view updating logic to do minimum work necessary
The first point was unexpected, but after measuring the actual speed of the code the overhead of spinning up a new thread and running code in parallel was not actually worth doing. As ever, measurement trumps expected outcomes.
The third point clearly didn’t really any difference to the amount of code to be run, but perception is all and it feels a little faster.
The final point is obvious - the Apple Watch is very underpowered, so doing the absolute minimum amount of work at all times is essential.
Summary
The startup time is still a little slow - and my unproven suspicion is that Swift apps take a little longer to initialise in general anyway - but I’m a lot happier with it now.
As ever, more details can be found on the GitHub repository where all the code for the app lives.
I’ve just submitted v2.0.3 to the App Store for review, so unless we have any shenanigans as before hopefully it will be available in the next few days.