Changing logic to select frameCacheSizeOptimal. #172
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.
Fixed an issue causing delays when playing certain GIF files due to selecting
FLAnimatedImageFrameCacheSizeLowMemory
even thoughFLAnimatedImageFrameCacheSizeDefault
can be selected.Problem
Our app downloads and plays gif files from the server, some of them are very slow to play.
When I tried to figure out the cause,
_frameCacheSizeOptimal
was selected asFLAnimatedImageFrameCacheSizeLowMemory
when loadingFLAnimatedImage
animatedImageWithGIFData
from the file.So it could not read directly from the cache and there was a delay in playback.
This GIF file is 419KB in size, 720 * 200 pixels, and has 300 frames.
CGFloat animatedImageDataSize = CGImageGetBytesPerRow(self.posterImage.CGImage) * self.size.height * (self.frameCount - skippedFrameCount) / MEGABYTE;
=>
animatedImageDataSize = (2880 * 200) * 300 / (1024 * 1024) = 164.795
_frameCacheSizeOptimal
is set toFLAnimatedImageFrameCacheSizeLowMemory
becauseanimatedImageDataSize
is larger thanFLAnimatedImageDataSizeCategoryDefault
(75).When the
_frameCacheSizeOptimal
is set toFLAnimatedImageFrameCacheSizeLowMemory
, the reason for the delay is that whenimageLazilyCachedAtIndex
is performed indisplayDidRefresh
,nil
is returned because there is no image in the cache, and theaccumulator
does not increase induration
.This GIF file has a lot of frames but it does not have a large size per frame, so I think it's a problem to choose not to cache at all.
Fix
This GIF file is small size per frame, so it seems more appropriate to select
FLAnimatedImageFrameCacheSizeDefault
rather thanFLAnimatedImageFrameCacheSizeLowMemory
, and the modified logic can be seen in commit.Check the following youtube link for the video comparing the before/after changes.
before and after video
As a workaround, I can specify an
optimalFrameCacheSize
ofFLAnimatedImageFrameCacheSizeDefault
(5), but I need to useanimatedImageWithGIFData
to automatically select theframeCacheSizeOptimal
because I need to input various GIF files.The following are GIF files with delayed playback problems. (All files with large frameCounts cause problems.)
http://netdna.webdesignerdepot.com/uploads/2013/07/dribble_gif.gif
http://netdna.webdesignerdepot.com/uploads7/50-inspiring-animated-gifs/006.gif
http://netdna.webdesignerdepot.com/uploads/2013/07/2222.gif