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.

Map view lags behind annotation views when panning #5489

Closed

Description

@Paladinfeng

*_Platform: iOS 9.3.2
*_Mapbox SDK version: v3.3.0-beta2

I found the MGLAnnotationView scrolling like jello when I use the new iOS SDK. The MGLAnnotationView can't follow the MapView smoothly. I have tested at iPhone 5s and iPhone 6.

Activity

  1. friedbunny commented on Jun 27, 2016

    @friedbunny
    Contributor

    Please post more information about the view you’re using — code and a gif would be ideal. Thanks.

  2. Paladinfeng commented on Jun 27, 2016

    @Paladinfeng
    Author

    ok, I'll save something as a gif video tomorrow.
    it just like rolling shutter in the field of photography.

  3. Paladinfeng commented on Jun 28, 2016

    @Paladinfeng
    Author

    rolling_shutter
    can u see it? The MGLAnnotationView can't follow the mapView totally.

  4. friedbunny commented on Jun 28, 2016

    @friedbunny
    Contributor

    Thanks for the image, @Paladinfeng. Syncing the movement of native views with the map is an ongoing challenge, certainly.

    /cc @boundsj @1ec5

  5. added
    iOS
    performance
    on Jun 28, 2016
  6. 1ec5 commented on Jun 28, 2016

    @1ec5
    Contributor

    I suspect #5245 may yield some improvement, specifically disabling animations while updating annotations and coalescing the frame updates into one Core Animation transaction. I’ll need to pull those changes out into a separate PR and see if they improve things on their own, without the other matrix-related changes.

  7. changed the title [-]AnnotationView scrolling like jello[/-] [+]Annotation views lag behind map view when panning[/+] on Jul 3, 2016
  8. changed the title [-]Annotation views lag behind map view when panning[/-] [+]Map view lags behind annotation views when panning[/+] on Jul 3, 2016
  9. 1ec5 commented on Jul 3, 2016

    @1ec5
    Contributor

    The changes in #5245 don’t address this issue after all.

    As far as I can tell, the map is lagging behind the annotation views by one frame every other frame or so. In the screen recording below, keep an eye on the annotation view that initially covers up the word “Washington”. When I scroll up, you can occasionally see “Washington” appear to the south of the annotation view; when I scroll down, you can occasionally see “Washington” appear to the north of the annotation view:

    gelatin

  10. added
    annotations
    on Jul 6, 2016
  11. added this to the ios-v3.4.0 milestone on Jul 6, 2016
  12. 1ec5 commented on Jul 7, 2016

    @1ec5
    Contributor

    One potential way to eliminate the "tearing" effect might be to put the annotation updating phase into a custom style layer drawing callback. This would ensure that the Core Graphics and Core Animation drawing commands occur closer to the OpenGL drawing commands and in the same run loop iteration. Ironically, the annotation views would be less performant, but the perceived performance would improve.

  13. incanus commented on Jul 19, 2016

    @incanus
    Contributor

    Naive post to related issue, before further investigation: #1813

  14. 1ec5 commented on Jul 19, 2016

    @1ec5
    Contributor

    #1813 in some respects addresses the opposite issue: the map was leading the UIView because the map was given the opportunity to advance one step (for a transition) before the UIView got a chance to update. The annotation view implementation addresses this by updating the frame on the "map did finish rendering frame" notification.

    I think what we're seeing is that Core Animation / Core Graphics manages to maintain 60fps drawing of the annotation views even as MGLMapView struggles to do the same with the underlying map. We mitigated that for the user dot in #3683 by disabling implicit animation, but the root cause can still be reexposed by adding multiple views onto the map.

  15. 34 remaining items

  16. modified the milestones: ios-future, ios-v3.4.0 on Aug 22, 2016
  17. incanus commented on Aug 22, 2016

    @incanus
    Contributor

    Will continue to investigate this, but for a lot of use cases (particularly small view annotations) current performance is acceptable.

  18. 1ec5 commented on Aug 22, 2016

    @1ec5
    Contributor

    @mb12, thanks for the reminder. We previously looked into presentsWithTransaction in #1125 (comment), but there was no effect. In hindsight, that was because of an implicit animation, which we disabled in #3683. Having exhausted that lead for this issue, we should look into presentsWithTransaction at some point.

  19. incanus commented on Aug 23, 2016

    @incanus
    Contributor

    The good news: I have figured out the problem and have a local version working nearly perfectly.

    The bad news: We need to get a higher frame rate on our core GL draws to solve it. This is essentially what @1ec5 has been hypothesizing since #5489 (comment), but I think I have confirmed it.

    I tried a number of approaches to get the annotations & Core Animation to slow down and/or draw in sync with the OpenGL frame updates:

    • Calling -updateAnnotationViews only every other GL render (i.e. every other CADisplayLink update, i.e. at essentially half its current frame rate)
    • Experimenting with -[CATransaction flush] and -[CATransaction lock]
    • Bracketing both the call to -updateAnnotationViews and _mbglMap->render() in a CATransaction with varying options (-setDisableActions:YES, varying animation durations including 0)
    • Checking out ((CAEAGLLayer *)_glView.layer).presentsWithTransaction = YES; after watching the WWDC session (again), despite poor specifics in both that and the docs around how to use it (but which is what led me to experimenting with the above bracketing around the GL render)

    None of these reduced jitter since what we perceive as jitter is the position relative to the map, and the map isn't moving as smoothly as it could.

    Also, just to be sure, I experimented with:

    • Rounding annotation latitude & longitude to varying levels (2-5 decimal places)
    • Rounding annotation position values to whole numbers instead of their default fractional CGPoint values
    • Experimenting with calling updateAnnotationViews from the drawingHandler of a custom layer
    • Ensuring that a map-less view with annotations still looked smooth
    • Ensuring that an annotation-less map view still looked smooth

    It was that last one that still looked suspect to me, especially when using Apple Maps to compare, and profiling confirmed that I was only ever seeing ~30fps for a default Streets style (on a couple years old but respectable retina iPad mini). I pared back a style in Studio until I could get one that was consistently 55-60fps:

    screen shot 2016-08-22 at 6 27 17 pm

    Portland

    This mostly involved getting rid of all labels, symbols, and roads and just leaving fills like water and parks.

    But: once I did this, and got the OpenGL frame rate to about 60fps, I got some good-looking sync:

    '

    You can still see this jitter a tiny bit when we dip into the ~55fps range, which is to be expected.

    screen shot 2016-08-22 at 6 14 23 pm

    The test style URL in question is mapbox://styles/justin/cis6rzo41000egpnt2julnz92 if you'd like to try this yourself.

    So, again I think we punt on this for now as there is no magic Core Animation bullet to help us. We need to get our frame rate up with arbitrary styles, which is a more difficult proposition than what Apple Maps does with its one or two default styles.

    /cc @jfirebaugh @kkaefer

  20. incanus commented on Aug 23, 2016

    @incanus
    Contributor

    To be complete: I also changed the MGLTargetFrameInterval to trigger 30fps max GL draws, in combination with the CATransaction experimentation in case that would be enough to cause Core Animation to slow down and sync, but no dice. Our map looks the same (since we're at about 30fps already) and Core Animation was still out of sync since it's faster.

  21. 1ec5 commented on Aug 23, 2016

    @1ec5
    Contributor

    You can also see the map lagging behind the view in the GIF (!) in #5489 (comment) – that effect wouldn't be possible if not for the map rendering at far less than 60 fps.

    We added CADisplayLink in order to throttle map redraws (originally to 30 fps, later to 60 fps, nominally). Should we revisit our use of that API? It has its own performance downsides: #2985.

  22. incanus commented on Aug 23, 2016

    @incanus
    Contributor

    Will read up on CADisplayLink further.

    As a clarification, when I say Core Animation in the context of this problem, I mean the mechanism by which native views are composited to the frame buffer on the device. Even though we no longer actually animate our annotation views, the mere movement of them pixel-by-pixel is governed by internal OpenGL rendering on Core Animation's part and that is a solid 60fps, thus highlighting weaknesses in our own frame draws.

  23. 1ec5 commented on Nov 1, 2016

    @1ec5
    Contributor

    Same case is with Android too. UserLocation dot and ViewMarkers are not synced with map panning.

    @Paladinfeng, FYI, the equivalent issue on Android is being tracked in #6139. mapbox/mapbox-gl-js#3273 is a conceptually similar issue in GL JS.

  24. tabsong commented on Jun 30, 2017

    @tabsong

    @incanus in the end, can you resolve the sync problem?

  25. removed this from the ios-future milestone on Nov 15, 2017
  26. 1ec5 commented on Aug 25, 2018

    @1ec5
    Contributor

    I can't see why the user dot would behave differently.

    I’ve split out #12740 to track a separate synchronization issue that only affects the user dot but not other annotation views. That issue includes a possible explanation as to why the user dot behaves differently than other annotation views.

  27. 1ec5 commented on Dec 10, 2018

    @1ec5
    Contributor

    Fixed in #12895.

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

    annotationsiOSperformance

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions