6

I as wondering how expensive reloadData on tableView is. I wanted to refresh the tableview every 5 seconds. Is that going to cause any performance issues?

  • 4
    whoever downvoted this question earlier, I honestly feel this is not a bad question. (at least tell the noob why such a question should not be posted instead of just downvoting) – Nitin Alabur Sep 13 '12 at 23:24
  • 2
    The only real answer is for you to use Instruments and measure your code. Your code will operate differently than anyone else's. Do what seems best, then measure. Then change according to any poor performance characteristics. Yes, it's the same I answer I give to everyone asking performance related questions -- because it's the only real answer until you actually have hard performance numbers. – Jody Hagins Sep 13 '12 at 23:53

3 Answers3

5

Reload data will call the two main methods on your table view data source, numberOfRowsInSection and then iterate over cellForRow:atIndexPath: for the visible cells required, depending on your tableView's contentOffset

If your app scrolls nicely already then the only performance hit your app will endure is if you're doing a lot of work in numberOfRowsInSection (like hitting the network or something time consuming).

Edit: As noted, heightForRow:atIndexPath: can also be a pain point if you're using it to do complex calculations for different height cells.

Jessedc
  • 12,320
  • 3
  • 50
  • 63
  • Awesome. Thanks for answering the question. My heights of the rows are constant and there are no complex calculations within the rows. – user1670024 Sep 14 '12 at 06:35
0

In addition to @Jessedc answer,

If all your rows are of same height, then heightForRowAtIndexPath is more expensive than tableview.rowHeight.

If you have a lot of rows with varying heights for each row, and you are calculating the height of the row each time the heightForRowAtIndexPath method is called, then its even more expensive.

There are a lot of factors involved in deciding how expensive the reloadData call is. Everything depends on what and how much you are doing each time the delegate methods are called.

Stunner
  • 12,025
  • 12
  • 86
  • 145
Nitin Alabur
  • 5,812
  • 1
  • 34
  • 52
0

If applicable to your situation, an NSFetchedResultsController can notify your table view when the data changes, instead of refreshing it every "n" seconds.

Robert Zahm
  • 1,877
  • 2
  • 12
  • 8