Jump to content

[TOPIC: topicViewTemplate]
[GLOBAL: userSmallPhoto]
Photo

Large Table view Insert Performance
Started by davidgmonical Oct 16 2017 12:46 PM

3 replies to this topic
[TOPIC CONTROLS]
This topic has been archived. This means that you cannot reply to this topic.
[/TOPIC CONTROLS]
[modOptionsDropdown]
[/modOptionsDropdown]
[reputationFilter]
[TOPIC: post.html]
#1

davidgmonical

[GLOBAL: userInfoPane.html]
davidgmonical
  • Enthusiast

  • 98 posts
  • Corona SDK

I'm building an app that includes a table view with a couple thousand rows. The table view needs to be searchable, and so the only way to reload it that I can see on search is to delete the rows and recreate the relevant ones (I've already implemented this). However, since there can be a couple thousand rows, looping through and inserting 2000 rows is very slow (about 1 second). I'm wondering if anyone has gotten around this somehow or has an idea of a possible solution. Thanks!



[TOPIC: post.html]
#2

nick_sherman

[GLOBAL: userInfoPane.html]
nick_sherman
  • Corona Geek

  • 1,916 posts
  • Corona SDK

You can load the rows in chunks so the UI is not tied up. Insert them in an enterFrame listener and after a certain number each frame let the program continue (you’ll have to experiment to get the best balance between responsiveness of the UI and speed of loading).

[TOPIC: post.html]
#3

Rob Miracle

[GLOBAL: userInfoPane.html]
Rob Miracle
  • Moderator

  • 26,544 posts
  • Enterprise

You should not be loading thousands of rows into a tableview.  There is a programming design pattern called MVC - Model - View - Controller that should be sort of considered here.

 

You should have a Lua table with your data in it. That's where your search happens. Once you have a search, only load matched items into the table"View".  Your Lua table is your "Model", the code that handles the search and inserts into the table view is the "Controller" in the MVC model. Your user isn't going to want to scroll through hundreds of records, little on thousands.  

 

In the CoronaWeather app (https://github.com/coronalabs-samples/CoronaWeather), I have a city, country database. I limit my search to only insert around 100 records. As they expand the search, the number of records drop, so my tableView gets smaller and smaller in size.

 

Nick's suggestion of loading in blocks works in particular if you want more of an endless scroll type of method (like the Facebook app does), detect when you get to the bottom of the tableView and insert more records.

 

Rob



[TOPIC: post.html]
#4

davidgmonical

[GLOBAL: userInfoPane.html]
davidgmonical
  • Enthusiast

  • 98 posts
  • Corona SDK

So the app is a field guide app and if the user presents no search parameters, I believe it should show all of the species. I already have the search and data model behind it setup (I use SQL queries) it's just a matter of loading that many rows. As for loading in chunks I can't see that working because I've tried this implementation and whenever the rows are inserted it halts/messes up the scrolling, making it frustrating for the user.




[topic_controls]
[/topic_controls]