Why is MapKit CPU usage higher with SwiftUI than AppKit?

I've copied a couple of tutorial Mac OS apps using MapKit. One uses SwiftUI, the other AppKit. Both initially display a map and allow the user to pan and zoom with the mouse. According to XCode's debug navigator, once the user has stopped panning or zooming, the CPU usage goes to 0%.

Both apps allow the user to enter a location and add a MapAnnotation to the map.

On the AppKit version, once the annotation is added, the CPU usage drops back to 0%, but on the SwiftUI version, the CPU usage remains around 5 - 15%. If you look closely at the SwiftUI version, you can see the annotation vibrating by a pixel or so on the display. It seems to me that the display is being constantly updated.

If the annotation is removed, the CPU usage goes back to 0%

I placed a breakpoint in the code that draws the annotation in the SwiftUI version. When adding an annotation, the breakpoint is hit twice, but then no more, so I don't think the CPU is spending time in the Swift code.

  • Xcode 13.3.1
  • OSX Monterey 12.3.1
  • Mac Mini M1
Why is MapKit CPU usage higher with SwiftUI than AppKit?
 
 
Q