Reputation: 113
I'm profiling my app and finding that Google Maps (v2.0.1) for iOS is pegging the CPU when creating more than 840 markers on the map. As soon as I create that 841st marker, CPU peg about 98%.
func loadMarkers() {
if(mapView != nil) {
let objects = objectAPI.getObjects()
for (index, object) in objects.enumerate() {
let marker = GMSMarker()
marker.snippet = object.title
marker.position = CLLocationCoordinate2D(latitude: object.lat.doubleValue, longitude: object.lng.doubleValue)
marker.icon = GMSMarker.markerImageWithColor(UIColor.redColor())
marker.map = mapView
}
}
The trace shows that it's performance is killed in EntityRenderer::Draw. Why random 840 markers? If I render 840 markers or less, then no problem. Same behavior on Simulator and 6s Plus device.
Running Time Self (ms) Symbol Name
422370.0ms 98.5% 5.0 -[GMSDisplayLink displayLinkFired:]
422364.0ms 98.5% 7.0 -[GMSEntityRendererView draw]
422351.0ms 98.5% 0.0 -[GMSPhoenixRenderer drawIfNeeded]
422331.0ms 98.5% 341.0 gmscore::renderer::EntityRenderer::Draw(bool)
213215.0ms 49.7% 1373.0 (anonymous namespace)::StickerBehavior::Commit(gmscore::renderer::EntityRenderer*)
186073.0ms 43.4% 17786.0 (anonymous namespace)::StickerBehavior::SelectFrame(UIImage*, double, double)
Upvotes: 3
Views: 1392
Reputation: 113
The solution to this performance problem is to reuse the uiimage for marker icon:
let objects = objectAPI.getObjects()
let markerImage = GMSMarker.markerImageWithColor(UIColor.redColor())
for (index, object) in objects.enumerate() {
let marker = GMSMarker()
marker.snippet = object.title
marker.position = CLLocationCoordinate2D(latitude: object.lat.doubleValue, longitude: object.lng.doubleValue)
marker.icon = markerImage
marker.map = mapView
}
Upvotes: 1