mozilla/pdf.js — pull request #4264 by fkaelberer (2014-02-08 19:23:17+00:00)
Title: Faster JPX decoding

This PR reduces decoding time of JPX images by some 10 to 25 percent, and so improves #2790 and #2103 a little bit.

Roughly 50 % of JPX decoding time is spend for (arithmetic) decoding of the byte stream, and the remaining 50 % is (mostly) spend on the wavelet transform. This PR concerns wavelet transform.
During the wavelet transform, rows and columns of the images are processed individually, and the bottleneck is mainly memory copy performance to access rows and cols.

This PR increases memory performance by
1. using `Array.set()` when reading rows and
2. reading multiple columns at a time to avoid cache misses:

```
// Accesses to the items array can take long, because it may not fit into
// CPU cache and has to be fetched from main memory. Since subsequent
// accesses to the items array are not local when reading columns, we
// have a cache miss every time. To reduce cache misses, get up to
// 'numBuffers' items at a time and store them into the individual
// buffers. The colBuffers should be small enough to fit into CPU cache.
```

Using different settings, I measured the following timings. Numbers are averaged over the first 4 pages of #2790, but are similar for other JPX-heavy pdfs.

5201ms --> 3827ms (-26%) Firefox Nightly 30a1 Linux (in a VM)
4681ms --> 3951ms (-16%) Firefox Nightly 30a1 Win7-64
6704ms --> 5649ms (-16%) Chrome 34 dev Linux (in a VM)
5538ms --> 4797ms (-13%) Chrome 34 dev Win7-64