flutter-mapbox-gl / maps

A Mapbox GL flutter package for creating custom maps
Other
1.04k stars 503 forks source link

Mapbox causes battery drain and overheating when myLocationEnabled == true. #1225

Closed irjayjay closed 1 year ago

irjayjay commented 1 year ago

Our app has been reported to heat up users' phones, so a few of us tested the app out in the wild and sure enough, the app heats up our phones and causes massive battery drain.

I started investigating and found the culprit: with myLocationEnabled on, it uses 90% of my GPU and 50% CPU. When I turn it off, it uses 0% GPU and 20% CPU.

Compared this to GMaps that while navigating only uses 30% CPU and 30% GPU while moving the entire map and updating its puck.

I tested more and found that if I zoomed in close enough to where no streets or other geometry had to render since I'm focusing on a building or block, the GPU % drops significantly. This leads me to believe that Mapbox is redrawing the entire visible portion of the map for each frame while the location puck is being updated.

Hacked the plugin to do a setMaxAnimationFps to 1. GPU usage dropped to about 60%, but still way too high.

Any ideas what else I can do to lower the battery drain or prevent the entire map from re-rendering just to update the puck?

PhilippMatthes commented 1 year ago

Have you double checked that this is not caused by the hereby enabled GPS? GPS is one of the biggest energy consumers in a smartphone.

stale[bot] commented 1 year ago

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

irjayjay commented 1 year ago

@PhilippMatthes, yeah, since I took GPU and CPU readings, shown in my original post above. GPU/CPU shouldn't be affected by whether the GPS is being used or not. Phones also don't overheat because of GPS either.

GPS uses minimal power in modern devices. The usual culprit nowadays is the screen backlight, or in rare cases, like in games, CPU/GPU being kept busy.

It's definitely the location puck somehow causing the entire map to redraw every frame. When zooming in to where there's no detail visible, it uses way less GPU than when there's more geometry shown at lower zoom levels.

I built a custom location puck to get around this. It only redraws when absolutely necessary. CPU now averages 20% and GPU 15% with the custom puck.

PhilippMatthes commented 1 year ago

Thanks for elaborating. Hit me up if you want to share your solution or open a PR, this could help us as well in reducing the energy impact/fps in our app.

stale[bot] commented 1 year ago

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.