PhoneGap Couchbase Lite View performance issue on Android


#1

We are creating a disconnected app using Cordova,the Phonegap plugin, Sync Gateway, and Couchbase. The sync works fine and pulls down about 8K objects. We then have a number of views using Javascript maps. When we access the views the data is returned as expected. The issue is that this works very fast on iOS and extremely slow on Android - both in the emulator and on physical devices (tested on GS3 & GS5). One view takes a few seconds on iOS and 3 minutes on Android. Other views take upwards of 20 minutes. It seems the index is being created because the 2nd time accessing the view is much faster.

Are there any known issues with Couchbase Lite on Android that would cause this drastic performance gap? We reduced the view map functions to almost nothing and it did not seem to impact the time.

Thanks


#2

Hello @zebra1024,

Seems like your indexing is slow. Can you provide some code for the different Map Functions you have as the extreme contrast you described is very strange between iOS and Android.

Which version of CBL are you using and are you emitting the entire document?


#3

Yes the indexing is very slow - but only on Android. CLB version is below.

com.couchbase.lite.phonegap 1.0.4 “Couchbase Lite”

Example map is as follows

        var userMap = {
            _id: "_design/Users",
            views: {
                byName: {
                    map: function (doc) {
                        if (doc.ObjectType === "User") {
                            emit(doc.Username);
                        }
                    }.toString()
                }
            }
        };

I ran this on the emulator and it took about 7 minutes to generate the index (logging below)

03-10 10:53:59.585 V/View ( 2217): Re-indexing view: Users/byName
03-10 11:00:42.251 V/View ( 2217): Finished re-indexing view: Users/byName up to sequence 8196 (deleted 0 added ?)


#4

Hi @zebra1024
Is is possible to share sample documents with us?
Also, can you file the ticket on github repo? https://github.com/couchbase/couchbase-lite-java-core/issues
Thanks,


#5

The view looks reasonable. Maybe the JavaScript interpreter CBL uses on Android is slow?


#6

@jens, Thank you for your input.
CBL Android uses Rhino 1.7R3 which was released 2011-05-09.
We could try latest version of Rhino 1.7R5 which was released 2015-01-29. https://developer.mozilla.org/en-US/docs/Mozilla/Projects/Rhino/Download_Rhino
But I wonder if upgrading Rhino could dramatically improve map/reduce speed.


#7

Placed ticket at https://github.com/couchbase/couchbase-lite-java-core/issues/478

Example object:

{
   "channels":[
      "1c749055269f4dcb9ccffa6d1c1c153d"
   ],
   "CCObject":"{\"Username\":\"Ted Jones\",\"Password\":\"gR2H5Xv/C8k=\",\"Email\":null,\"AccountIDs\":[\"3ad73f94bb2342889d27fc687d197f87\"],\"Channel\":\"1c749055269f4dcb9ccffa6d1c1c153d\",\"ID\":\"77f39c10e6f3458eb753f37322e96813\",\"RecordVersion\":\"0000000000022615\",\"Type\":\"User\",\"Status\":\"Unchanged\",\"ObjectKey\":\"1c749055269f4dcb9ccffa6d1c1c153d_User_77f39c10e6f3458eb753f37322e96813\"}",
   "Username":"John Lawson",
   "ObjectType":"User",
   "Status":"Unchanged"
}

#8

This sounds like a good idea. I do not currently have a build environment for the plugin and the Java CBL project. I would be willing to try this if you could provide a new build. We are iterating over all the objects and doing manual filtering as a workaround.


#9

Could you profile the app while the view is being queried, to find out what the bottleneck is?


#10

I have not profiled the CBL running as part of a Cordova app- except for the logging with times I added above.
If there is a quick/easy way to profile the code in my test environment I will give it a try.

What do you suggest?


#11

Traceview requires Java code change
http://developer.android.com/tools/debugging/debugging-tracing.html

Android Device Monitor tracks memory usage and threads, but I don’t think if it can track method level performance profileing.
http://developer.android.com/tools/help/monitor.html