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.

Avoid animating to the same camera options #5983

Closed

Description

@1ec5

If you attempt to change the camera to an mbgl::CameraOptions that’s identical to the current CameraOptions, mbgl::Transform still goes through the entire animation machinery. We do avoid modifying the TransformState in that case, but by then it’s too late: we’ve already kicked off an animation timer and all the calculations for each step of the animation. The animation timer updates the map on a schedule regardless of whether the transform state changes.

There are multiple places where we can short-circuit the animation, and we should consider all of them to avoid severe energy consumption in navigation use cases, which require constant animation.

Incidentally, when we bail for a no-op animation, should the completion callback by called immediately, or still on a delay?

/cc @kkaefer @friedbunny

Activity

  1. added
    performance
    Core
    on Aug 12, 2016
  2. added this to the ios-v3.4.0 milestone on Aug 12, 2016
  3. added
    navigation
    on Aug 12, 2016
  4. tobrun commented on Aug 12, 2016

    @tobrun
    Member

    Incidentally, when we bail for a no-op animation, should the completion callback by called immediately, or still on a delay?

    I think from end user perspective immediately would make the most sense.

  5. self-assigned this
    on Aug 16, 2016
  6. incanus commented on Aug 16, 2016

    @incanus
    Contributor

    I am going the route here of:

    There are multiple places where we can short-circuit the animation

    I'm doing this with a few reusable viewport and camera equality check routines and some other slight refactoring to ensure that:

    1. We always bail early while still possibly running any completion block (immediately, per above).
    2. In future code we don't introduce new paths which circumvent these checks.

    Starting with iOS to hit some immediate needs, but will bring this to Android as well.

  7. added a commit that references this issue on Aug 16, 2016
  8. incanus commented on Aug 16, 2016

    @incanus
    Contributor

    Beginning in 4ef336e I am gating each viewport change method on MGLMapView (center, zoom, direction, bounds, camera, etc. with or without padding) by checks to bail early (possibly immediately running a passed completion callback in the main thread) before attempting any further mutation of the viewport state.

    I also abstracted some routines out that we use more than once and created a set of convenience handlers for checking the viewport changes by passing some or all of these parameters.

    This is just iOS to start.

    /cc @1ec5 @friedbunny

  9. added 2 commits that reference this issue on Aug 17, 2016
  10. 1ec5 commented on Aug 17, 2016

    @1ec5
    ContributorAuthor

    I think this is the cruxt of the problem that’s currently affecting user tracking use cases and causing #5833.

    The fix in 4ef336e will harden us against this kind of issue, but it should be much more tightly scoped to take advantage of the equality functions we already have in the SDK. Every round trip between MGLMapCamera and mbgl::CameraOptions loses accuracy when the map is tilted, due to #2259.

  11. incanus commented on Aug 17, 2016

    @incanus
    Contributor

    @1ec5 @friedbunny @boundsj I'm trying to think ahead to how I might write tests for these gates and coming up blank. Basically, we want to ensure that the setters are bailing early if the viewport is unchanged. By virtue of the viewport not getting changed, there isn't really anything to measure concretely.

    Any ideas?

    🤔

  12. incanus commented on Aug 17, 2016

    @incanus
    Contributor

    Specifically, it would be nice to be able to determine that either a Core Animation or a core GL transition aren't happening.

  13. incanus commented on Aug 17, 2016

    @incanus
    Contributor

    Currently trying something around inspecting _mbglMap->transform.inTransition().

  14. 20 remaining items

  15. 1ec5 commented on Nov 21, 2016

    @1ec5
    ContributorAuthor

    Why not now?

    Because there would still be some knots (like the KVO willChange/didChange calls) to untangle so close to a release, with the risk of regressing delegate method coalescing that we've been unable to UI test reliably. Also because the right fix in mbgl has implications for the Android SDK, which is even closer to release. See #5833 (comment).

  16. modified the milestones: ios-v3.5.0, ios-v3.4.0, on Nov 28, 2016
  17. 1ec5 commented on Nov 30, 2016

    @1ec5
    ContributorAuthor

    This issue – insignificant camera changes that trigger animations in-place – is most likely an edge case that only occurs for instance when the user is stopped at a traffic light and GPS readings bounce around slightly.

    #7236 is related and much more acute. We’ll have to do a bit more profiling to know exactly where the issue lies.

  18. modified the milestones: ios-v3.4.1, ios-v3.4.2 on Jan 25, 2017
  19. added
    iOS
    macOS
    and removed
    Core
    on Feb 18, 2017
  20. 1ec5 commented on Feb 18, 2017

    @1ec5
    ContributorAuthor

    Fixed for iOS and macOS in #7125 on the release-ios-v3.4.0 branch. #7295 tracks a similar issue on Android.

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

Metadata

Metadata

Assignees

Labels

iOSmacOSnavigationperformance

Type

No type

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions