Performance improvement suggestion
Dear developers, I found several bitmap displaying issues in document-viewer. These issues could affect performance. In the position of document-viewer: org.ebookdroid.common.cache.ThumbnailFile.java load() https://github.com/SufficientlySecure/document-viewer/blob/master/document-viewer/src/main/java/org/ebookdroid/common/cache/ThumbnailFile.java `
private Bitmap load(final boolean raw) {
if (this.exists()) {
final Bitmap stored = BitmapFactory.decodeFile(this.getPath());
if (stored != null) {
return raw ? stored : paint(stored);
}
}
return getDefaultThumbnail();
}
` the bitmap object is created with the invocation of BitmapFactory.decodeFile(). I found load() is invoked indirectly by: org.ebookdroid.ui.library.adapters.RecentAdapter.java getView() org.ebookdroid.ui.library.adapters.BookShelfAdapter.java getView()
getView() callbacks are frequently invoked in the UI thread and this means that there will be many bitmap objects being created in the UI thread. Since image decoding is slow, for performance considerations, we should perform the image decoding operations in worker threads (e.g., via AsyncTask).
In addition, maybe we can define memory cache and disk memory cache to store the bitmap objects. Then app can reuse them instead of creating new bitmap objects continuously. Also, we can use the Option.inbitmap to reuse the memory space of existing bitmap objects instead of consuming new memory space, which will greatly reduce the memory consumption and improves app's performance.
By the way, I noticed that in the following code, disk memory cache is correctly applied: org.ebookdroid.ui.opds.adapters.LoadThumbnailTask.java loadBookThumbnail() https://github.com/SufficientlySecure/document-viewer/blob/master/document-viewer/src/main/java/org/ebookdroid/ui/opds/adapters/LoadThumbnailTask.java `
final Bitmap image = BitmapFactory.decodeStream(new FileInputStream(file), null, opts);
if (image != null) {
thumbnailFile.setImage(image);
image.recycle();
}
`
Maybe we can also define memory cache and use Option.inbitmap here.
Do you think these optimizations can improve document-viewer's performance?
Looking forward to your response and hope I can help improve document-viewer. Thanks.
References: Processing Bitmaps Off the UI Thread https://developer.android.com/training/displaying-bitmaps/process-bitmap.html the use of disk memory cache and memory cache: https://developer.android.com/training/displaying-bitmaps/cache-bitmap.html the use of Option.inbitmap: https://developer.android.com/training/displaying-bitmaps/manage-memory.html