Description
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.
Lines 220 to 255 in 5410cb3
It's not clear if this sort
is necessary. Maybe it can be made into a sort_unstable
or removed altogether.
Lines 239 to 243 in 5410cb3
Original discussion started in #111 (comment)