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

[ios] Enable/disable presentsWithTransaction to address #14232 #14307

Merged
merged 7 commits into from
Apr 3, 2019

Conversation

julianrex
Copy link
Contributor

@julianrex julianrex commented Apr 2, 2019

Moved from: #14264

This is a potential work around for for the slowdown reported in #14232. This may not address the associated crash.

As @jmkiley notes in that issue the cause appears to be the introduction of CAEAGLLayer.presentsWithTransaction in #12895 to synchronize OpenGL and UIKit views.

Julian Rex added 2 commits April 2, 2019 18:44
…ndow.

Added change log

Recreate GL views if rendering takes > 1 second. (since glClear is blocked for 1 sec)

Use presentsWithTransaction only if we have annotation UIViews.

Re-add annotation views.
platform/ios/src/MGLMapView.mm Show resolved Hide resolved
platform/ios/CHANGELOG.md Outdated Show resolved Hide resolved
platform/ios/src/MGLMapView.mm Outdated Show resolved Hide resolved
platform/ios/src/MGLMapView.mm Outdated Show resolved Hide resolved
[self.glView display];
CFTimeInterval after = CACurrentMediaTime();

if (after-before >= 1.0) {
Copy link
Contributor

@chloekraw chloekraw Apr 2, 2019

Choose a reason for hiding this comment

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

My second comment on this #ifdef is that I'm concerned about unintended consequences and believe the risks could outweigh the potential benefits, especially since this issue is so difficult to reproduce, but glClear could be blocked due to a variety of circumstances. We don't want to throw this hammer at every circumstance.

I can get onboard with offering this "escape hatch" in the code if we can implement it in a way so that it's entirely opt-in by the developer. I'm also ok with testing this before merging to see what the impact is like. But I remain skeptical that this is going to be a net-better experience for most apps and their end-users, compared to the status quo where sometimes when you rapidly switch between tabs many times, the map freezes and you have to restart the app. The vast majority of apps don't have use cases where users are frequently switching tabs, and until we hear more than one report of this issue, I think this would be overkill.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The developer would need to be building from source & provide the MGL_RECREATE_GL_IN_AN_EMERGENCY define as @1ec5 mentions above.

However, we will need to test that code path regardless.

Copy link
Contributor

@1ec5 1ec5 Apr 3, 2019

Choose a reason for hiding this comment

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

A single OpenGL call should take milliseconds. If glClear() is blocked for a second or more, that’s a clear sign of trouble, whether or not it’s the specific issue we’re trying to work around.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

But I remain skeptical that this is going to be a net-better experience for most apps and their end-users, compared to the status quo where sometimes when you rapidly switch between tabs many times, the map freezes and you have to restart the app.

Totally agree. We could decide (later) to change from an #ifdef to a developer set property, but hopefully a better solution will have shown its head by then.

Copy link
Contributor Author

@julianrex julianrex Apr 3, 2019

Choose a reason for hiding this comment

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

Yep, longer term it might be worth having something more robust anyway. But then, Metal.

Copy link
Contributor

Choose a reason for hiding this comment

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

Sounds good!

@julianrex julianrex added this to the release-liquid milestone Apr 3, 2019
@@ -444,6 +449,7 @@ - (void)commonInit
{
_isTargetingInterfaceBuilder = NSProcessInfo.processInfo.mgl_isInterfaceBuilderDesignablesAgent;
_opaque = NO;
_atLeastiOS_12_2_0 = [NSProcessInfo.processInfo isOperatingSystemAtLeastVersion:(NSOperatingSystemVersion){12,2,0}];
Copy link
Contributor

Choose a reason for hiding this comment

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

Nit: The operating system version doesn’t change dynamically during the process’ lifetime, so we can set this variable in +initialize above. (The same also goes for _isTargetingInterfaceBuilder, come to think of it.)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yep, let's address this later.

@@ -1101,6 +1110,13 @@ - (void)updateFromDisplayLink:(CADisplayLink *)displayLink
{
MGLAssertIsMainThread();

// Not "visible" - this isn't a full definition of visibility, but if
// the map view doesn't have a window then it *cannot* be visible.
if (!self.window) {
Copy link
Contributor

Choose a reason for hiding this comment

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

This seems like a pretty safe assumption. Do we suspect that -didMoveToWindow doesn’t get called as reliably?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

More concerns about when and how the display link method may be called. It's definitely defensive and a remnant of testing, but I think it's worth keeping.

_glView.drawableDepthFormat = GLKViewDrawableDepthFormat16;
_glView.contentScaleFactor = [UIScreen instancesRespondToSelector:@selector(nativeScale)] ? [[UIScreen mainScreen] nativeScale] : [[UIScreen mainScreen] scale];
_glView.layer.opaque = _opaque;
_glView.delegate = self;
Copy link
Contributor

Choose a reason for hiding this comment

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

These several lines are copy-pasted from -createGLView. Can we refactor that method to avoid the duplication? I’m just concerned that we may find it useful to keep this method around longer-term, but it’s really easy to forget to keep two code paths in sync.

@chloekraw chloekraw self-requested a review April 3, 2019 15:44
Copy link
Contributor

@chloekraw chloekraw left a comment

Choose a reason for hiding this comment

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

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug iOS Mapbox Maps SDK for iOS
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants