PistonDevelopers/image — pull request #102 by lifthrasiir (2014-09-26 04:03:44+00:00)
Title: Use a `BufferedReader` on `image::open`

Many image decoders and encoders operate on the byte-sized I/O, so the non-buffered reader is very bad for the performance. This PR fixes the non-generic portion of the problem (the user cannot really control the internals of `image::open`). I also strongly recommend not to allow using an arbitrary `Reader` for decoders; they should have the `Buffer` bound instead.

Non-scientific experiments: I've used an [8-bit indexed PNG](http://upload.wikimedia.org/wikipedia/commons/8/81/Grub_logo_large.png) for benchmarking both the filtering and palette expansion. Each step roughly corresponds to statements in `PNGDecoder::read_baseline`.

~~~~
rust-png before: TOTAL 278746708ns
parsing 251517832ns
(deflate 244435857ns)
filtering 22801442ns
copying 466346ns
palette-expansion 52890ns

rust-png after: TOTAL 134008444ns
parsing 106510307ns
(deflate 103497009ns)
filtering 23039392ns
copying 460653ns
palette-expansion 51760ns
~~~~

For the comparison, ImageMagick (`convert -debug coder Grub_logo_large.png null:`) takes about 50ms to decode the image.