[AC-6427] EncryptedDB - Android - Fetching from db very slow.
GitHub Issue | n/a |
Type | Bug |
Priority | n/a |
Status | Closed |
Resolution | Done |
Resolution Date | 2019-12-21T07:25:56.000+0000 |
Affected Version/s | n/a |
Fix Version/s | n/a |
Components | n/a |
Labels | n/a |
Reporter | Andrew Sankey |
Assignee | Aminul Islam |
Created | 2019-11-06T12:57:21.000+0000 |
Updated | 2019-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
Hello! Thanks for reaching out! Could you please add your SDK version and comparison log for with and without the encryption database? Thanks
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]
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
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
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