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.

User dot sometimes jitters during panning gesture #12740

Closed

Description

@1ec5

Sometimes, the user dot (user location annotation view) moves inconsistently as the user pans the map view from side to side; in other words, it sometimes darts forward or backtracks, producing a jarring jittering effect. To illustrate the problem, here’s a 30 fps recording at half speed (original screen recording):

jitter

This effect is distinct from the issue in #5489, in which the map view lags behind the annotation views but the annotation views move at a consistent rate. That issue also reproduces during camera animations driven by mbgl, such as drift animations following gestures. By contrast, this issue only reproduces during panning gestures, even slow ones in which the underlying map is able to move at a consistent rate. It’s fairly difficult to reproduce reliably: scrubbing the same map region repeatedly will reliably reproduce the issue, but then it’ll stop reproducing after you switch applications or stop interacting with the map for awhile.

The user dot differs from any other annotation view in that its center property is set inside an instantaneous UIView animation block that is triggered by -glkView:drawInRect: after telling mbgl to render a frame:

_rendererFrontend->render();
[self updateUserLocationAnnotationView];
[self updateUserLocationAnnotationViewAnimatedWithDuration:0];
[UIView animateWithDuration:duration
delay:0
options:(UIViewAnimationOptionCurveLinear |
UIViewAnimationOptionAllowUserInteraction |
UIViewAnimationOptionBeginFromCurrentState)
animations:^{
if (self.selectedAnnotation == self.userLocation)
{
UIView <MGLCalloutView> *calloutView = self.calloutViewForSelectedAnnotation;
calloutView.frame = CGRectOffset(calloutView.frame,
userPoint.x - annotationView.center.x,
userPoint.y - annotationView.center.y);
}
annotationView.center = userPoint;
} completion:NULL];

-glkView:drawInRect: is driven by a CADisplayLink, which #2985 proposes eliminating. (Optionally, -updateFromDisplayLink will also throttle rendering, but that functionality isn’t enabled here.)

Meanwhile, every other annotation view’s center property is set directly via -mapViewDidFinishRenderingFrameFullyRendered: after mbgl finishes rendering a frame:

annotationView.center = MGLPointRounded([self convertCoordinate:annotationContext.annotation.coordinate toPointToView:self]);

-mapViewDidFinishRenderingFrameFullyRendered: can be called not only after -glkView:drawInRect: asks mbgl to render a frame but also after mbgl renders a frame on its own volition. Perhaps not coincidentally, I’ve only been able to reproduce this issue when labels fade in and out as I pan the map, as seen in the recording above. That fading is driven entirely by a timer in mbgl, as are the drift animations in #5489.

The iOS and macOS map SDKs use mbgl’s synchronous rendering path rather than the asynchronous rendering path that the Android map SDK uses. So on each frame rendered because of CADisplayLink, -updateAnnotationViews gets called before -updateUserLocationAnnotationView.

Configuration

Mapbox SDK versions: v4.3.0, but probably earlier
iOS/macOS versions: 11.4.1
Device/simulator models: iPhone 8
Xcode version: 10.0 beta 6

/ref #8874 (comment)
/cc @mapbox/maps-ios

Activity

  1. added
    iOS
    performance
    annotations
    on Aug 25, 2018
  2. 1ec5 commented on Aug 25, 2018

    @1ec5
    ContributorAuthor

    -[MGLFaux3DUserLocationAnnotationView updateFrameWithSize:] also sets the center property directly. This code is triggered by a call to -[MGLUserLocationAnnotationView update] right after the call to +[UIView animateWithDuration:delay:options:animations:completion:] in -[MGLMapView updateUserLocationAnnotationViewAnimatedWithDuration:]. Perhaps that -update call should go in the completion handler of +[UIView animateWithDuration:delay:options:animations:completion:], which is asynchronous even when it’s instantaneous.

  3. 1ec5 commented on Dec 10, 2018

    @1ec5
    ContributorAuthor

    Fixed in #12895.

  4. julianrex commented on Dec 10, 2018

    @julianrex
    Contributor

    I believe there may still be an issue if two simultaneous operations try to modify the user location at the same time (for example dragging the map while the being repositioned by location updates).

    @1ec5 feel free to reopen should you notice this. Going to open a new ticket for the above if it turns out #13041 isn't sufficient.

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

Metadata

Metadata

Assignees

Labels

annotationsiOSperformance

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions