mapbox / mapbox/mapbox-navigation-android
Inefficient use of MapboxRouteLineApi cache for restricted sections
Nessuno ha ancora preso questa issue.
- Lingua principale
- Kotlin
- Stelle
- 651
- Fork
- 321
- Metriche di merge delle PR
- Nessuna PR unita negli ultimi 30g
Descrizione
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<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
Guida per i contributori
Apri la guida per i contributori
Come iniziare
- Leggi tutta la issue e poi la guida ai contributi del progetto.
- Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
- Fai un fork del repository e lavora su un branch.
- Apri una pull request che faccia riferimento al numero della issue.
Direzione di ricerca
Inizia in MapboxRouteLineApi.kt, in updateTraveledRouteLine e setNavigationRoutes, quindi esamina MapboxRouteLineUtils.kt, dove ExtractedRouteData viene memorizzato nella cache. Mantieni localmente i dati della route estratti in MapboxRouteLineApi e aggiornali quando le route vengono ridisegnate, in modo che gli aggiornamenti del punto di fuga non debbano più ricalcolare l'hash della route, costoso, né eseguire la ricerca nella cache.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Valutazione
- Stack tecnologico
- android, kotlin
- Ambito
- mobile-dev, performance
- Tipo di issue
- Refactoring
- Difficoltà
- 3/5
- Tempo stimato
- 1-2 giorni
- Stato di attività
- Ferma
- Chiarezza
- Specificata chiaramente
- Idoneità per principianti
- 38/100