image icon indicating copy to clipboard operation
image copied to clipboard

Frame blending/disposal in GIF decoder branches for every pixel

Open Shnatsel opened this issue 2 years ago • 0 comments

This happens in image v0.24.7 as well as the latest git on commit 96b8cee8fef5893e49dc1c79a654b962fcbe2be8

The following function is currently called for every pixel in the image when decoding animated GIFs:

https://github.com/image-rs/image/blob/96b8cee8fef5893e49dc1c79a654b962fcbe2be8/src/codecs/gif.rs#L289-L319

As you can see, it has non-trivial branches on every pixel, and no vectorization. Its performance could be considerably improved by branching once on the disposal method outside the loop, since the blending method is the same for every frame; and then calling the appropriate loop with no branches that operates on multiple elements at once, e.g. via slice::chunks_exact_mut.

However I have not checked how much time is spent with this function with a profiler. It might be that this function is Fast Enough :tm: (although I doubt that).

Shnatsel avatar Jan 09 '24 02:01 Shnatsel