bonzoq / hniosreader

Hacker News API-Based iOS Reader

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Slow scrolling performance

RedBanHammer opened this issue · comments

From the code, it looks like the UITableView implementation isn't properly doing the prototype-row caching method; row heights are being calculated during scrolls causing jitteriness and other gnarly performance issues.

Hi, thanks for your feedback. Can you help me by answering the following questions?

  1. Are you talking about the stories view or comments view?
  2. What iPhone are you using?
  1. Both table views have issues unfortunately
  2. iPhone 5s, iOS 8

From what I can see, I believe it's due to how you're setting up the table view cells. You're doing the height fitting in cellForRowAtIndexPath which means the table view needs to recalculate the height each time a new cell moves into the frame. You did put some sort of caching, but it only alleviates the other part of the problem (calculating heights after cells have moved into the frame from scrolling).

One alternative is to use temporary prototype cells to do caching and preloading of heights in the heightForRowAtIndexPath method (rather than estimatedHeightForRowAtIndexPath, since you're calculating the actual heights there). This allows the cell creation method (cellForRowAtIndexPath) to have preloaded heights on start.

In the heightForRowAtIndexPath, it would look something like (1) dequeueReusableCellWithIdentifier your regular cell identifier, (2) checking the height cache, (3) if hit, return cached height, if not, calculate the actual height and return using layout fitting.

Hopefully that helps. I don't have code on hand, but it's a pretty trivial fix I think. Cheers!

/hn/View Controllers/TableViewController.m

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
 //   [...]
// This is causing the jankiness:
    CGSize cellSize = [cell systemLayoutSizeFittingSize:CGSizeMake(self.view.frame.size.width, 0) withHorizontalFittingPriority:1000.0 verticalFittingPriority:50.0];
    [self.rowHeights setObject:[NSNumber numberWithFloat:cellSize.height] forKey:indexPath];

    return cell;
}

Thanks for this explanation. I will definetely try to fix this issue in the coming weeks.