Performance improvement suggestion
Dear developers, I am a big fan of owncloud. Recently I found some potential slow bitmap displaying implementations in owncloud's code. (1) In the position: com.owncloud.android.ui.adapter.DiskLruImageCache.java getBitmap() (line 125) the bitmap object is created with the invocation of decodeStream(). I found getBitmap() is called by: com.owncloud.android.datamodel.ThumbnailsCacheManager.java getBitmapFromDiskCache() (line 146) and getBitmapFromDiskCache() is called by: com.owncloud.android.ui.adapter.ReceiveExternalFilesAdapter.java getView() (line 116) and com.owncloud.android.ui.adapter.FileListListAdapter.java getView() (line 302)
getView() callbacks are frequently invoked in the UI thread and this means that there will be many bitmap objects being created. Android documentation says this: https://developer.android.com/training/displaying-bitmaps/process-bitmap.html "The BitmapFactory.decode* methods should not be executed on the main UI thread if the source data is read from disk or a network location" Image decoding is slow. So, do you think they will affect owncloud's performance? If yes, for performance considerations, maybe we should perform the image decoding operation in background thread (e.g., via AsyncTask).
In addition, I think we can define memory cache to store the bitmap objects. Then app can reuse them instead of creating new bitmap objects continuously. Also, we can use Option.inbitmap to reuse the memory space of existing bitmap objects, which will reduce the memory consumption and improves app's performance.
(2) In the position: com.owncloud.android.ui.preview.PreviewAudioFragment.java extractAndSetCoverArt() (line 217) the bitmap object is created with the invocation of decodeByteArray (). I found extractAndSetCoverArt() is invoked directly by: com.owncloud.android.ui.preview.PreviewAudioFragment.java onActivityCreated() (line 200) which means image decoding operation is performed in the UI thread. Maybe we should perform the image decoding operation in background thread too.
(3) Android documentation says this: https://developer.android.com/training/displaying-bitmaps/load-bitmap.html#load-bitmap " Images come in all shapes and sizes. In many cases they are larger than required for a typical application user interface (UI)", " To avoid java.lang.OutOfMemory exceptions, check the dimensions of a bitmap before decoding it, unless you absolutely trust the source to provide you with predictably sized image data that comfortably fits within the available memory "
I noticed in the following position, the dimension checking is correctly applied: com.owncloud.android.utils.BitmapUtils.java decodeSampledBitmapFromFile() (line 58 to line 82)
However, in the following positions, the dimension checking is not implemented: com.owncloud.android.ui.preview.PreviewAudioFragment.java extractAndSetCoverArt() com.owncloud.android.datamodel.ThumbnailsCacheManager.java: doOCFileInBackground() So I am curious.
Looking forward to your response and hope I can help improve owncloud. Thanks.
References: The use of Option.inbitmap: https://www.youtube.com/watch?v=_ioFW3cyRV0&list=PLWz5rJ2EKKc9CBxr3BVjPTPoDPLdPIFCE&index=54 https://developer.android.com/training/displaying-bitmaps/manage-memory.html