mapbox / mapbox/mapbox-navigation-android

Inefficient use of MapboxRouteLineApi cache for restricted sections

未关闭
#6,167 1 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看

还没有人认领这个 Issue。

improvement jira-sync-complete UI
主要语言
Kotlin
星标
651
派生
321
PR 合并指标
30 天内没有已合并 PR

描述

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](https://user-images.githubusercontent.com/16925074/184624176-117a3615-5c46-4554-8281-52117e319ff2.png)

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

贡献指南

打开贡献指南

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

调研方向

从 MapboxRouteLineApi.kt 中的 updateTraveledRouteLine 和 setNavigationRoutes 开始,然后检查 MapboxRouteLineUtils.kt,其中会缓存 ExtractedRouteData。在 MapboxRouteLineApi 中本地保存提取出的路线数据,并在路线重新绘制时刷新这些数据,这样消失点更新就不再需要重新计算开销很大的路线哈希和缓存查找。

由索引模型根据 Issue 内容生成。

评估

技术栈
android, kotlin
领域
mobile-dev, performance
Issue 类型
重构
难度
3/5
预计耗时
1-2 天
活跃度
停滞
描述清晰度
描述清楚
新手友好度
38/100

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。