views:

106

answers:

1

Hi,

I am trying to add suggestions for a UITextField. They show up as a UITableView below the text field that displays a few entries according to what the user is typing (like Google Suggest for example).

The only method I tried so far is a select from an internal SQLite database. This works, but it is extremely slow as the database is really large (approx. 35000 entries). Everytime something is typed, the app freezes for 4 or 5 seconds before showing up new suggestions. So I guess this method ain't the best.

I was thinking of mapping everything in an NSDictionary but I'm afraid the table is too big (about 1.5MB) and keeping the NSDictionary permanently would be very costful in terms of memory.

What do you guys think would be best?

A: 

have you thought of using NSThread to create the array that will be used by the table view? (don't do any UIKit calls through this though). If you run it all on the main thread, it'll be way slower, especially since your database is large.

If you don't know how NSThread works, check out this awesome tutorial: http://www.xprogress.com/post-36-threading-tutorial-using-nsthread-in-iphone-sdk-objective-c/

David Schiefer
Well using a thread could be a solution but there still would be a delay between when the user types and when the suggestions show up. An existing app from the app store does the exact same thing instantly (suggestions from a large db), so I guess there must be a better way to do.
Jukurrpa
Well my app does it via NSThread and it works instantly too...
David Schiefer
I tried this now that I retrieved an iphone to work on, it did not solve the problem. the UI does not freeze anymore but results still take a few seconds to show up.
Jukurrpa
The fact that it doesnt lag is good - NSThread is working. The slowness is normal therefore, your DB is just very large?
David Schiefer
Yes. I did many improvements today, simplified the query, and I tried working with temporary tables which group entries by their starting letter. It makes the queries almost instant, but tables are long to create. Maybe storing definitely in separate tables could work, but that would be 36 tables in the database just for this (26 letters + 10 digits), that's not very clean.
Jukurrpa
it works - sometimes you have to make small sacrifices :P
David Schiefer
Well it's still not perfect. And on the other app which does exactly the same thing, it is perfect! So I've got to find other ways to improve it.
Jukurrpa