Couchbase-lite v2.1.2 Andorid Encryption makes application performance slow

Hi,

We are working on an Android Application which using Cblite version 2.1.2 Enterprise Edition. and we have enabled encryption using -

dbConfig.setEncryptionKey(new EncryptionKey(encryptionKey));

But after enabling the encryption our application performance decreases, it makes DB operations and queries slow.

Could you please help with this? as we want to secure the app but it’s impacting application performance.

Thanks!

How much slower? A 5-10% slowdown is expected due to the overhead of encrypting and decrypting pages.

Make sure your queries are supported by good indexes, since otherwise queries will have to scan the entire database which incurs much more I/O and decryption. (Use the Query.explain method to get a description of the query, and watch out for any SCAN operations in the output.)

Also, what device/hardware? You may be testing on a device that doesn’t have hardware acceleration of AES cryptography, although that should be unlikely nowadays.

Thank you, Jens,

It’s slowing application around 400-500% as a query is taking 4 seconds with encryption and takes less than a second without encryption.
Encryption with Indexes improves a little bit around 3.5 seconds to execute the query.

Multiple indexes can slowdown writing in the database as per Couchbase lite documents. Will it make syncing slow?

We are using the Samsung Active Tab 2 device which has hardware ARM Cortex-A53. and according to the below article, This has Armv8-A Cryptographic Extension which provides instructions for the acceleration of encryption and decryption.

I am new on Encryption things, please correct me if I am wrong and If you need anything from me, please.

(Use the Query.explain method to get a description of the query, and watch out for any SCAN operations in the output.)

Please provide this piece of information

Hi borrden,

Please find result of Query.explain() below -

SELECT fl_result(fl_value(body, ‘ReservationPersonID’)) FROM kv_default WHERE (fl_value(body, ‘type’) = ‘PersonStatus’ AND (fl_value(body, ‘IsValidationSuccessful’) = 1 AND ((1556582400000 BETWEEN fl_value(body, ‘StartDateEpoch’) AND fl_value(body, ‘EndDateEpoch’) AND 1556063999999 != fl_value(body, ‘EndDateEpoch’)) AND 1556582400000 != fl_value(body, ‘StartDateEpoch’)))) AND (flags & 1) = 0 ORDER BY fl_value(body, ‘ValidationStatusDateEpoch’) DESC LIMIT MAX(0, 5)

0|0|0| SCAN TABLE kv_default

0|0|0| USE TEMP B-TREE FOR ORDER BY

SCAN TABLE kv_default means no index is being used; the query has to read every single document into memory to check it. That’s bad.

What indexes to add depends on your data set, but an index on type is usually a good idea. You probably also want an index on StartDateEpoch; indexing (StartDateEpoch, EndDateEpoch) instead might work slightly better.

Thanks, Jens

I have created indexes as per your guidance and found performance increased. now it’s taking around 2 seconds. Can we improve it more?

find below Query.Explain() result after adding indexes -

0|0|0| SEARCH TABLE kv_default USING INDEX type (<expr>=?)
0|0|0| USE TEMP B-TREE FOR ORDER BY

Creating multiple indexes can slow the writing in the database as per the couchbase documents. Doesn’t it slow the syncing?

How many documents of that type are there in the db? And about how large are they? (Very large documents can slow things down, as the whole document has to be read from storage.)

@borrrden, do you know if the AES operations in SEE are hardware-accelerated in Android? That is, do they call into the OS (as on iOS) or are they implemented in the SEE source code?

On indexing vs not indexing — its a trade-off, and you’ll have to decide whether it’s worth it. But each index should only slow down insertions a little bit, so it’s usually good to index if the query is being run often.

1 Like

Around 4000 documents and a document have around 20 fields. Can it slow the query execution?

The number of fields doesn’t matter. The size of the document (as JSON) does.