One of the more surprising announcements at WWDC2020 was the move from Intel to Apple Silicon. In this article, I want to look at how it will affect us humble developers. How will we be able to take advantage of the new hardware?

During this WWDC2020 video on the subject, the presenter (Gavin Barraclough) goes over some of the differences between Intel-based and Apple Silicon-based Macs and answers my question to an extent. Let’s dig a little deeper into his recommendations.

One of the principal points he made was the fact that the new Macs based on Apple Silicon will be using a single system on a chip or SoC. The SoC itself is an asymmetric multiprocessing unit that is different from Intel’s, as displayed in this image taken from that presentation:

Image for post

Symmetric cores vs. asymmetric cores

The emphasis is on designing hardware that will be able to run apps requiring less CPU more efficiently whilst retaining the performance required for more CPU-intensive ones. In the presentation, Gavin goes over the sort of frameworks and formats you need to focus on to take full advantage of the new SoC. Frameworks like these named specifically are designed to take advantage of multiprocessing cores:

Image for post

Apple frameworks already AMP-tuned

There is obviously far too much to cover in any detail here, and with that in mind, I want to focus on what you can do to manually optimise your app to run on asymmetric multiprocessing Apple SoC hardware — optimisation that I suspect you’re already doing.

You see, Swift has been taking advantage of this sort of architecture for some time with a system called GCD or Grand Central Dispatch.

Focusing AMP hardware with GCD centres around using QoS. There are four levels of QoS in Swift that Apple have defined, illustrated here in the WWDC2015 slide on the subject:

Image for post

By default, the main thread (User Interactive) is always running at top priority. Threads dispatched from it run as User Initiated. Nothing runs as Utility or Background unless you specify it to do so. Let’s do a review of what that looks like.

To make sure we’re not comparing apples to oranges, I am going to read in a file of 48,000 lines, noting when I start and when I complete.

I’ve provided a very simple animation to show what is happening. The GIF below illustrates the effect. When I start the demo app, the start time shows on both uploads. As the data loads, the UI is updated on the thread running the upload as a background thread. With the upload running on the same thread as the UI, it doesn’t give us any update until it is finished. The code to push a thread to the background looks like this:

DispatchQueue.global(qos: .background).async { 
  //background thread
}

#apple-silicon #xcode #ios #programming #macos

Apple Silicon App Developer
1.45 GEEK