Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

performance suggestions #19

Open
johnnychen94 opened this issue Apr 24, 2023 · 0 comments
Open

performance suggestions #19

johnnychen94 opened this issue Apr 24, 2023 · 0 comments

Comments

@johnnychen94
Copy link
Member

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.

res = map(x -> RGB{N0f8}(x.Red / 255, x.Green / 255, x.Blue / 255), colortypes)
res = reshape(res, Int(loaded_gif.SWidth), Int(loaded_gif.SHeight))
res = res'
final[:, :, i] = res

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

colors = []

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

mapping = Dict()
for (i, j) in enumerate(colors)
mapping[j] = UInt8(i-1)
end

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.

img1 = vec(collect(@view(img[:, :, i])'))
pix = map(x -> mapping[x], img1)

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

No branches or pull requests

1 participant