mattdesl / gifenc

fast GIF encoding
MIT License
301 stars 20 forks source link

Optimize pnnquant2.js #4

Closed p01 closed 7 months ago

p01 commented 3 years ago
mattdesl commented 3 years ago

Hey thanks!

I don't think indexOf will work as we are dealing with array equality:

[ [2, 255, 5] ].indexOf([ 2, 255, 5 ])
// -> -1

Second thing, I don't think "fill palette" is actually a hot code path (typically we are dealing with 256 colors or less) so I'm not sure it's worth optimizing at the expense of legibility/simplicity.

Did you manage to benchmark the others in Chrome? I think I tested inlining create_bin() and IIRC it performs about the same or better, but I could be mistaken.

mattdesl commented 3 years ago

I ended up cherry-picking a couple of these patches into the latest build, you could resolve conflicts and we could see if there's anything else here that could be optimized. I also didn't see much of a change in benchmarks when inlining the create_bin function.

p01 commented 3 years ago

I need to verify the code, 'coz I use Github's UI to resolve the conflict :p