New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
ImageView with webp take more time to fetch disk image when app Re-enter foreground #2227
Comments
@swapnil-vuclip No flicker, means to More over, actually that Also, there are another option. We can keep a global weak NSMapTable for all image instance.(Do not impact the retain count to increase memory usage.) So when memory warning, even the NSCache was purged, your UIImageView.image is alive, so we can get this as from memory cache to allow rendering. And then sync back this alive image to NSCache again. This performance enhancement is scheduled to be done in 5.x, but if user really need this, we can put back in 4.x |
@dreampiggy Thanks for your reply and detailed description on same, Adding the SDWebImageQueryDiskSync worked perfectly for me along with SDWebImageRefreshCached so whenever their is change in server image sdk will fetch and update latest one in disk cache. Updated Code : Also thanks for version 4.3.1 available with improvement on Cache. |
You're welcome :) |
I struggling with one issue related to as we discussed in above thread, When I test with sample app where I added 4-5 UIImageView and load both the format images (jpg & webp) from server, performance wise work fine for me.
2] With jpg images :
@dreampiggy specially need your help on WebP front |
@swapnil-vuclip The only difference between JPEG and WebP is the decoding time. In general, WebP decoding spend 5x time slower than JPEG(Real device on ARM64 platform, not iPhone Simulator). So, I can provide some advice for this. One simple solution is to provide a transition animation when you load the image from disk cache. This can avoid those visual effect. Maybe some cases you can try this to "solve the problem". For other solution, such as use Maybe in 5.x I can introduce a However, since you load the image from disk, there must be duration unlike memory cache, this is un-avoidable :) |
one more how to use in my case NSDataReadingMappedIfSafe in diskCacheReadingOptions |
You should import "UIView+WebCache.h" when using Objective-C. Or import the umbrella headers. Since many user argue for this "cache serializer" feature and it's not API-breaking. I'm considering add this into 4.x in patch version.... |
@swapnil-vuclip See #2245. If you are facing the issue of WebP decoding speed from disk cache. You can considerate to encode the image to another format such like JPEG or PNG when storing to disk cache. |
When would available 4.3.3 via pod? |
As soon as those 4.3.3 milstone merged. Maybe this weekend. |
@dreampiggy Thanks for #2245, I replace both .h&.m files for SDWebImageManager in my pod project but still facing few issues
|
@swapnil-vuclip 😅 There is no magic way to solve this. Because your application was killed or anyway that cause your memory cache invalid. You now have to query disk cache. However, query disk cache need time to first load For disk data time, you can use For decoding time, WebP decoding spend 5x time than JPEG, so I create that PR to allow user to convert the original WebP data from the server to JPEG format and store to cache. Then you just need to decoding JPEG from disk cache. If this duration still not face your limit, you have to find other ways to reduce this visual effect. For example, you can provide placeholder image, add indicator, using view transition...and so on. For that view transition, it was designed to use after download because most time we do not need any transition for image from disk cache. We have one |
@dreampiggy Agreed and thanks for detailed description, how to use/set NSDataReadingMappedIfSafe on SDImageCache.shared.cacheConfig.diskReadingOptions in my case
|
If you want this config applied for all the view category request, set the config to If not(only apppied for current batch of image request), you should now use a little tricky way by using the API in Though this looks suck. In 5.x we will introduce this SDImageCache *imgCache = [[SDImageCache alloc] init];
imgCache.config.diskCacheReadingOptions = NSDataReadingMappedIfSafe;
SDWebImageManager *manager = [[SDWebImageManager alloc] initWithCache:imgCache downloader:SDWebImageDownloader.sharedDownloader];
imageView.sd_imageTransition = SDWebImageTransition.fadeTransition;
[imageView sd_internalSetImageWithURL:imgUrl placeholderImage:nil options:SDWebImageRetryFailed|SDWebImageRefreshCached operationKey:nil setImageBlock:nil progress:nil completed:nil context:@{SDWebImageExternalCustomManagerKey : manager}]; |
#2245 Merged and 4.3.3 released |
@dreampiggy Thanks for 4.3.3 release, |
@swapnil-vuclip See the documents there: SDWebImageManager.sharedManager.cacheKeyFilter = ^NSData * _Nullable(UIImage * _Nonnull image, NSData * _Nullable data, NSURL * _Nullable imageURL) {
SDImageFormat format = [NSData sd_imageFormatForImageData:data];
switch (format) {
case SDImageFormatWebP:
return image.images ? data : nil; // return nil means let `SDImageCache` to automatically choose the data, currently implementation is based on alpha channel, PNG for alpha channel image and JPEG for non-alpha channel image
default:
return data;
}
}; |
New Issue Checklist
Issue Info
Issue Description and Steps
SDWebImage will clear memory cache when app enter background. So, when app enter foreground,
on reloadData, imageView in cell will flicker for jpg images and take more time to load for webp images(If I am not wrong it will take more time to decode webp images), even though cached data haven't changed. I am straggling with webp images, Is their is any way around it to fetch images from disk with no flicker.
[cell.cellImageView sd_setImageWithURL:[NSURL URLWithString:toolsModel.thumbImgUrl] placeholderImage:[UIImage imageNamed:@"background"] options:SDWebImageRefreshCached|SDWebImageRetryFailed];
Steps around reloadData:
show image before reloadData;
find image in SD memory cache, and not found;
find image in SD disk cache, get it async;
load disk image complete and show.
The text was updated successfully, but these errors were encountered: