image-gif
image-gif copied to clipboard
Benchmark `common::Frame::from_rgba_speed`
In #110, support was added to bypass the NeuQuant algorithm when the color count was <= 256
so that it could fit in a palette without quantization. The implementation is very straightforward and clear but there may be possible performance improvements. It'd be good to have a benchmark to test changes in this function since it's in the main path for encoding Frame
s.
The following are preliminary thoughts on the topic. They may not be faster than the current implementation.
At the cost of making the logic more complex, there may be a way to reduce allocation and hash calculations in palette creation. A HashSet
is used, collected into a Vec
, and then the Vec
is built into a HashMap
. The HashMap
and palette indexing could be built from the start but manual bookkeeping would need to be introduced for indexing.
https://github.com/image-rs/image-gif/blob/5410cb32f6582114b4cbd5e9ec3878ea3aa358f5/src/common.rs#L220-L255
It's not clear if this sort
is necessary. Maybe it can be made into a sort_unstable
or removed altogether.
https://github.com/image-rs/image-gif/blob/5410cb32f6582114b4cbd5e9ec3878ea3aa358f5/src/common.rs#L239-L243
Original discussion started in https://github.com/image-rs/image-gif/pull/111#discussion_r702281457
I've been working on a personal project using gif
, and wanted to bench a different algo I implemented amongst other things, so I'm currently working on this. I can guarantee the quality of my code as I'm fairly new to rust, but I'll be happy to contribute if it's deemed up to par.
This is what I have so far for benching - it just uses PNGs in the samples directory for the input. https://github.com/foopub/gif_caption/blob/master/benches/rgb_frame_bench.rs I'll be adding more tests soon, and some better sample images.