optimized cache management when switching between routes
Description
Closes https://github.com/mapbox/mapbox-navigation-android/issues/6138 by trimming the route parsing cache to the size of the new collection of routes, instead of clearing it entirely. This still correctly evicts the route references when they are intentionally cleared while keeping the cache when routes are switched. Additionally, filters out duplicates by NavigationRoute#id to not allow them to impact the size of the cache.
For a route from Munich to Madrid, on Samsung S22+, I see the execution time of MapboxRouteLineApi#setNavigationRoutes when switching between alternative routes decreasing from ~140ms to ~25ms.
Codecov Report
Merging #6171 (28a0023) into main (28a0023) will not change coverage. The diff coverage is
n/a.
:exclamation: Current head 28a0023 differs from pull request most recent head 32495be. Consider uploading reports for the commit 32495be to get more accurate results
@@ Coverage Diff @@
## main #6171 +/- ##
=========================================
Coverage 68.86% 68.86%
Complexity 4256 4256
=========================================
Files 639 639
Lines 25666 25666
Branches 3004 3004
=========================================
Hits 17676 17676
Misses 6845 6845
Partials 1145 1145