wvanbergen/chunky_png — pull request #60 by lencioni (2014-04-13 23:32:33+00:00)
Title: Improve performance of Palette.from_canvas

When saving a Canvas to a PNG file, we end up initializing an instance
of a Palette from the canvas pixels. Since the canvas pixels are stored
as an array, and Palette subclasses SortedSet, we end up with a
SortedSet of the unique colors in the Canvas.

While this works fine, I discovered that it could be a bit faster. After
some experimentation, it looks like if we first call `.uniq.sort` on the
pixel array before initializing the SortedSet, we can achieve some nice
performance wins with identical results. This was tested under Ruby
2.1.0.

For more context on the performance characteristics of this change, see:

trotzig/diffux#76 (comment)
trotzig/diffux#76 (comment)

We may also be able to use a similar technique in `.from_pixels`, but
since I am not aware of how that method is called and since it doesn't
benefit my current use-case, I am hesitant to make the same change there
at this time.