Question

I used SQLCipher to encrypt sqlite database and used FMDB for performing sqlite operation on encrypted database by using [FMDB setKey:] call.

My application work slowly when I used SQLCipher with FMDB on encrypted database. If I used only FMDB on non encrypted database then it works properly without taking more cpu uses of the device.

Please help me out here how to resolve this memory cpu uses with SQLCipher & FMDB? Thanks in advance.

Was it helpful?

Solution

There are a few very important guidelines for optimal SQLCipher performance:

  • Do not repeatedly open and close connections, as key derivation is very expensive, by design
  • Use transactions to wrap insert / update / delete operations. Unless executed in a transaction scope, every operation will occur within it's own transaction which slows things down by several orders of magnitude
  • Ensure your data is normalized (i.e., using good practices for separation of data into multiple tables to eliminate redundancy). Unnecessary duplication of data leads to database bloat, which means more pages for SQLCipher to operate on
  • Ensure that any columns that are used for searches or join conditions are indexed. If you don't, SQLCipher will need to execute full database scans across large numbers of pages
  • Vacuum periodically to ensure databases are compact if you do large deletes, updates etc.

Finally, to diagnose further the performance of your specific query statements, could you run an explain query plan command against some of your queries? The output of the explain query command is described here.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top