Load Large Data from multiple tables in parallel using multithreading

人走茶凉 提交于 2019-12-12 00:05:23

问题


I'm trying load data about 10K records from 6 different tables from my Ultralite DB.

I have created different functions for 6 different tables.

I have tried to load these in parallel using NSInvokeOperations, NSOperations, GCD, Subclassing NSOperation but nothing is working out.

Actually, loading 10K from 1 table takes 4 Sec, and from another 5 Sec, if i keep these 2 in queue it is taking 9 secs. This means my code is not running in parallel.

How to improve performance problem?


回答1:


There may be multiple ways of doing it.

What i suggest will be :

  • Set the number of rows for table view to be exact count (10k in your case)
  • Table view is optimised to create only few number of cells at start(follows pull model). so cellForRowAtIndexPath will be called only for few times at start.
  • Have an array and fetch only 50 entries at start. Have a counter variable.
  • When user scrolls table view and count reaches after 50 fetch next 50 items(it will take very less time) and populate cells with next 50 data. keep on doing same thing.

Hope it works.




回答2:


You should fetch records in chunks(i.e. fetch 50-60 records at a time in a table). And then when user reach end of the table load another 50 -60 records. Try hands with this library: Bottom Pull to refresh more data in a UITableView

Regarding parallelism go with GCD, and reload respective table when GCD's success block called.




回答3:


Ok you have to use Para and Time functions look them up online for more info



来源:https://stackoverflow.com/questions/16213603/load-large-data-from-multiple-tables-in-parallel-using-multithreading

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!