Titanium JIRA Archive
Appcelerator Community (AC)

[AC-6427] EncryptedDB - Android - Fetching from db very slow.

GitHub Issuen/a
TypeBug
Priorityn/a
StatusClosed
ResolutionDone
Resolution Date2019-12-21T07:25:56.000+0000
Affected Version/sn/a
Fix Version/sn/a
Componentsn/a
Labelsn/a
ReporterAndrew Sankey
AssigneeAminul Islam
Created2019-11-06T12:57:21.000+0000
Updated2019-12-21T07:25:56.000+0000

Description

We are experiencing a significant slowdown on Android when fetching data from an encrypted database using the appcelerator.encrypteddatabase module v3.1.0. Using the sample todo app provided with the module running on a Nexus 6 device, when profiling the fetch calls, we are experiencing times of up to 1.5 seconds per fetch. For comparison, when fetching from a standard database without encryption, the same calls are taking around 0.058s. We have currently tried implementing suggestions from AC-6207, however these have had no effect.

Attachments

FileDateSize
EncryptedDB_Log.txt2019-12-03T09:08:33.000+000037716
StandardDB_Log.txt2019-12-03T09:08:38.000+000036347

Comments

  1. Aminul Islam 2019-12-02

    Hello! Thanks for reaching out! Could you please add your SDK version and comparison log for with and without the encryption database? Thanks
  2. Andrew Sankey 2019-12-03

    The Titanium SDK used is 8.2.0.GA with the appcelerator.encrypteddatabase module v3.1.0. Device being used is Motorola Nexus 6 running Android v7.1.1. Using the sample todo app provided by the encrypted database, four todo entries where added to the database, then the fetch was profiled within the showTasks method found in index.js. When profiled with the encrypted database, these fetches where taking between 1.68 to 1.85 seconds. With the encrypted database removed, the same fetches where only taking approx. 0.05 seconds. See logs attached. [^EncryptedDB_Log.txt] [^StandardDB_Log.txt]
  3. Aminul Islam 2019-12-04

    Hello! We use the SQLCipher library to implement encrypted SQLite database support on Android and iOS. They provide the following guidance in improving performance... https://discuss.zetetic.net/t/sqlcipher-performance/14 So, transactions should be used when doing multiple INSERTs and UPDATEs as a single batch. And you should be using indexes to reduce the SELECT, INSER, and UPDATE execution times as well. Also, opening the database file is expensive as well and you should leave it open if you are actively using it. Don't open and close it per database transaction. Note that execution times on Android are going to be a bit slower compared to iOS because there is "language-interop" involved. On iOS, the JavaScript, SQLite, and encryption APIs are all implemented in C, so there is no language interop or extra string copies that need to happen. On Android, there's additional overhead with copying the JavaScript C/C++ stringss to/from Java strings (involves transcoding to/from UTF-8 and UTF-16 too). Thanks
  4. Matt Ward 2019-12-06

    Hi, Thank you for your response on optimisation, however please can you perform some testing on the issue raised and confirm whether your can or cannot replicate. As outlined in the issue the timings are based on simple fetch statements from the example code you provide with the encrypted module, whilst we understand there is overhead due to the encryption / decryption the fact are this has now risen from milliseconds to seconds over a couple of versions makes this library totally unusable. Thanks Matt
  5. Aminul Islam 2019-12-19

    Hello! Yes, we can replicate this and it is not a platform bug.We use the SQLCipher library to implement encrypted SQLite database support on Android and iOS. Writes/read to file with encryption is especially expensive. To significantly improve performance, you need to reduce the number of file writes via database "transactions". Thanks

JSON Source