Skip to content
This repository was archived by the owner on Aug 8, 2023. It is now read-only.
This repository was archived by the owner on Aug 8, 2023. It is now read-only.

Remove CADisplayLink #2985

Closed
Closed

Description

@incanus

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

@kkaefer Did you measure this at all? How?

/cc @adam-mapbox @tmpsantos

Activity

  1. added
    iOS
    performance
    on Nov 9, 2015
  2. added this to the ios-v3.0.0 milestone on Nov 9, 2015
  3. adam-mapbox commented on Nov 9, 2015

    @adam-mapbox
    Contributor

    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.

  4. incanus commented on Nov 9, 2015

    @incanus
    ContributorAuthor

    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.

  5. kkaefer commented on Nov 9, 2015

    @kkaefer
    Member

    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".

  6. adam-mapbox commented on Nov 9, 2015

    @adam-mapbox
    Contributor

    Can you put that into context in terms of how big of a deal that is? Like, does it drain the battery or something?

  7. tmpsantos commented on Nov 9, 2015

    @tmpsantos
    Contributor

    @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.

  8. tomtaylor commented on Nov 10, 2015

    @tomtaylor

    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?

  9. 1ec5 commented on Nov 12, 2015

    @1ec5
    Contributor

    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).

  10. incanus commented on Nov 17, 2015

    @incanus
    ContributorAuthor

    @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.

  11. 1ec5 commented on Nov 17, 2015

    @1ec5
    Contributor

    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.

  12. 1ec5 commented on Nov 17, 2015

    @1ec5
    Contributor

    Either way, Xcode reports zero energy impact at idle.

  13. 1ec5 commented on Nov 17, 2015

    @1ec5
    Contributor

    Scratch that, I’m not profiling battery usage correctly.

  14. incanus commented on Nov 18, 2015

    @incanus
    ContributorAuthor

    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.

  15. 44 remaining items

  16. incanus commented on Apr 13, 2017

    @incanus
    ContributorAuthor

    Render callback & -updateAnnotationViews does fire, but views sometimes don't update position?!

  17. 1ec5 commented on Apr 14, 2017

    @1ec5
    Contributor

    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. 🤔

  18. incanus commented on Apr 14, 2017

    @incanus
    ContributorAuthor

    The behavior here is reminiscent of hangs in animations due to scroll view tracking and display link run modes, FWIW. Will keep debugging this.

  19. incanus commented on Apr 14, 2017

    @incanus
    ContributorAuthor

    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.

  20. incanus commented on Apr 14, 2017

    @incanus
    ContributorAuthor

    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.

  21. incanus commented on Apr 15, 2017

    @incanus
    ContributorAuthor

    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. 🤦‍♂️ 🤦‍♂️

  22. incanus commented on Apr 15, 2017

    @incanus
    ContributorAuthor

    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.

  23. incanus commented on Apr 15, 2017

    @incanus
    ContributorAuthor

    Here's a slow, deliberate GIF of the above jitter.

    jitter

  24. 1ec5 commented on Jun 14, 2017

    @1ec5
    Contributor

    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.

  25. added
    navigation
    on Jun 14, 2017
  26. stale commented on Oct 27, 2018

    @stale

    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.

  27. added
    archived
    on Oct 27, 2018
  28. stale commented on Dec 6, 2018

    @stale

    This issue has been automatically detected as stale because it has not had recent activity and will be archived. Thank you for your contributions.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    archivediOSnavigationperformance

    Type

    No type

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions