Swift Playgrounds on MacOS performs badly, spinning up the fans and working the CPU

performanceswift

Using the basic "Learn to Code 1" playground results in the MacBooks that I've tested on, including a 2020 MacBook Air, working far harder than I'd expect. The fans spin up and the CPU usage increases more than I'd expect.

The performance settles down if I leave the application running, I see the high load whenever I type and change the program.

The app is compiling some Swift code and displaying a fairly simple game interface to show the results. What can account for this poor performance on a capable machine?

Best Answer

Every time you change source code within the game (every time you add a new line of code), Swift Playgrounds is writing files to locations like /Users//Library/Containers/com.apple.PlaygroundsMap

These are synchronised with iCloud. It's this that's causing the performance problem. Processes like "bird", related to the iCloud sync, show up in Activity Monitor and can be seen interacting with files using terminal utility fs_usage.

Apple's site says:

https://developer.apple.com/swift-playgrounds/ "iCloud Drive seamlessly shares your playgrounds, and changes you make on either iPad or Mac immediately appear on your other devices."

Switching this feature off solves the problem. Go to System Preferences and search for iCloud (or go directly into the Apple ID screen and select iCloud). Then go into iCloud "Options..." and remove the check next to Swift Playgrounds.

You will need to re-download the playgrounds.

iCloud Options in System Preferences

Remove check next to Swift Playgrounds in iCloud Options