Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Description
Closes #1176.
This PR does another major improvement to the
SDWebImage
cache implementation.Memory improvement with
shouldDecompressImages
When enabling the
SDWebImage
-settingshouldDecompressImages
, anyUIImage
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
-settingshouldDecompressImages
, anyUIImage
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 targetedUIImageView
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