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

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

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

Notice (2018-05-24): bugzilla.xamarin.com is now in read-only mode.

Please join us on Visual Studio Developer Community and in the Xamarin and Mono organizations on GitHub to continue tracking issues. Bugzilla will remain available for reference in read-only mode. We will continue to work on open Bugzilla bugs, copy them to the new locations as needed for follow-up, and add the new items under Related Links.

Our sincere thanks to everyone who has contributed on this bug tracker over the years. Thanks also for your understanding as we make these adjustments and improvements for the future.

Please create a new report for Bug 47748 on Developer Community or GitHub if you have new information to add and do not yet see a matching new report.

If the latest results still closely match this report, you can use the original description:

  • Export the original title and description: Developer Community HTML or GitHub Markdown
  • Copy the title and description into the new report. Adjust them to be up-to-date if needed.
  • Add your new information.

In special cases on GitHub you might also want the comments: GitHub Markdown with public comments

Related Links:

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

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.