Very slow data retrieval (iOS)


#1

I have an iOS app with a Couchbase Lite db with 2.219 documents. When the app starts I read all the documents into dictionaries. I do this in a loop document by document because using CB ResultSet takes too much memory. Also toDictionary() seems to have a memory leak.

Anyway. When I first get all document IDs, it takes about 1.5 seconds. Getting all documents after that takes about 19 seconds.
When I do the same thing again later in the running app, getting document IDs takes about 0.15 seconds and getting all documents takes about 4 seconds.

What can I do to speed up the first access to the data?


#2

Have you considered using pagination instead via the skip and limit properties of query? Then you wouldn’t have to go through “document by document” as you do now. Putting 2,000 documents into dictionaries seems like an odd thing to do though. The whole purpose of the database is to get things on demand when you need them. Are you always going to need all of them at the same time?


#3

Just to make sure: You mean 2219 documents, right? [I’m from the US, which uses periods as decimal points.]

That’s a pretty tiny number of documents. Doing anything with a few thousand docs should take milliseconds, not seconds. Are they each extremely large? I’m guessing so, if you’re complaining about ResultSet taking too much memory. Large documents (more than a megabyte or so) aren’t a good idea for several reasons. They’re expensive to load and store; any tiny change requires the entire doc to be re-synced; and changes on multiple devices are likely to conflict. Plus, as Jim said, the point of having a database is to load only the information you need at that moment.

Could you tell us how large the database file is, and how big a typical document is, and what it consists of?