1

I am trying to load 10k static records in TableView. It took 30s-45s to render tableview. How can I improve performance?

Analysed on lazy loading, found related search results only on downloading from remote server for images.

Note: i have tried loading the data in main thread which makes the app to get freezed

i had an idea of loading the 100 data at a time and when it is scrolled we can load the another 100 data. But i dont know exacty how to implement this

i have searched with these links

Table View takes a lot of time to refresh after "reloadData()"

UITableView reloadData taking too much time

Nothing has solved the problem

Anyone suggest for achieving this?

rmaddy
  • 314,917
  • 42
  • 532
  • 579
Gobi M
  • 3,243
  • 5
  • 32
  • 47
  • 1
    why you are not tried with [UITableViewDataSourcePrefetching](https://developer.apple.com/documentation/uikit/uitableviewdatasourceprefetching) – Anbu.Karthik Oct 06 '17 at 07:30
  • 2
    how do you mean _"to render tableview"_ takes 30s-45s? the tableview usually renders the visible cells only, whose number usually is around about 5-15 at the same time in practice – regardless whether you have 25 or 1M records on your _model_. – holex Oct 06 '17 at 08:11
  • i am just calling the reload tableview with 10k data. it first hitted the "numberOfRowsInSection" and then it takes 40 seconds to go to the cellForRowAt indexPAth. The method cellForRowAt indexPAth called only for visible rows which didnot take time – Gobi M Oct 06 '17 at 08:18
  • it means thread not upated, try with main_queue – Anbu.Karthik Oct 06 '17 at 08:20
  • i have tried with the main queue also, the app gets freezed if i use the main thread to load the data – Gobi M Oct 06 '17 at 08:23
  • Can you post the code for your `TableView` delegate and datasource methods? Typically a `TableView` doesn't take that long to render, so it's probably some performance issue in your code. Without seeing what you are actually doing it's going to be very difficult to speculate on a solution to your issue. – dlbuckley Oct 06 '17 at 08:57
  • @Gobi M You used pagination or not? – Jay Oct 06 '17 at 09:05
  • @Gobi what are you loading from where? It may not be the app, but the source? Are you sure it is the tableview that is taking forever, comment out the code and just a print statement to the console to look at the record load of the data,obviously not the data itself but some metric say count. – user3069232 Oct 08 '17 at 05:05

1 Answers1

9

UITableViewDataSourcePrefetching

Prefetching is useful when we need to download large models (usually images or video files) from the web or obtain from disk. Prefetching also gives us some kind of laziness in accessing data models: we don’t have to obtain all the data models, but rather only those, which are about to display. This approach reduces battery and CPU consuming and, thus, leads to better user experience.

the following two methods handle for prefetch

public func tableView(_ tableView: UITableView, prefetchRowsAt indexPaths: [IndexPath])
optional public func tableView(_ tableView: UITableView, cancelPrefetchingForRowsAt indexPaths: [IndexPath])

your question is too broad to answer , for sample you get the step by step tutorial here

Anbu.Karthik
  • 82,064
  • 23
  • 174
  • 143
  • No. i just want to load 10k text data which is statically already fetched and available. it takes that almost 40 seconds for reloading the tableview – Gobi M Oct 06 '17 at 08:03
  • @GobiM - your ? is different, where you faced the problem in load more time or initial time – Anbu.Karthik Oct 06 '17 at 11:05