mapbox / mapbox/mapbox-navigation-android

Inefficient use of MapboxRouteLineApi cache for restricted sections

Ouverte
#6,167 1 commentaire 0 réactions 0 personnes assignées Voir sur GitHub

Personne n'a encore pris cette issue.

improvement jira-sync-complete UI
Langage dominant
Kotlin
Étoiles
651
Forks
321
Métriques de merge des PR
Aucune PR mergée en 30 j

Description

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.
Screenshot from 2022-08-15 12-47-47

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<ExtractedRouteData> locally in MapboxRouteLineApi and refresh it whenever routes are re-drawn. We already follow the same practice with the List<RouteLineExpressionData>:
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

Guide de contribution

Ouvrir le guide de contribution

Par où commencer

  1. Lisez l'issue en entier, puis le guide de contribution du projet.
  2. Signalez en commentaire que vous la prenez — cela évite que deux personnes fassent le même travail.
  3. Forkez le dépôt et travaillez sur une branche.
  4. Ouvrez une pull request qui référence le numéro de l'issue.

Piste de recherche

Commencez dans MapboxRouteLineApi.kt, au niveau de updateTraveledRouteLine et setNavigationRoutes, puis examinez MapboxRouteLineUtils.kt, où ExtractedRouteData est mis en cache. Conservez localement les données de route extraites dans MapboxRouteLineApi et actualisez-les lorsque les routes sont redessinées, afin que les mises à jour du point de fuite ne recalculent plus le coûteux hash de route ni la recherche dans le cache.

Rédigé par le modèle d'indexation à partir du texte de l'issue.

Évaluation

Stack technique
android, kotlin
Domaine
mobile-dev, performance
Type d'issue
Refactorisation
Difficulté
3/5
Temps estimé
1-2 jours
Activité
À l'abandon
Clarté
Clairement spécifiée
Accessibilité débutants
38/100

Recevez les nouvelles issues par e-mail

Un résumé court des issues GitHub adaptées aux débutants.