Bug 7307 - Huge performance hit with GetRowHeight
Summary: Huge performance hit with GetRowHeight
Alias: None
Product: iOS
Classification: Xamarin
Component: XI runtime ()
Version: 5.4.x
Hardware: PC Mac OS
: --- critical
Target Milestone: Untriaged
Assignee: Rolf Bjarne Kvinge [MSFT]
Depends on:
Reported: 2012-09-19 14:27 UTC by James Clancey
Modified: 2012-09-19 15:32 UTC (History)
2 users (show)

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

TestCase (740.20 KB, application/zip)
2012-09-19 14:27 UTC, James Clancey

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 on Developer Community or GitHub with your current version information, steps to reproduce, and relevant error messages or log files if you are hitting an issue that looks similar to this resolved bug and you do not yet see a matching new report.

Related Links:

Description James Clancey 2012-09-19 14:27:28 UTC
Created attachment 2574 [details]

I have been playing around with instruments trying to get the hang of it. And while doing so I found a major performance bug with MonoTouch.  
I have a very simple GetRowHeight method

public bool DarkThemed {get;set;}
public override float GetHeightForRow (UITableView tableView, NSIndexPath indexPath)
				return Container.DarkThemed ? 80 : 56;

While checking instruments you can see this call is taking a ton of processing power


I provided a test case. As I move the UITableViewController, I set the frame. Whenever the frame is set it recalculates the height of the rows. On an iPhone 3gs this operation can lock the UI for up to 5 seconds.  

There is also an instruments trace included in the zip
Comment 1 Sebastien Pouliot 2012-09-19 15:15:08 UTC
How many items/rows does your UITableView has ? (all of them, not just the visible ones)

I found out (it's documented), with my own app, that Apples calls GetHeightForRow for *every* cell - even if they are not visible. In my case I had more than 209,000 items - and that took more than 16 seconds in an iPad3. 

I removed the override and it fells to less than one second (which includes a lot of other things, like opening my database...)

with overrides
2012-08-04 11:07:55.720 Sample[4092:707] 16921,844 ms

without overrides
2012-08-04 11:09:26.786 Sample[4109:707] 671,273 ms

So it's likely your issue is the number of calls, not the time each calls takes (native to managed) that is the main issue. I did not need to have different height (the override came from Jeff's library) but you might be able to fake it with a lower value (and adjust it).

That's an hack but it's easier to control the number of calls than to optimize (even by 50%) the cost of native to managed transitions (and even 50% would still not be fast enough for you).
Comment 2 James Clancey 2012-09-19 15:32:32 UTC
Sebastien, I believe you are right. This is an iOS issue not MonoTouch.