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

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

Merged
julianrex merged 7 commits into
masterfrom
jrex/14232-work-around-master
Apr 3, 2019
Merged

julianrex merged 7 commits into
masterfrom
jrex/14232-work-around-master

Conversation

@julianrex

@julianrex julianrex commented Apr 2, 2019 •

Copy link
Copy Markdown
Contributor

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.
Comment thread platform/ios/src/MGLMapView.mm Resolved
Comment thread platform/ios/CHANGELOG.md Resolved
Comment thread platform/ios/src/MGLMapView.mm Resolved
Comment thread platform/ios/src/MGLMapView.mm Resolved
[self.glView display];
CFTimeInterval after = CACurrentMediaTime();

if (after-before >= 1.0) {

@chloekraw chloekraw Apr 2, 2019 •

Copy link
Copy Markdown
Contributor

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
Copy Markdown
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.

@1ec5 1ec5 Apr 3, 2019 •

Copy link
Copy Markdown
Contributor

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
Copy Markdown
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.

@julianrex julianrex Apr 3, 2019 •

Copy link
Copy Markdown
Contributor Author

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
Copy Markdown
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
{
_isTargetingInterfaceBuilder = NSProcessInfo.processInfo.mgl_isInterfaceBuilderDesignablesAgent;
_opaque = NO;
_atLeastiOS_12_2_0 = [NSProcessInfo.processInfo isOperatingSystemAtLeastVersion:(NSOperatingSystemVersion){12,2,0}];

Copy link
Copy Markdown
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
Copy Markdown
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.


// 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
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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

@chloekraw chloekraw left a comment

Copy link
Copy Markdown
Contributor

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