Issue #412

  • Google Maps with a lot of pin, and no clustering can have bad performance if there are complex view in the marker.
  • The workaround is to use manual layout and rasterization

shouldRasterize

When the value of this property is true, the layer is rendered as a bitmap in its local coordinate space and then composited to the destination with any other content. Shadow effects and any filters in the filters property are rasterized and included in the bitmap. However, the current opacity of the layer is not rasterized. If the rasterized bitmap requires scaling during compositing, the filters in the minificationFilter and magnificationFilter properties are applied as needed.

In the class PinView: UIView

isOpaque = true
layer.shouldRasterize = true
layer.rasterizationScale = UIScreen.main.scale

final class StopMarker: GMSMarker {
    let stop: Stop
    private let pinView = PinView()

    init(stop: Stop) {
        self.stop = stop
        super.init()
        self.position = stop.toCoordinate()
        self.iconView = pinView
    }
}

Read more

When your app needs to draw something on the screen, the GPU takes your layer hierarchy (UIView is just a wrapper on top of CALayer, which in the end are OpenGL textures) and applies one by one on top of each other based on their x,y,z position. In regular rendering, the whole operation happens in special frame buffers that the display will directly read for rendering on the screen, repeating the process at a rate around 60 times per second.

Of course the process have some drawbacks as well. The main one is that offscreen rendering requires a context switch (GPU has to change to a different memory area to perform the drawing) and then copying the resulting composited layer into the frame buffer. Every time any of the composited layers change, the cache needs to be redrawn again. This is why in many circumstances offscreen rendering is not a good idea, as it requires additional computation when need to be rerendered. Besides, the layer requires extra video memory which of course is limited, so use it with caution.