Improve decoding full-sized images in RCTImageLoader
#54127
Closed
+22
−12
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.
Summary:
In Expo, someone reported (expo/expo#40158) that
expo-image-manipulator
causes memory crashes when processing large images (> 30MB).Image manipulator uses
RCTImageLoader
to load and decode images. As opposed to the Image component, it always requests for images in full size. For large images it may crash atCGImageSourceCreateThumbnailAtIndex
which in the provided repro slowly increases memory usage until it finally crashes after a few seconds of running.I figured out that not including the
kCGImageSourceThumbnailMaxPixelSize
option works much better, but usingCGImageSourceCreateImageAtIndex
instead ofCGImageSourceCreateThumbnailAtIndex
works even better – it's faster and consumes less memory during decoding. This is more or less whatSDWebImage
library does, seeSDImageIOAnimatedCoder
.With the proposed changes, it's still crashing but only for the largest image (64MB), other images (40MB and 50MB) are now working fine. Obviously, it cannot be fixed entirely and it's not recommended to load such big images without downscaling them.
Changelog:
[IOS] [CHANGED] - Use
CGImageSourceCreateImageAtIndex
instead ofCGImageSourceCreateThumbnailAtIndex
to decode full-sized imagesTest Plan:
I've tested the examples of the
Image
component in RNTester as well as the repro provided in expo/expo#40158