You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository was archived by the owner on Aug 8, 2023. It is now read-only.
Repository navigation
This repository was archived by the owner on Aug 8, 2023. It is now read-only.
archivedArchived because of inactivityiOSMapbox Maps SDK for iOSnavigationFor the Mapbox Navigation SDK for Android or iOS or navigation use cases in generalperformanceSpeed, stability, CPU usage, memory usage, or power usage
See background in #2922 (comment). Makes sense that as the CADisplayLink always ticks, we'd be using resources to decide if a frame needs rendered or not, even when idle.
This change seems to cause a constant (but low) CPU usage
So, I admit I haven't measured this, but the CPU usage should be extremely minimal. Remember that when the CADisplayLink wakes up all it has to do is check a boolean. It's not checking for whether we should render at that moment. And the CADisplayLink run loop mechanism is always running anyway; we're merely adding, at most, about one method call and maybe two or three instructions. It would be difficult to even measure the impact.
@adam-mapbox on Intel architectures that I'm more familiar with, it definitely would have an impact because that would prevent the CPU from going to a "deep" C-State. But anyway, it is just a quirk if not measured.
The way I've used a CADisplayLink in the past is to start it on some kind of user interaction, and then let it remove itself when all its work is complete. Maybe that's an option here?
@tomtaylor There are so many different entry points for "interaction" here — gestures, but also programmatic/animated viewport changes, implicit changes for things like user dot tracking, etc.
If we can confirm that we had 0% battery usage when idle previously, and that we don't now, we should fix that.
Prior to #2922, on my 64 GB iPhone 6 running iOS 9.1, iosapp was stable at 0% CPU usage and 2 fps. As of 7288473, it’s at 1–2% CPU usage and 3 fps. This is with iosapp in portrait showing the world map at z0 with the Streets style and no user dot.
Building on @tomtaylor's thoughts, a naive approach that might work here is to observe app foreground/background state and suspend the CADisplayLink as a result. But in past we've had rendering issues such as return to foreground with black map and app crashing in background, and we might run into similar things with such an approach as well.
Either way, I think we can move this off of the 3.0.0 milestone since this is only for app foreground mode and continue to experiment given the upside of much better rendering performance.
If it is pan-tossed, camera-animated, or anything that doesn't tie to direct manipulation, the frame render callback doesn't fire, which doesn't call -updateAnnotationViews.
I’ve been assuming that having mbgl drive updates was best, because mbgl has the most context about when a redraw is needed (camera transitions, property transitions, etc.). But mbgl doesn’t know anything about Core Animation. 🤔
Ok, pushed my WIP to 2985-jrm-wip (commenting out CADisplayLink routines so that we can easily compare where it was used formerly).
As far as I can tell, the actual transplantation of removing CADisplayLink is fairly trivial, as per that diff.
The problems that crop up are related to the user and normal annotation views. Easy way to replicate:
User: Have the user dot on screen. Contrast moving the map with your finger (works fine) with tossing the map to coast to a stop (dot freezes until pan is complete).
The visual update routine seems to be called properly on each frame draw, so my hypothesis here is that the UIView animation block in -updateUserLocationAnnotationViewAnimatedWithDuration: is somehow hanging or not moving forward during these pans.
Normal: Choose Add 100 Views from the gear menu. Observe that they track properly. Then, tap the tracking mode button and (assuming you are not also in DC) as the viewport changes, the annotations eventually freeze on screen despite being way out of view until the fly animation ends. Again, the update routine seems to be called each frame.
Hypothesis: we don't actually ever remove annotation views from the hierarchy until the annotations are removed, we just skip updating their positions. This is catching up with us now for some reason. I'm not yet sure why they sync up properly at the end; possibly because they don't exist in offscreenAnnotations as they should until the final pass.
Part of me also wonders if the fact that CADisplayLink is part of Core Animation, if, as @1ec5 suggests in #2985 (comment), it causes some sort of Core Animation render buffer flush which keeps views/layers in sync properly. Something that we get for free with CADisplayLink that we might have to manage manually in future.
At the very least, removing CADisplayLink aggravates the annotation view lag we've seen before because -updateAnnoationsViews is only called after a frame is rendered and not every screen refresh as with the display link. This makes it look like the views are lagging, when in fact they are crisply updating but our <60FPS map is not.
Even if removing CADisplayLink doesn’t address the jittering, we know it contributes to increased power usage. Having it on constantly, especially while using turn-by-turn navigation, could be a real performance issue in itself.
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.
archivedArchived because of inactivityiOSMapbox Maps SDK for iOSnavigationFor the Mapbox Navigation SDK for Android or iOS or navigation use cases in generalperformanceSpeed, stability, CPU usage, memory usage, or power usage
Activity
adam-mapbox commentedon Nov 9, 2015
So, I admit I haven't measured this, but the CPU usage should be extremely minimal. Remember that when the CADisplayLink wakes up all it has to do is check a boolean. It's not checking for whether we should render at that moment. And the CADisplayLink run loop mechanism is always running anyway; we're merely adding, at most, about one method call and maybe two or three instructions. It would be difficult to even measure the impact.
incanus commentedon Nov 9, 2015
Yeah, that was my hunch. If @kkaefer can confirm that he wasn't seeing anything more egregious, I think we can just close here then.
kkaefer commentedon Nov 9, 2015
It's minimal, but it still means the CPU needs to wake up. Previously, the CPU usage was reported as "zero" when the map was idling, now it's "low".
adam-mapbox commentedon Nov 9, 2015
Can you put that into context in terms of how big of a deal that is? Like, does it drain the battery or something?
tmpsantos commentedon Nov 9, 2015
@adam-mapbox on Intel architectures that I'm more familiar with, it definitely would have an impact because that would prevent the CPU from going to a "deep" C-State. But anyway, it is just a quirk if not measured.
tomtaylor commentedon Nov 10, 2015
The way I've used a CADisplayLink in the past is to start it on some kind of user interaction, and then let it remove itself when all its work is complete. Maybe that's an option here?
1ec5 commentedon Nov 12, 2015
On my 64 GB iPhone 6 running iOS 9.1, iosapp flatlines at 1% CPU usage when idle (and ticks up to 2% a couple times a minute).
incanus commentedon Nov 17, 2015
@tomtaylor There are so many different entry points for "interaction" here — gestures, but also programmatic/animated viewport changes, implicit changes for things like user dot tracking, etc.
If we can confirm that we had 0% battery usage when idle previously, and that we don't now, we should fix that.
1ec5 commentedon Nov 17, 2015
Prior to #2922, on my 64 GB iPhone 6 running iOS 9.1, iosapp was stable at 0% CPU usage and 2 fps. As of 7288473, it’s at 1–2% CPU usage and 3 fps. This is with iosapp in portrait showing the world map at z0 with the Streets style and no user dot.
1ec5 commentedon Nov 17, 2015
Either way, Xcode reports zero energy impact at idle.
1ec5 commentedon Nov 17, 2015
Scratch that, I’m not profiling battery usage correctly.
incanus commentedon Nov 18, 2015
Building on @tomtaylor's thoughts, a naive approach that might work here is to observe app foreground/background state and suspend the
CADisplayLinkas a result. But in past we've had rendering issues such as return to foreground with black map and app crashing in background, and we might run into similar things with such an approach as well.Either way, I think we can move this off of the 3.0.0 milestone since this is only for app foreground mode and continue to experiment given the upside of much better rendering performance.
44 remaining items
incanus commentedon Apr 13, 2017
Render callback &
-updateAnnotationViewsdoes fire, but views sometimes don't update position?!1ec5 commentedon Apr 14, 2017
I’ve been assuming that having mbgl drive updates was best, because mbgl has the most context about when a redraw is needed (camera transitions, property transitions, etc.). But mbgl doesn’t know anything about Core Animation. 🤔
incanus commentedon Apr 14, 2017
The behavior here is reminiscent of hangs in animations due to scroll view tracking and display link run modes, FWIW. Will keep debugging this.
incanus commentedon Apr 14, 2017
Ok, pushed my WIP to
2985-jrm-wip(commenting outCADisplayLinkroutines so that we can easily compare where it was used formerly).As far as I can tell, the actual transplantation of removing
CADisplayLinkis fairly trivial, as per that diff.The problems that crop up are related to the user and normal annotation views. Easy way to replicate:
User: Have the user dot on screen. Contrast moving the map with your finger (works fine) with tossing the map to coast to a stop (dot freezes until pan is complete).
The visual update routine seems to be called properly on each frame draw, so my hypothesis here is that the
UIViewanimation block in-updateUserLocationAnnotationViewAnimatedWithDuration:is somehow hanging or not moving forward during these pans.Normal: Choose
Add 100 Viewsfrom the gear menu. Observe that they track properly. Then, tap the tracking mode button and (assuming you are not also in DC) as the viewport changes, the annotations eventually freeze on screen despite being way out of view until the fly animation ends. Again, the update routine seems to be called each frame.Hypothesis: we don't actually ever remove annotation views from the hierarchy until the annotations are removed, we just skip updating their positions. This is catching up with us now for some reason. I'm not yet sure why they sync up properly at the end; possibly because they don't exist in
offscreenAnnotationsas they should until the final pass.incanus commentedon Apr 14, 2017
Part of me also wonders if the fact that
CADisplayLinkis part of Core Animation, if, as @1ec5 suggests in #2985 (comment), it causes some sort of Core Animation render buffer flush which keeps views/layers in sync properly. Something that we get for free withCADisplayLinkthat we might have to manage manually in future.incanus commentedon Apr 15, 2017
WELP
All of the bugs described in #2985 (comment) happen in an unaltered
master, too 🤦♂️So, I believe we can implement here and get rid of
CADisplayLink!Can anyone else confirm that these bugs exist or is it just me?
Edit: Scratch this; PEBKAC. 🤦♂️ 🤦♂️
incanus commentedon Apr 15, 2017
At the very least, removing
CADisplayLinkaggravates the annotation view lag we've seen before because-updateAnnoationsViewsis only called after a frame is rendered and not every screen refresh as with the display link. This makes it look like the views are lagging, when in fact they are crisply updating but our <60FPS map is not.incanus commentedon Apr 15, 2017
Here's a slow, deliberate GIF of the above jitter.
1ec5 commentedon Jun 14, 2017
Even if removing CADisplayLink doesn’t address the jittering, we know it contributes to increased power usage. Having it on constantly, especially while using turn-by-turn navigation, could be a real performance issue in itself.
stale commentedon Oct 27, 2018
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.
stale commentedon Dec 6, 2018
This issue has been automatically detected as stale because it has not had recent activity and will be archived. Thank you for your contributions.