Conversation
bcc9dee to
b90703c
Compare
|
Updates Context.kt (loadImageBase):
Context.kt (loadImage):
Context.kt (preloadImageBase):
MediaAdapter.kt:
SvgModule.kt:
The cachedThumbnailSize defaults to 0 until the first prefetch measures a child view, so the very first few binds before |
|
This work has significantly improved the app experience for me. Theres no test in the repo, but pull down these changes build and test locally in a large library. you will notice how much snappier everything loads immediately. |
|
noticed small bugs when:
will fix and update PR. |
b90703c to
63344d1
Compare
|
Hello. Thank you. I tested it on an emulator and on a real device. Media file thumbnails load faster, but folder thumbnails load very slowly, with some taking several seconds to appear. |
|
thanks for checking it out! hmm i have it installed on two devices and using because its such a huge improvement for me and I'm not encountering that behavior. the largest album i have has like 500+ photos/videos. did you pull the latest commit? cache size? and was that behavior even after the initial load? Edit: ohh you mean the photo thumbs of the actual folder itself? yes i noticed that a compressed version first appears and then will eventually render the higher quality thumb. let me make sure I'm prioritizing caching of that folder thumb. if subsequent loads are caching correctly is the initial behavior okay with you or how would you like it to be changed? |
|
I made a screen recording from the emulator. The first app with the black theme is your changes, and the second white one is without your changes. Folder thumbnails take a long time to load after unloading the app from memory. It's faster on a physical device, but still much slower than in the old version. Another problem appeared on the emulator that is not present on my physical device: when updating media files, the files get mixed up. I haven't figured out why this is happening yet. |
63344d1 to
6472149
Compare
|
@Goodwy updated the PR, issues should be fixed. Prioritized caching / retrieval of folder thumbs and the slow low res step. on fresh app cold start latency is expected to be slow. After that, the app should be loading gallery thumbs much much faster. I also updated behavior around built in photo editor. when new photo is created or existing media is over written it should trigger a gallery thumb refresh instead of having to manually do so. |
Thumbnail Loading Optimization
1. Robust Thumbnail Prefetching
The bulk of the optimization comes from new prefetching logic in
MediaAdapter.ktandDirectoryAdapter.kt.MediaAdapter(and 20 items inDirectoryAdapter).MediaAdapterprefetching at either 48 items OR24MBof estimated uncompressed bitmap memory (prefetchSizeBudgetBytes = 24L * 1024L * 1024L). This ensures aggressive preloading won't cause Out-Of-Memory (OOM) crashes on low-end devices.highPriorityLookAheadItems) with Glide'sPriority.HIGH, while the rest getPriority.NORMAL. This ensures the images the user is about to see right now are prioritized over images further down the scroll buffer..thumbnail(0.1f)directive to the Glide builder insideloadImageBase. This means while the full quality thumbnail is loading, Glide will display a 10% resolution placeholder instantly.2. "Show All" View Optimization (I/O Bottleneck Fix)
The "Show all folders" view in Android 11+ (Scoped Storage) is notoriously slow because it has to heavily query the
MediaStore.GetMediaAsynctask.kt, whenshowAllis true, it now performs a single, upfront query viagetAndroid11FolderMedia().prefetchedAndroid11FilestomediaFetcher.getFilesFrom(). This avoids each individual folder scan having to redundantly hit the I/O layer.maybeRunMediaDbMaintenance()which silently runs in the background on a 6-hour interval to clean up stale and deleted rows in the database in batches of 100. A smaller, cleaner Room DB means much faster disk queries.3. Smart App Memory Management
Tightly couples Glide's memory behaviors with the Android Application Lifecycle:
App.ktwas modified to listen toonTrimMemory. When the UI is hidden (the app is in the background), Glide's memory category is dropped toLOW. When memory is critically low (onLowMemory), the cache is wiped.SimpleActivity.onResumebumps the memory category back toNORMAL. This frees up RAM when the user isn't using the app, but maximizes caching when they are.4. User-Configurable Cache Setting
SettingsActivityusing a Radio Button dialog.100 MB,256 MB,512 MB,1024 MB, and2048 MB. The default is set to512 MB.SvgModule.kt(which serves as theAppGlideModule), the app reads this exact Config state and dynamically applies it to Glide'sInternalCacheDiskCacheFactory. It also expanded the RAM allowance to keep exactly 3 screens worth of thumbnails in active memory (setMemoryCacheScreens(3f)).The scroll performance should be significantly smoother due to the budgeted prefetching, the
showAllquery will be unblocked on Android 11+, and the user now has direct control over how much storage the app uses for caching.