Search code examples
iosipadsqlitefmdb

Sqlite performance with 10000 of records in iPad


I'm using FMDB wrapper class for my iPad application. I'm having table which contains nearly 10000 records. Each record is having 140 fields. I'm using Modal class to store the retrieved values like,

 NSString *query = [NSString stringWithFormat:@"select * from table"];
 FMResultSet *results = [db executeQuery:query];
 while([results next]) {
    ModalClass *modal = [[ModalClass alloc] init];
    [modal setField1:value1];
    [modal setField2:value2];
    [modal setField3:value3];
    [modal setField4:value4];
    .
    .
    .
    .
    .
    [modal setField139:value139];
    [modal setField140:value140];

    [array addObject:modal];
 }

I've used some options i know, performSelectorOnMainThread, dispatch_async() and some other multithreading techniques. But nothing helped me to make this efficient.

In Simulator, it takes 5 seconds. But when it comes to device it takes nearly 20 seconds.

Database is given by client, so i could not change or modify any tables.

Can anyone help me to make this efficient. Waiting for 20 seconds is very disgusting.

Thanks.


Solution

  • You are approaching the problem in the wrong way. The UITableView will have a data source that is called to allow you to populate the cells. Use these methods to load only the row data you need, not all 10,000 rows up front.

    I normally use a simple caching method to avoid re-loading the same row over and over for different cells within the tableview, but you don't need to worry about that initially (worry about it later if you feel the database is being hit too hard).