Android sqlite / BLOB perfomance issue

对着背影说爱祢 提交于 2019-11-29 04:08:56

问题


Ever since I moved my data from ArrayList to a sqlite database on Android, I have a serious performance drop. There are no cursors left open that could cause that, so I suspect that the problem is with the images I store in a BLOB field.

The application creates Cards that have a field cardBitmap that gets populated with a bitmap upon creation.

Can anyone tell me from their experience, what solution is more performant:

  1. cardBitmap holds a reference (path) to a file on SDcard that will be drawn upon creation. Only path is stored in DB.
  2. cardBitmap holds an object (BitmapFactory.decodeStream(imageStream,null,null)), where imageStream is read as a ByteArrayInputStream from the corresponding database field.

Any suggestions would be helpful. Thanks!


回答1:


Your first solution is better one, Use a file from sdcard and store the reference path in your sqlite database, This gives you faster performance and also your database is remain light weight.




回答2:


I don't have the reputation yet to comment an answer, so I'll add my 2cts as an answer instead, please forgive me.

I was looking for an answer to a similar question and I don't think the current answer is satisfying because if you ask SQLite.org they'll tell you that it depends on the blob size and on the page size.

They have done a benchmark - not on android though - that shows that storing blobs in SQLite is faster for small blobs (up to 20kB) than storing on separate files. For blobs greater than 100kB though, the performance drop is big and it's better storing the blobs in separate files as you ( user370605 ) recommend. See http://www.sqlite.org/intern-v-extern-blob.html

I'll consider the question not answered regarding Android.




回答3:


I have not enough reputation to do comments as well. I'm adding this answer to help anyone who still looking for some suggestion. After several years hardware improvement, performance of that two solutions have little difference. I've tried several times in my Nexus 6p writing an about 2 MB image binary to SQLite only takes 50 ms in average. Even though external storage will perform better, current performance can meet my expectation. Write to SQLite do not need WRITE_EXTERNAL_STORAGE permission which may be revoke if permission granted from other apps. In this case, SQLite can be a good choice.



来源:https://stackoverflow.com/questions/8400540/android-sqlite-blob-perfomance-issue

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!