xbmc / Official-Kodi-Remote-iOS

Full-featured remote control for XBMC Media Center. It features library browsing, now playing informations and a direct remote control.
Other
224 stars 104 forks source link

Rework image cache #1186

Closed wutschel closed 1 week ago

wutschel commented 3 weeks ago

Description

Closes https://github.com/xbmc/Official-Kodi-Remote-iOS/issues/1176.

This PR does another major improvement to the SDWebImage cache implementation.

Memory improvement with shouldDecompressImages

When enabling the SDWebImage-setting shouldDecompressImages, any UIImage loaded from flash to in-memory retained the CG context of the decompressed image. This PR applies a change to the decompression which results in not retaining this copy anymore. The memory consumption for the image cache is reduced to 50%.

Memory improvement without shouldDecompressImages

When disabling the SDWebImage-setting shouldDecompressImages, any UIImage loaded from flash to in-memory retains the (PNG) data loaded from flash. In this case the memory consumption is reduced to about 60%.

Pre-scaling to target resolution and aspect ratio

After reviewing the implementation in-depth, it became clear that thumb images are not really fully scaled to the target resolution, which would require content fill method to be taken into account at this stage. In fact, the image's aspect ratio was kept, and the thumbs were only scaled half-way to meet to minimum resolution requirements. Examples:

This caused some scaling do be processed by UIImageView, if target and image have different aspect ratios. In addition, the PNG image saved to flash used more pixels and therefore size. This is prominent especially when target and image aspect ratio mismatch a lot, like for TV station logos in grid view.

This PR now scales images to the exact target resolution and aspect ratio before writing them to flash. The implementation takes into account the UIViewContentMode used by the targeted UIImageView to avoid any image scaling after this initial image caching.

Summary for release notes

Improvement: Reduce memory consumption of image cache Improvement: Image cache pre-scales to target resolution and aspect ratio Improvement: Reduce load by avoiding unwanted image scaling / processing