mapbox / mapbox/mapbox-navigation-android

History player crash when reading large history files

Open
#2,833 2 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Kotlin
Stars
651
Forks
321
PR merge metrics
No merged PRs in 30d

Description

**Mapbox Navigation SDK version:** 1.0.0

### Steps to trigger behavior

1. Load the large sensor [data history file](https://firebasestorage.googleapis.com/v0/b/driver-efb37.appspot.com/o/history%2Fandroid%2F509a527ba87021d4%2F2020-04-22%2021%3A15%3A13_2020-04-22%2021%3A31%3A51_5e9eb7f5-615a-410b-abe1-a55f097097f6.json6752346270703539633.json?alt=media&token=43a6fdb0-cfc9-4777-b9af-64f831f113a2)
2. Add this file to the [examples asset folder](https://github.com/mapbox/mapbox-navigation-android/tree/master/examples/src/main/assets)
3. Reference the new [json file in the ReplayHistoryActivity](https://github.com/mapbox/mapbox-navigation-android/blob/acea8690e2c98446f53ab8ee3ef539a4c12e93a8/examples/src/main/java/com/mapbox/navigation/examples/core/ReplayHistoryActivity.kt#L118)
4. Launch the ReplayHistoryActivity example

### Actual behavior
💥 It will run out of memory

### Expected behavior
The large [files are loaded as a JSON string](https://github.com/mapbox/mapbox-navigation-android/blob/acea8690e2c98446f53ab8ee3ef539a4c12e93a8/examples/src/main/java/com/mapbox/navigation/examples/core/ReplayHistoryActivity.kt#L276-L281). When doing this it creates a copy in memory and causes an `OutOfMemoryError`

```
java.lang.OutOfMemoryError: Failed to allocate a 55805472 byte allocation with 25165824 free bytes and 28MB until OOM, target footprint 196105960, growth limit 201326592
```

#### Approaches
- Read json files and decode the history byte by byte. Pumping new events into the history player.
- When uploading history files with sensor data, create a timer that uploads every < 10 minutes to reduce the file sizes
- Change the format of the history file to a compressed format like Proto

From these approaches, uploading history files in chunks seems like the quickest solution.

cc: @mskurydin @Guardiola31337 @a-kosak-mbx

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with examples/src/main/java/com/mapbox/navigation/examples/core/ReplayHistoryActivity.kt, especially the JSON loading at lines 276-281, and reproduce the failure using the linked large history asset. Trace how the file is passed to the history player and verify that the large file no longer causes an OutOfMemoryError when the example runs.

Written by the indexing model from the issue text.

Assessment

Tech stack
android, kotlin
Domain
mobile, performance
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.