JuliaIO / GIFImages.jl

Provides Gif support in Julia using LibGif
https://ashwani-rathee.github.io/GIFImages.jl/dev/
MIT License
12 stars 2 forks source link

performance suggestions #19

Open johnnychen94 opened 1 year ago

johnnychen94 commented 1 year ago

The quantizers could possibly be improved, but doesn't have the bandwidth to check it 😢


Use MappedArrays to avoid allocating buffers for res at each iteration. This could be GC-heavy if the image itself is large.

https://github.com/JuliaIO/GIFImages.jl/blob/c3b84d0045bd3b142ae91ab35c6b8b57ef5facbe/src/decode.jl#L62-L65

[] is equivalent to Any[] and is slow. Use Concrete types, e.g., UInt8[]?

https://github.com/JuliaIO/GIFImages.jl/blob/c3b84d0045bd3b142ae91ab35c6b8b57ef5facbe/src/encode.jl#L35

colors should also be a concret type Dict{RGB{N0f8}, UInt8}()

https://github.com/JuliaIO/GIFImages.jl/blob/c3b84d0045bd3b142ae91ab35c6b8b57ef5facbe/src/encode.jl#L48-L51

Computating order matters. Here we want to make sure pix is a dense memory with valid pointer. But we can compute it in one line, e.g., map(x->colors[x], @view(img[:, :, i])'). -- Vector and Matrix should be the same when you get the pointer of it so vec is needless.

https://github.com/JuliaIO/GIFImages.jl/blob/c3b84d0045bd3b142ae91ab35c6b8b57ef5facbe/src/encode.jl#L67-L68