Bug 47748 - Delay when presenting view controller from RowSelected
Summary: Delay when presenting view controller from RowSelected
Status: CONFIRMED
Alias: None
Product: iOS
Classification: Xamarin
Component: General (show other bugs)
Version: XI 10.2 (iOS 10.1)
Hardware: PC Windows
: --- normal
Target Milestone: Untriaged
Assignee: Bugzilla
URL:
Depends on:
Blocks:
 
Reported: 2016-11-23 16:28 UTC by tmrog
Modified: 2016-11-24 16:34 UTC (History)
2 users (show)

See Also:
Tags:
Is this bug a regression?: ---
Last known good build:


Attachments
Project to demonstrate the bug (46.47 KB, application/x-zip-compressed)
2016-11-23 16:28 UTC, tmrog
Details

Description tmrog 2016-11-23 16:28:32 UTC
Created attachment 18622 [details]
Project to demonstrate the bug

I have been wrestling with an issue that I finally isolated to being related to Presenting a VC from RowSelected vs. other places like a button hit.

I see this on a device running iOS 9.2.1 but not in the iOS10 simulator. My hands are tied testing on other platforms.

When I present a view controller from the RowSelected override in my table source, I see a delay of 5 to 10 seconds before the view controller is loaded and displayed. After the initial presentation, it is usually faster but still sometimes very slow.

After much trial and error and just plain trying stuff, I found that if I presented the ViewController inside a BeginInvokeOnMainThread() handler the delay goes away.

Here is what I had to do. I worked this in a test project that really was not doing anything else. (i.e. - no data retrieval and only UI for test)

        public override void RowSelected(UITableView tableView, NSIndexPath indexPath)
        {
            BeginInvokeOnMainThread(() =>
            {
                var item1VC = new Item1XibController();
                vc.PresentViewController(item1VC, true, null);
            });
        }

I have attached source code. I setup the table so that even rows do not call BeginInvokeOnMainThread so are slow and the odds rows do. and are always fast . The button in the header presents the vc without BeginOnvokeOnMainThread and is always fast.
Some logging spits out the time it takes for the vc to appear.

See RowSelected in BrowseTableSource and ItemSelected in BrowseViewController for pertinent code.
Comment 1 Vincent Dondain [MSFT] 2016-11-24 16:34:31 UTC
Hi,

First of all thanks for providing a good test case.

For me, time to ViewDidAppear varies from 1478ms (no BeginInvokeOnMainThread) and 575ms when BeginInvokeOnMainThread is called (using the iOS 10 sim though).

Now looking at the current threads and call stack it does not seem the code is running from a background thread so `BeginInvokeOnMainThread` should, technically, not make a difference and yet it does.

We'll have to investigate a bit more, I'm marking this bug as confirmed.

Note You need to log in before you can comment on or make changes to this bug.