harrydb/go — pull request #1 by jcmdev0 (2013-08-11 05:22:58+00:00)
Title: 6.34 Speedup in decodeRawRGB with a big-read and fewer slices.

Thanks for putting this library up on github.

I am using go to load some ~80MB pnm files output from a scanner and things were running a little more slowly (13.8s for 10 decode iterations). After a little profiling, I came up with this change for decodeRawRGB. It lowers the number of system calls by reading the RGB data into the start of the RGBA pixel array and then repacks. I initially used copy(m.Pix[i*4:i*4+3], m.Pix[i*3:i*3+3]), but the memmove overhead associated with the slices was still high in the profiling (took ~8s for 10 decodes). Unrolling the slice copy brought it down to ~2.2s for 10 iterations.

Please let me know if you have any concerns.

Thanks,
John