mapbox / mapbox/mapbox-navigation-android
Inefficient use of MapboxRouteLineApi cache for restricted sections
Nadie ha tomado este issue todavía.
- Lenguaje dominante
- Kotlin
- Estrellas
- 651
- Forks
- 321
- Métricas de merge de PR
- Sin PR fusionados en 30 d
Descripción
Whenever the `MapboxRouteLineApi` needs to update the vanishing point (`MapboxRouteLineApi#updateTraveledRouteLine`), `MapboxRouteLineOptions#styleInactiveRouteLegsIndependently` is enabled, and the route goes through a visualized restricted section, the API needs to extract the full parsed route object to create the gradient expression for the restricted sections:
https://github.com/mapbox/mapbox-navigation-android/blob/d8d04fe75e53063f5e185c3779c04c7b0914f77d/libnavui-maps/src/main/java/com/mapbox/navigation/ui/maps/route/line/api/MapboxRouteLineApi.kt#L463-L470
This parsed data is already cached in
https://github.com/mapbox/mapbox-navigation-android/blob/d8d04fe75e53063f5e185c3779c04c7b0914f77d/libnavui-maps/src/main/java/com/mapbox/navigation/ui/maps/internal/route/line/MapboxRouteLineUtils.kt#L67-L72
however, the key of this cache is based on the hash of the full `DirectionsRoute`, which makes computing the key very expensive for long routes.
While this is not as problematic when routes are re-drawn (for each `MapboxRouteLineApi#setNavigationRoutes`), it is extremely unsuitable for very frequent updates of the vanishing point with `MapboxRouteLineApi#updateTraveledRouteLine`. This cache lookup on a route from Munich to Madrid can take more than 20% of the main thread's time on a rather powerful Samsung S22+, and on other hardware can even occasionally lead to ANRs if the frequency of the location indicator updates is high enough to flood the main thread.

During the vanishing updates, they cache element is not possible to be changed, so instead of extracting the value from the cache on each update, we should store the `List` locally in `MapboxRouteLineApi` and refresh it whenever routes are re-drawn. We already follow the same practice with the `List`:
https://github.com/mapbox/mapbox-navigation-android/blob/d8d04fe75e53063f5e185c3779c04c7b0914f77d/libnavui-maps/src/main/java/com/mapbox/navigation/ui/maps/route/line/api/MapboxRouteLineApi.kt#L199
cc @cafesilencio @abhishek1508
Guía de contribución
Primeros pasos
- Lee el issue completo y luego la guía de contribución del proyecto.
- Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
- Haz un fork del repositorio y trabaja en una rama.
- Abre un pull request que haga referencia al número del issue.
Línea de trabajo
Empieza en MapboxRouteLineApi.kt, en updateTraveledRouteLine y setNavigationRoutes, y después inspecciona MapboxRouteLineUtils.kt, donde se almacena en caché ExtractedRouteData. Mantén los datos de ruta extraídos localmente en MapboxRouteLineApi y actualízalos cuando se vuelvan a dibujar las rutas, para que las actualizaciones del punto de fuga ya no vuelvan a calcular el costoso hash de la ruta ni a consultar la caché.
Escrito por el modelo de indexación a partir del texto del issue.
Evaluación
- Stack tecnológico
- android, kotlin
- Área
- mobile-dev, performance
- Tipo de issue
- Refactorización
- Dificultad
- 3/5
- Tiempo estimado
- 1-2 días
- Estado de actividad
- Estancado
- Claridad
- Bien especificado
- Aptitud para principiantes
- 38/100