Skip to content

Conversation

@momoraul
Copy link

@momoraul momoraul commented Feb 5, 2017

Fixed an issue causing delays when playing certain GIF files due to selecting FLAnimatedImageFrameCacheSizeLowMemory even though FLAnimatedImageFrameCacheSizeDefault 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 as FLAnimatedImageFrameCacheSizeLowMemory when loading FLAnimatedImage 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 to FLAnimatedImageFrameCacheSizeLowMemory because animatedImageDataSize is larger than FLAnimatedImageDataSizeCategoryDefault (75).

When the _frameCacheSizeOptimal is set to FLAnimatedImageFrameCacheSizeLowMemory, the reason for the delay is that when imageLazilyCachedAtIndex is performed in displayDidRefresh, nil is returned because there is no image in the cache, and the accumulator does not increase in duration.

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 than FLAnimatedImageFrameCacheSizeLowMemory, 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 of FLAnimatedImageFrameCacheSizeDefault (5), but I need to use animatedImageWithGIFData to automatically select the frameCacheSizeOptimal 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

- Fixed an issue causing delays when playing certain GIF files due to selecting FLAnimatedImageFrameCacheSizeLowMemory even though FLAnimatedImageFrameCacheSizeDefault can be selected.
- Modify the existing conditions to maintain.
@momoraul
Copy link
Author

momoraul commented Feb 6, 2017

Modify the existing conditions to maintain.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant