eugeneware/jpeg-js — pull request #6 by metabench (2014-08-09 12:30:35+00:00)
Title: Speed Optimizations

Please note - the code is not tidied up, there are lots of commented out console.log statements, I have left code which is yet to be deleted. I'm still working on the code, and plan to get more optimizations done. I didn't want to rearrange the code yet, but wanted to send what I had done once I had seen very high speed increases (about 334%, depending on how it's calculated).

-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~

Have replaced the use of many Int32Arrays with a single 'matrix'
Int32Array for each component. Created new versions of functions that
interact with that array.

Removed the 'buffer copy' code at the end by writing
getData_rgb_to_rgba_buffer, which writes directly to an RGBA buffer.

In the test I did, observed decoding time decreased from 3300ms to 760ms.

I also got it to calculate a few variables that get used multiple times, like XscaleX and YscaleY. I don't know if those other optimizations really sped it up, it was changing to the blocks_matrix that really made the difference, and then making it write the result directly to the RGBA node Buffer made a big difference too.

There are further optimizations that can yet be made, to do with better
use of typed arrays, and not allocating various variables multiple
times, but reusing space in typed arrays.