Take long time for first access Cipher Room Database
I Cipher Room database with code bellow.
final byte[] passphrase = SQLiteDatabase.getBytes(DatabaseHelper.KEY.toCharArray());
final SupportFactory factory = new SupportFactory(passphrase);
mInstance = Room.databaseBuilder(context, AppDatabase.class, DB_NAME)
.openHelperFactory(factory)
.fallbackToDestructiveMigration()
.allowMainThreadQueries()
.build();
EdcmDao abc = mInstance.edcmDao();
Log.d("开发者_StackOverflow社区Database", "Database begin");
abc.deleteEdcmInfo();//--No data in EDC Table
Log.d("Database", "Database end");
The problem takes about 2-3 seconds to access the database the first time but I don't know why? Can we speed up it?
[Take 2-3s to show log "Database end" after "Database begin"]
Opening the database is relatively resource intensive, opening a Cipher database will be even more intensive as the entire database has to be deciphered as part of the open.
Room itself adds some additional overheads as it has to compare the hash stored in the room_master_table against the compiled hash.
Deletion of rows, even if there are none, is not the least intensive operation (assuming that you are just using this to force an open). So perhaps try instead to just force an open instead of using abc.deleteEdcmInfo();
e.g.
mInstance.getOpenHelper().getWritableDatabase();
Although I suspect that it would make little difference, but would confirm that the deletion is or is not the bottle neck.
精彩评论