CBL 2.6.0 Performance: saving 11,000 MutableDocuments takes 20 seconds; what am I doing wrong?

Realm’s benchmark results were for Couchbase Lite 1.0 or 1.1, which was admittedly much slower, and the implementation of their benchmark for Couchbase Lite was extremely inefficient since they didn’t make use of indexing (map/reduce views.)

Glad to hear we should be seeing faster performance, currently our benchmarks are at 1.2k inserts per second on an iPad Air. So Realm’s benchmarks of 1.7k inserts per second seems to be faster than what we are seeing on 2.6. We are looking at the insert performance under the inserts tab on that webpage.

There’s a lot of code in the Shared directory of your repo. Could you describe what the benchmark does at a high level?

Restructured the Shared directory to make it clearer what the benchmark does.
The entire benchmark code can be found here, lines 14 - 160.
It has 6 steps called out with the following comments.
// STEP 1: DELETE DB
// STEP 2: NEW DB
// STEP 3: ENSURE INDEXES
// STEP 4: CREATE MODELS
// STEP 5: CREATE MUTABLE DOCUMENTS
// STEP 6: INSERT INTO COUCHBASE

I can see it has custom data model classes which it then encodes to CBL Documents; what does it do after saving them?

We are focusing on just the saving/inserting performance at the moment.
So the benchmark ends after saving to Couchbase, nothing is done after saving the documents.

I’m happy to run a benchmark and share the results. Could you please make a release apk available. I lack the knowledge of setting up a C# developer IDE.

Thanks @benjamin_glatzeder! Uploaded a release APK here: https://github.com/ryanholden8/CouchbaseBenchmark/tree/master/APKs

My results on Xiaomi Mi A2

It was quite a bit slower the second time I run the benchmark. 3rd time was also about 43 seconds.

Since Android Studio shows me the method names when analyzing the apk

3

I’m not sure it is a signed release apk. The code should be optimized when a release apk is built. I’d expect to see method names like so:

4

and hopefully faster inserts!

I built the 1.0 APK with the following settings:
See: APK-1.0-Compiler-Setting.png & APK-1.0-Android-Build-Setting.png. (Sorry working around the 2 link and 1 picture limitation on the forum for new members, otherwise I’d include directly here)

Saw the same performance issue from the APK on my Android device that you were seeing. Around 40 seconds.

Playing around with other build settings and found this fixed the APK performance issue:

I had to install Android NDK, which is not part of the standard Visual Studio installation.

The inserts are still slow but are inline with the other benchmarks I posted above. ~10 seconds on the same Android device.

You can grab the new APK 1.1, with this setting turned on, here: https://github.com/ryanholden8/CouchbaseBenchmark/tree/master/APKs

I adjusted every other setting on the “Android Build” page.
Nothing else had any further effect on the benchmark timings.
Just to point out - “Enable AOT” is experimental (non-production) and Visual Studio Enterprise only option. It also did not change the performance of the benchmark timings.

Interesting, thanks for running that! I analyzed each APK after changing each setting and none of the options stripped the MainActivity method names. The methods look like mono generated code so it might be optimized but still modified by Mono? Not sure I know enough to try anything more on it. If ya have any ideas please let me know.

Hi @benjamin_glatzeder and @jens; just wanted to check in and see if the benchmarking app has helped to identify any root causes with insert performance?

I haven’t done anything, but I don’t develop for .NET or Android so I can’t directly use any of your code…

Hello @Ryan_Holden and @Andy_Huntsman

I’m unable to give any advice on how to build a release apk with Visual Studio. I grabbed the apk version 1.1 and have these results:

Delete DB: 0 ms
Create New DB: 151 ms
Create 11 Indexes: 332 ms
Create 11000 Models: 128 ms
Create 11000 Documents: 781 ms
Batch Save 11000 Documents: 8583 ms

1st, 2nd, 3rd run:

So that’s a big improvement over my previously posted benchmarks. I’m also unable to help you profile method calls. I might be able to help you port the benchmark app from .Net to Java. If there are differences in the benchmark results then at least you would know that it makes sense to profile the .Net code first and afterwards the Couchbase Lite Core module.