Search Unity

Reading quickly a SQlite3 database with 50000 elements and handling UI elements efficiently

Discussion in 'Editor & General Support' started by AIO1, Nov 24, 2019.

  1. AIO1

    AIO1

    Joined:
    Jan 19, 2018
    Posts:
    1
    Hello!

    I've run into an issue whcih I'm unable to find a solution for.
    I have a database in SQlite3 which contains a table with 50000 elements. My goal is to generate a button for each element inside a Scroll view > Viewport > Content and to perform this operation in the fastest posible way.

    Generating this many UI buttons (50000) makes Unity unable to handle the application at a decent framerate (it won't go faster than 4fps) as expected. Is there a way to have the UI buttons there, but unactive when outside the scroll view?

    To load the database I've tried to do it in two ways:
    - Read everything directly in a void start (takes like 2-3 minutes)
    - Use a corutine, so I can still do stuff while it's generating each element and reading the database at the same time, but it takes longer to load all the elements (like 10 minutes, and yes, I'm using yield return null)

    Does anyone know a solution for my two issues?
    Thanks in advance :)
     
  2. Corvwyn

    Corvwyn

    Joined:
    Nov 15, 2013
    Posts:
    114
    I would do something like this:
    - Select a certain amount of elements from the database at a time, using limit, rownum or similar (I'm not familiar with SQlite). This is called paging/pagination.
    - Have a number of buttons equal to what you see on screen + enough elements to make sure that they are populated in time.