-
-
Notifications
You must be signed in to change notification settings - Fork 6k
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
Animated webp sd_memoryCost 40 times higher than content-length on browser #3668
Comments
You seems don't understand what's RAM occupation of image The data length != bitmap size The bitmap size = For example, a 1000x1000 GIF with 100 frames will occpuy 381MB See: https://docs.huihoo.com/apple/wwdc/2018/219_image_and_graphics_best_practices.pdf |
You should avoid using Use See: https://github.com/SDWebImage/SDWebImage/wiki/Advanced-Usage#animated-image-50 |
@dreampiggy I am using I've done some more testing and it looks like its connected with setting If I comment out that line, and leave the cache memory unbounded, it loads fine and the app RAM never exceeds 102 mb any ideas what this could be? |
You means, calling |
Can you provide the Instrumentation report (archive zip or send via email to me) ? I check the |
What's this How did you use the decoding and downloader ? When a request from |
No, calling I've done some more digging and i've found the issue. Using the prefetcher, results in Code: @IBOutlet weak var imageView: SDAnimatedImageView!
private let cache = SDImageCache(namespace: "custom-cache")
private var prefetcher: SDWebImagePrefetcher? = nil
private let otherImages: [URL] = [
URL(string: "https://data.mantodev.com/media/mobile900/ipfs/QmZhHfAQsw2kugnbCeAXwdFHuQmajWhxtWkFzVNoaexSkD")!
]
override func viewDidLoad() {
super.viewDidLoad()
cache.clearDisk()
cache.clearMemory()
cache.config.maxDiskAge = 3600 * 24 * 7 // 1 Week
cache.config.maxMemoryCost = UInt(500 * 1000 * 1000) // 500 MB
prefetcher = SDWebImagePrefetcher(imageManager: SDWebImageManager(cache: cache, loader: SDImageLoadersManager()))
}
override func viewWillAppear(_ animated: Bool) {
super.viewWillAppear(animated)
prefetcher?.prefetchURLs(otherImages, progress: { _, _ in
print("prefetch progressed!")
}, completed: { [weak self] processed, skipped in
guard let self = self else {
print("Error grabbing self")
return
}
let bigUrl = URL(string: "https://data.mantodev.com/media/mobile900/ipfs/QmZhHfAQsw2kugnbCeAXwdFHuQmajWhxtWkFzVNoaexSkD")
var context: [SDWebImageContextOption: Any] = [:]
context[.imageCache] = self.cache
self.imageView.sd_imageIndicator = SDWebImageActivityIndicator.gray
self.imageView.sd_setImage(with: bigUrl, placeholderImage: nil, context: context, progress: nil) { image, error, cacheType, returnedUrl in
print("Big image size: \(image?.sd_memoryCost ?? 0)")
}
})
} Run this and it will print the below and hog the main thread
Comment out the URL inside
Why does this prefetcher cause it to use |
Just use prefetch with context[SDWebImageContextAnimatedImageClass] = SDAnimatedImage.class This is common mistake since you load images without a imageView as context. We don't know your preserved one. I fired a proposal to make this more easy to customize, see that #3669 ans comment there |
@dreampiggy that worked perfect, thank you |
Issue Info
Issue Description and Steps
I'm integrating a server that returns certain webp images in different sizes. Some animated, some not. Using small animated images where content length is 1.3 mb, SDWebImageCache loads them and animates fine, with the
image?.sd_memoryCost
being quite close to the content-length / download sizee.g. https://data.mantodev.com/media/mobile180/ipfs/QmZhHfAQsw2kugnbCeAXwdFHuQmajWhxtWkFzVNoaexSkD
However when using a large size, where the content-length is 12.3mb, the
image?.sd_memoryCost
skyrockets to 481 MB. This blocks the main thread for a long time, crashing the app.e.g. https://data.mantodev.com/media/mobile900/ipfs/QmZhHfAQsw2kugnbCeAXwdFHuQmajWhxtWkFzVNoaexSkD
For now, i've added some code to check for max memoryCost and if it exceeds, just load the first frame and don't animate. But this offers a poor UX, especially since the small one animates fine in the "thumbnail view", and is then frozen in the "detail view".
Can someone have a look at why the large image has such a large different in sizes?
And is there any other suggested ways I could handle this? I tried adding some transformers to decrease the size, but it still caused the main thread to block
The text was updated successfully, but these errors were encountered: