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

Short-circuit redundant camera changes #7125

Merged
merged 1 commit into from
Feb 18, 2017

Conversation

1ec5
Copy link
Contributor

@1ec5 1ec5 commented Nov 20, 2016

Avoid canceling transitions (and triggering preexisting completion handlers) until we get a chance to ensure that a new transition really does have to begin. Consistently avoid mbgl transitions for redundant camera changes. Upon bailing, schedule the completion handler to run asynchronously on a delay equivalent to the requested animation duration.

MGLMapCamera now performs a float-precision equality check to avoid trivial differences. Added an equality operator to CameraOptions that similarly uses float-precision. Added a “functional” equality method to MGLMapCamera that avoids trivial differences.

Having made these changes, I very much want to move these redundancy checks into mbgl::Transform. However, that depends on eliminating the numerous SDK-side cancelTransitions() calls: #5833 (comment). This PR is less risky but should address the performance issues the iOS SDK is experiencing.

This change also fixes invocations of XCTAssertEqualWithAccuracy() that incorrectly expressed the accuracy as a number of digits rather than a scalar tolerance.

Fixes #5983.

/cc @incanus @jfirebaugh

@1ec5 1ec5 added iOS Mapbox Maps SDK for iOS macOS Mapbox Maps SDK for macOS performance Speed, stability, CPU usage, memory usage, or power usage labels Nov 20, 2016
@1ec5 1ec5 added this to the ios-3.4.1 milestone Nov 20, 2016
@1ec5 1ec5 self-assigned this Nov 20, 2016
@mention-bot
Copy link

@1ec5, thanks for your PR! By analyzing the history of the files in this pull request, we identified @rmnblm, @incanus and @boundsj to be potential reviewers.

XCTAssertEqualObjects(tester.mapView.camera, camera);

[tester.mapView setCamera:camera withDuration:10 animationTimingFunction:nil completionHandler:^{
XCTAssert(NO, @"Camera animation should not be canceled by redundantly setting the camera to the current camera.");
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is the best I could come up with for a test of the redundancy check. It essentially only verifies that cancelTransitions() isn’t called in the case of a redundant camera change. The test in #6060 is infeasible because the completion handler is eventually called even for redundant camera changes.

I verified via breakpoints that we do short-circuit mbgl for redundant camera changes and that significant camera changes still work.

@@ -34,6 +34,31 @@ struct CameraOptions {
/** Pitch toward the horizon measured in radians, with 0 rad resulting in a
two-dimensional map. */
optional<double> pitch;

bool operator==(const CameraOptions& o) const {
if ((!center && o.center) || (center && !o.center) ||
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why isn't this defined simply as memberwise ==?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Due to the float casts, which are needed due to slight imprecision – comparing doubles never returns true in practice. Or should a fuzzy equals be a separate method for clarity?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I should probably bring over the six-decimal-place rounding from #6060.

@1ec5
Copy link
Contributor Author

1ec5 commented Feb 16, 2017

I’ve pared back the change to touch only SDK code and also leave the normal -[MGLMapCamera isEqual:] and -[MGLMapCamera hash] methods unaffected.

@1ec5 1ec5 requested a review from incanus February 16, 2017 17:34
@1ec5
Copy link
Contributor Author

1ec5 commented Feb 17, 2017

We’ll need to cherry-pick #8073 in order to get the macOS CI build to pass again: #8100.

@@ -2415,9 +2427,7 @@ - (void)setVisibleCoordinates:(const CLLocationCoordinate2D *)coordinates count:

- (void)_setVisibleCoordinates:(const CLLocationCoordinate2D *)coordinates count:(NSUInteger)count edgePadding:(UIEdgeInsets)insets direction:(CLLocationDirection)direction duration:(NSTimeInterval)duration animationTimingFunction:(nullable CAMediaTimingFunction *)function completionHandler:(nullable void (^)(void))completion
{
_mbglMap->cancelTransitions();

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: Inconsistent line break.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good catch – fixed.

Avoid canceling transitions (and triggering preexisting completion handlers) until we get a chance to ensure that a new transition really does have to begin. Consistently avoid mbgl transitions for redundant camera changes. Upon bailing, schedule the completion handler to run asynchronously on a delay equivalent to the requested animation duration.

Added a “functional” equality method to MGLMapCamera that avoids trivial differences.

Fixed invocations of XCTAssertEqualWithAccuracy() that incorrectly expressed the accuracy as a number of digits rather than a scalar tolerance.
@1ec5 1ec5 merged commit d790132 into release-ios-v3.4.0 Feb 18, 2017
@1ec5 1ec5 deleted the 1ec5-camera-noop-5983 branch February 18, 2017 22:36
1ec5 added a commit that referenced this pull request Feb 18, 2017
Removed a duplicate entry; moved the #7125 entry to the right release; added a blurb about #7937.
1ec5 added a commit that referenced this pull request Feb 19, 2017
Removed a duplicate entry; moved the #7125 entry to the right release; added a blurb about #7937.
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
iOS Mapbox Maps SDK for iOS macOS Mapbox Maps SDK for macOS performance Speed, stability, CPU usage, memory usage, or power usage
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants