k3b / APhotoManager

Manage local photos on Android: gallery, geotag with photomap, privacy, tags, find, sort, view, copy, send, ... .
GNU General Public License v3.0
224 stars 57 forks source link

Performance improvement suggestions #196

Open sunshinelwj opened 2 years ago

sunshinelwj commented 2 years ago

When loading images, Google suggests us to cache the bitmaps that can be reused, so as to keep a fluid and fast-loading UI. https://developer.android.com/topic/performance/graphics/cache-bitmap.html

However, in the code below, bitmap caching is not applied: de.k3b.android.androFotoFinder.imagedetail.HugeImageLoader.java loadImage() https://github.com/k3b/APhotoManager/blob/FDroid/app/src/main/java/de/k3b/android/androFotoFinder/imagedetail/HugeImageLoader.java#L75

I found loadImage() is invoked directly by: de.k3b.android.androFotoFinder.gallery.cursor.GalleryCursorAdapterFromArray.java getView() https://github.com/k3b/APhotoManager/blob/FDroid/app/src/main/java/de/k3b/android/androFotoFinder/gallery/cursor/GalleryCursorAdapterFromArray.java#L99

getView() is a function that is frequently invoked, which means that there will be many duplicate bitmap objects being created if we not define a cache to store them.

For performance considerations, 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. In addition, since image decoding is slow, we can perform these operations in worker threads (e.g., via AsyncTask).

Thanks.