Couchbase Lite Android

Hello I’ve implemented CouchBase Lite (1.4.1 version) and it works perfectly!.. Except that when I open the app It seems that it freezes about 3-10 seconds almost every time. It looks that all the couchbase networking is working on the MAIN thread! I don’t know how to fix this because I don’t find any other information about this specific issue. Also my colleague implemented couchbase to iOS device and it works smoothly without freezing the app. So maybe someone from this forum could help me to solve this problem? Thanks!

You likely have an index (map reduce view) defined. For some odd reason CBL 1.x sometimes re-indexes the view ever so often, hence the wait. To confirm that this is the case connect it to Logcat - Verbos, and you shall see CBL index related error or message(s). Anyhow, this is what was happening in my case.
Since CBL 2.0 has dropped the entire map reduce view, I decided not to ‘make waves’ about this, so not to burden the developers with old stuff. CBL 2.x indexing - and db, should be much more robust - I hope.
nat

It seems that it freezes about 3-10 seconds almost every time.

Do you mean that it freezes permanently after 3-10 seconds, or do you mean that it freezes for durations of 3-10 seconds and then recovers?

What does your main thread’s stack look like when this occurs, i.e. what if anything are you calling? The most likely issue is that you’re responding to a database change notification by doing something expensive, either in your code or in ours (i.e. querying a view, which requires updating the view’s index.)

It looks that all the couchbase networking is working on the MAIN thread!

No, Couchbase Lite does all of its networking on background threads, never the main thread.

It’s not mysterious at all. Views are indexed lazily and incrementally, so when you query a view, any documents that have changed (since the last time the view was indexed) will be indexed, i.e. fed through your map function.

However, if the main thread needs access to a db that is currently being indexed (in a different thread), the main threads will wait for the indexing to complete, with the same net effect (as all in the main thread).

I know.
The mysterious part is that if one thread with the db open spawns another thread which only reads that same db/view, upon its return it will re-index.

nat

It freezes for duration of 3-10 seconds and then recovers.