mapbox / mapbox-maps-android

Interactive, thoroughly customizable maps in native Android powered by vector tiles and OpenGL.
https://www.mapbox.com/mobile-maps-sdk
Other
476 stars 133 forks source link

Adding a circle annotation every 100 msec causes significant performance issues #1319

Closed crroush closed 2 weeks ago

crroush commented 2 years ago

Environment

Observed behavior and steps to reproduce

We are running an instance of mapbox 10.4.0, using the circleAnnotationManager to display lat/lon points on the map. There is a kotlin sharedflow that delivers and ingests the data and makes it available to the viewmodel for displaying on the map. The data is coming in at a rate of 100 msec a point. Watching the profile in Android studio it shows that GEOJSON_PARSER is eating up nearly 50+% of the available resources. This makes the map unusable.

image

This image from the Android Studio profiler shows what appears to be taking what is passed through the circleAnnotationManager, converting it to geojson, then doing an http post internally (maybe between the java and native side?) and I assume it must be converting it back from geojson on the native side? This sequence happens every time a new point is added to the circleManager.

This is how I am creating my CircleAnnotationOptions:

fun getCircleAnnotation( point: Point, color: Color, radius: Double = 8.0): CircleAnnotationOptions{
    return CircleAnnotationOptions()
        .withPoint(point)
        .withCircleColor(color.toArgb())
        .withCircleStrokeColor(color.toArgb())
        .withCircleRadius(radius)
}

Then I add the circle using the circleAnnotationManager:

 circleManager.create(circleAnnotationOptions)

Expected behavior

Notes / preliminary analysis

Additional links and references

Chaoba commented 2 years ago

Can you try to cache the annotations and add them with create(options: List<S>)? For example, adding 10 annotations every time.

crroush commented 2 years ago

@Chaoba I have done that, which helps a little. I was hoping there was some way to either bypass the geojson parser and get an pass the annotation directly to the native side.

ZiZasaurus commented 2 years ago

@crroush are you still experiencing this behavior on our most recent release, v10.9.1?

kiryldz commented 2 weeks ago

Closing as stale. Noting that if you need to apply some annotation property to all annotations - since v11.7.X it is possible to do so by applying this property to the annotation manager directly. Doing so (instead of styling every annotation individually) will result in much better performance.