Best way to integrate large number of icons with MapKit (Apple Maps)

I'm developing an iOS app that displays store locations on a map using Apple Maps (MapKit). I've limit the number of icons that can be displayed on the map to 100, but there's still huge performance issues and the app is very laggy even on modern iPhone models. What's the best practice when displaying a large number of icons on a map, should the icons be in PNG format with a small resolution (~10kb) or should the icons be vector (SVG) for best performance? Should I use the MapKit framework for iOS 17 or the UIKit approach?

A large number of images can always be a performance challenge. First, you should dig into where the performance challenge is actually appearing and then make the best decision given that. To do this, I would trace your interaction using Instruments. (See Explore UI animation hitches and the render loop and its two companion talks about commits and render hitches and how to fix them)

From there, you are likely to see one of a few things:

  1. Latencies due to image loading

PNG is a compressed format that is decoded entirely in software. You may explore JPEG or HEIC which should decode faster. (See Make blazing fast lists and collection views for some information on how images work) But more then that, you may realize you are doing it too often. You may want to keep a cache of CGImage/UIImages that you already have setup to avoid redoing that decoding work.

  1. Issues around MapKit commits

MapKit might be struggling with how many elements you have. Consider using Clustering which should help.

  1. Downstream impacts of too much memory

This is less likely. But if you see that your app is spending a lot of time allocating memory you may realize it's because your app is using too much. In that case, you may consider how you are loading the images. SVG in that case might be cheaper, but I'd say you should trace it in Instruments to be sure.

Once you've tried those, let me know what you find!

Should I use the MapKit framework for iOS 17 or the UIKit approach?

MapKit has been around for a while. You may mean the new MapKit SwiftUI interface versus the UIKit one. You can experiment with either. I don't necessarily think one or the other would limit your performance. But you may find in SwiftUI you have other performance issues which are making the Map invalidate more often. (See Demystifying SwiftUI Performance)

Best way to integrate large number of icons with MapKit (Apple Maps)
 
 
Q