Note that there are some explanatory texts on larger screens.

plurals
  1. POUITableViewCell bad performance with AutoLayout
    primarykey
    data
    text
    <p>I'm somewhat stuck with this one… any help is very appreciated. I've already spent lots of time debugging this.</p> <p>I've got <code>UITableView</code> with data source provided by <code>NSFetchedResultsController</code>. In a separate view controller I insert new records to the CoreData using <code>[NSEntityDescription insertNewObjectForEntityForName:inManagedObjectContext:]</code>, save the managed object context and dismiss that controller. Very standard stuff.</p> <p>The changes in managed object context are then received by <code>NSFetchedResultsController</code>:</p> <pre><code>- (void)controllerWillChangeContent:(NSFetchedResultsController *)controller { [self.tableView beginUpdates]; } - (void)controllerDidChangeContent:(NSFetchedResultsController *)controller { [self.tableView endUpdates]; } - (void)controller:(NSFetchedResultsController *)controller didChangeObject:(id)anObject atIndexPath:(NSIndexPath *)indexPath forChangeType:(NSFetchedResultsChangeType)type newIndexPath:(NSIndexPath *)newIndexPath { switch (type) { case NSFetchedResultsChangeInsert: [self.tableView insertRowsAtIndexPaths:@[newIndexPath] withRowAnimation:UITableViewRowAnimationNone]; break; case NSFetchedResultsChangeDelete: [self.tableView deleteRowsAtIndexPaths:@[indexPath] withRowAnimation:UITableViewRowAnimationNone]; break; case NSFetchedResultsChangeUpdate: [self.tableView reloadRowsAtIndexPaths:@[indexPath] withRowAnimation:UITableViewRowAnimationNone]; break; case NSFetchedResultsChangeMove: [self.tableView deleteRowsAtIndexPaths:@[indexPath] withRowAnimation:UITableViewRowAnimationNone]; [self.tableView insertRowsAtIndexPaths:@[newIndexPath] withRowAnimation:UITableViewRowAnimationNone]; break; } } </code></pre> <p>And this is where the problem appears — it takes too long(about 3-4 seconds on an iPhone 4) to do that. And it seems like the time is spent calculating layout for the cells.</p> <p>I've stripped everything from the cell(including custom subclass) and left it with just <code>UILabel</code>, but nothing changed. Then I've changed the style of the cell to Basic(or anything except Custom) and the problem disappeared — new cells are added instantaneously.</p> <p>I've doubled checked and <code>NSFetchedResultsControllerDelegate</code> callbacks are called only once. If I ignore them and do <code>[UITableView reloadSections:withRowAnimation:]</code>, nothing changes — it is still very slow.</p> <p>It seems to me like Auto Layout is disabled for the default cell styles, which makes them very fast. But if that is the case — why does everything loads quickly when I push the <code>UITableViewController</code>?</p> <p>Here's the call trace for that problem: <img src="https://i.stack.imgur.com/z2hCd.png" alt="stack trace"></p> <p>So the question is — what is going on here? Why are cells being rendered so slowly?</p> <p><strong>UPDATE 1</strong></p> <p>I've built a very simple demo app that illustrates the problem I'm having. here's the source — <a href="https://github.com/antstorm/UITableViewCellPerformanceProblem" rel="noreferrer">https://github.com/antstorm/UITableViewCellPerformanceProblem</a></p> <p>Try adding at least a screenful of cells to feel the performance problems.</p> <p>Also note that adding a row directly ("Insert now!" button) is not causing any slowness.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload