Swift Playgrounds on MacOS performs badly, spinning up the fans and working the CPU
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.