-
Notifications
You must be signed in to change notification settings - Fork 1.3k
iOS user tracking mode = follow leads to excessive CPU usage #7236
Comments
This issue has been automatically detected as stale because it has not had recent activity and will be archived. Thank you for your contributions. |
Hello, do you plan to include a fix for this issue in one of the next releases? |
I'd like to point out that the same issue in the Android SDK is caused by the heavy usage of the compass component. this Might be related? |
I'm testing version 4.10.0 on an iPhone X iOS 12.2, seems that we have spikes but profiling with instruments some are related to the core libraries but goes down immediately. The larger spikes in this chart are me playing with zooming in/out. @racer1988 could you please post a screenshot of what you are seeing. |
@fabian-guerra This is my graph when changing the map TrackingMode the issue seems to be identical to the one that the reported initially raised. Unfortunately I can't profile on the device and go around to reproduce the same. Just by profiling and tracking user location I can see the map spiking to 50% and most of the usage is due to MapBox rendering: I guess following user location is triggering re-rendering on the map somehow in a heavy way. The usage of the total CPU cores in Xcode is around 50%, where Thread 1 is stuck at 100%. Doing the same exact test with Mapkit sets the thread around 7/8 % |
@racer1988 which map's SDK version are you testing? What's the device? |
Tested with both 4.9 and 4.10 the same is visible on the simulators if using a GPX track to reproduce the location |
I currently don’t have access to my laptop. I don’t have a existing app, If it can help, I am hosting the map in a child view controller that is then included in the main one. Not sure how this is relevant, but might have different layout passes than a direct use of the map |
@julianrex @fabian-guerra I stripped down my production code to a basic map and I am able to reproduce in 100% of the cases. You can find the code and reproduce yourself from here: https://github.com/racer1988/mapboxIssue Important Notes:
How to reproduce:
you can see the same behaviour reported by me and @danpat : The TrackingMode button is the following one: |
@racer1988 thanks so much for providing a test case! |
Hi, @racer1988. Thank you for the test app. It seems that this is related to the You can modify the file changing the time as it's suggested here: https://stackoverflow.com/a/36416589/1919929 In case you need, we have an API that will let you simulate location updates: https://docs.mapbox.com/ios/api/maps/4.10.0/Location%20Updates.html and an example on how to implement it is in: https://github.com/mapbox/mapbox-gl-native/blob/master/platform/ios/app/MBXCustomLocationViewController.m |
@fabian-guerra Even at 4-5hz, if there's no map being rendered, what on earth is eating up all the CPU time? Why are location updates so CPU intensive if there's nothing to render? |
@danpat I'm still researching this issue. Location management technology is cpu intensive. That being said don't know if Apple has some sort of optimizations for |
@fabian-guerra the same behaviour in spike of CPU happens even with a fixed location when the tracking is set to follow and the map is slowly zoomed from level 1 to the max zoom level. There the issue looks the same, however the cause can't be the location updates, as there are none. |
@racer1988 a fixed location in a |
Without having any knowledge of this specific issue, one optimization that @LukasPaczos implemented on Android seems worth investigating on iOS — #13678 — the idea being that we attempt to update the user location too frequently and for no real/visible benefit. |
@fabian-guerra 2 more points here for your investigation:
You can simulate the issue two ways:
Even with this simple case, the CPU spike is the same (eats 100% Thread), the inspector shows the same issue (see image at the bottom) This is a simple case of a user wanting to zoom to his location.
To simulate, start the GPX file, start following the user, then slighly pan away, to fallback to tracking None. When the location annotation is in the viewPort, but the tracking is set to NONE, the CPU is at 0% as soon as you set the mode to
This point IMHO that the issue is not with the location updates, but with the update of the region in the viewPort |
@racer1988 I did tried with a single coordinate In my comment #7236 (comment) I posted how using our custom api to simulate updates it's almost unnoticeable. Thanks for the info I will continue researching. Considering as well if we can try what it was implemented on Android as described in this comment #7236 (comment) |
The intensive CPU usage is due to two main factors: Location update frequency: Xcode does not allow set a frequency update for Rendering frequency: As is already pointed in this comment #7236 (comment) A workaround is change the location update frequency to let the cpu finish the job. In this pr #14577 I'm exploring another platform level optimization. In the pr I added a point based threshold that will move the camera thus triggering the render engine once the This is how it looks with a 20point threshold, and using the In conclusion I suggest change the location update frequency. |
Has there been any progress on this? We're running into this with a turn by turn issue (using react-native-mapbox-gl) |
bump to this. not only user tracking is affected, but |
Also experiencing crash logs due to excessive cpu usage during turn-by-turn navigation:
|
any updated on this? |
I'm seeing this in a React Native app too, but interestingly, I'm also seeing the exact same behaviour in a pure SwiftUI app. |
Platform: iOS
Mapbox SDK version: 3.4.0-beta.4
Steps to trigger behavior
mapView.setUserTrackingMode(.follow, animated: true)
The value of
animated:
does not seem to have an effect on CPU usage.true/false
both lead to one pegged core.Small video showing the CPU changes with tracking mode changes with the iOS simulator:
https://www.youtube.com/watch?v=_71Hoz_7neA&feature=youtu.be
Expected behavior
Animating the map to follow the user marker shouldn't consume an entire core.
Actual behavior
My phone gets really hot and the battery drains quickly. My wife gets angry that she can't call me because my phone is dead. I get lost in the wilderness because I no longer have maps.
The text was updated successfully, but these errors were encountered: