Closed koji-1009 closed 1 year ago
I would like to try!
This issue seems difficult! Can you do it!? I'm looking forward to your implementation!
Maybe, related this issue. https://github.com/coil-kt/coil/issues/1610
@koji-1009 @takahirom
Hi! I'm also very curious about this issue and looked into it, but would it be okay whether to share my finding here?
@h6ah4i Of course! I am very interested in that!
Only in the environment at hand, I was able to avoid this problem by using AsyncImage of coil-compose instead of Image. I am currently checking the difference between AsyncImage and rememberAsyncImagePainter.
Thank you so much for the approvals!
First, I thought the sponsors screen has many images listed on it and they must be the bottleneck of the performance issue. So I used the profiler tool and network inspection tool to dig in what is going on here, and I noticed two things that affect performance significantly.
Next, I made a small code change to confirm my hypothesis is correct. Replace all logo images with a small dummy ones, like the following. (It worked very well and the performance issue seems resolved!)
) {
Image(
painter = previewOverride(previewPainter = { rememberVectorPainter(image = Icons.Default.Image) }) {
- rememberAsyncImagePainter(sponsor.logo)
+ rememberAsyncImagePainter(url = "https://avatars.githubusercontent.com/u/2552365?s=48&v=4")
},
contentDescription = sponsor.name,
This issue can be resolved by using smaller (appropriate) sized image files.
I think adding a thumbnail logo URL field to the API response is the most preferred way (if possible...).
Adding a caching layer of resized image files on app side should also resolves the issue, but it seems much difficult because the app have to run on multi-platform...
Update: It looks like Compose ImageLoader already supports the maxImageSize
option and it might work both Android and iOS...?
Update-2: The maxImageSize
option has been introduced in the latest version v1.6.5. It was just 5 days ago :tada: https://github.com/qdsfdhvh/compose-imageloader/releases/tag/1.6.5
It looks like the original image is preserved when converting to Painter. In the case of coil, it is resized to the display size, but it seems that compose-imageloader not resized.
Perhaps, but the AsyncImage#updateRequest is critical point. It appears that the ConstraintsSizeResolver is giving the image request a reasonable size, a situation that preserves performance.
@koji-1009
I've just created a new experimental branch to utilize the maxImageSize
option. Can you test this? It looks the performance has been significantly improved!
I suppose that we still need to take care more things like:
300
px should be replaced with more appropriate values@h6ah4i Thank you! I was just trying a similar implementation. At 300, there seems to be no problem with the performance of the sponsor screen. Around 1400~1500 larger, the sponsor screen seems to be affected by scrolling.
For this reason, it seems to me that it would be a good idea to limit the number to around 1024. I have looked at the other features of the app and consider the value to be without major problems.
Updating the min sdk seems to be the most issue. I looked at the differentials but could not determine how they were affected...
https://github.com/qdsfdhvh/compose-imageloader/compare/1.6.4...1.6.5
I found one more problem with the Compose ImageLoader v1.6.5.
Their default implementation does not include the com.seiko.imageloader.option.Option
(including maxImageSize
) into cache key string. I have not confirmed it yet, but it seems like unexpected cache conflictions will occurs.
Fortunately, the cache key generation logic can be extensible because it is abstracted as a chain of com.seiko.imageloader.component.keyer.Keyer
instances. I'm currently looking for a place where is the most relevant to inject our custom Keyer implementation.
It reads as if the scale is not used when downloading the image, but the maxImageSize is used when creating the bitmap. Therefore, it seems that maxImageSize does not need to be included in the key when saving to disk.
I think disk cache is okay, but the memory cache has a problem. It just returns a scaled Bitmap instance for an original source URL without considering the maxImageSize
option.
Wait, do we only have to take care about Android? The iOS version seems have different implementation for UI including image loader mechanism. I was trying to find an alternative to CompositionLocalProvider (ref. Use custom ImageLoader) on iOS, but it seems I'm doing something wrong.
I'm not sure how iOS version of this app works, but I thought Coil has been replaced with Compose ImageLoader in order to support iOS... (#258)
@h6ah4i Thank you for your research! I understand now.
Would memory cache be a problem in cases where the same image is retrieved with different maxImageSize
? In this case, if maxImageSize
is constant, it seems to be avoidable.
(Therefore, it may be OK to simply specify maxImageSize
as a fixed value.)
https://github.com/DroidKaigi/conference-app-2023#module-structure
We've added experimental support for Compose Multiplatform on certain screens, making the features accessible from the iOS app module as well."
It seems that sponsor screen is not a shared target module? If it is ok to split it, that is looks good to me that replacing it with coil would be the best.
Hi @takahirom, which option should I choose?
Would memory cache be a problem in cases where the same image is retrieved with different maxImageSize? In this case, if maxImageSize is constant, it seems to be avoidable.
True. That works for the simplest workaround for current situation :wink:
Also, I have created a minimal sample project to reproduce the cache confliction issue. I'm going to feedback it to the author of Compose ImageLoader project.
I'm going to feedback it to the author of Compose ImageLoader project
I've mentioned the author but the bug report is better. So I removed the comment 🙇
@koji-1009 I think it is good to use Coil for sponsor screen 👍
@takahirom Thank you very much! I will recreate PR!
FYI: I have reported the Compose ImageLoader's memory cache issue here; https://github.com/qdsfdhvh/compose-imageloader/issues/279
Thanks for the report, I will fix it tomorrow, i'm going to io connect today.
Describe the bug When the sponsor screen is displayed and scrolled, it is slower to respond than other screens. (ex. About, Staff, Contributor)
To Reproduce Steps to reproduce the behavior:
Expected behavior When the sponsor screen is displayed and scrolled, it is same to respond as other screens.
Screenshots
https://github.com/DroidKaigi/conference-app-2023/assets/17231507/5fc25bbe-a31d-4d06-84fe-64d00766685f
Enviroment