Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Faster JPX decoding #4264

Merged
merged 1 commit into from
Feb 24, 2014
Merged

Conversation

fkaelberer
Copy link
Contributor

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

@Snuffleupagus
Copy link
Collaborator

/botio test

@pdfjsbot
Copy link

pdfjsbot commented Feb 8, 2014

From: Bot.io (Linux)


Received

Command cmd_test from @Snuffleupagus received. Current queue size: 0

Live output at: http://107.21.233.14:8877/1a2e69cdc7f0d44/output.txt

@pdfjsbot
Copy link

pdfjsbot commented Feb 8, 2014

From: Bot.io (Windows)


Received

Command cmd_test from @Snuffleupagus received. Current queue size: 0

Live output at: http://107.22.172.223:8877/259980401037aca/output.txt

@pdfjsbot
Copy link

pdfjsbot commented Feb 8, 2014

From: Bot.io (Linux)


Failed

Full output at http://107.21.233.14:8877/1a2e69cdc7f0d44/output.txt

Total script time: 21.33 mins

  • Font tests: Passed
  • Unit tests: Passed
  • Regression tests: FAILED

Image differences available at: http://107.21.233.14:8877/1a2e69cdc7f0d44/reftest-analyzer.xhtml#web=eq.log

@Snuffleupagus
Copy link
Collaborator

Since Chrome timed out, let's re-run the test.

/botio-linux test

@pdfjsbot
Copy link

pdfjsbot commented Feb 8, 2014

From: Bot.io (Linux)


Received

Command cmd_test from @Snuffleupagus received. Current queue size: 0

Live output at: http://107.21.233.14:8877/bac70aa27711e01/output.txt

@pdfjsbot
Copy link

pdfjsbot commented Feb 8, 2014

From: Bot.io (Windows)


Success

Full output at http://107.22.172.223:8877/259980401037aca/output.txt

Total script time: 38.20 mins

  • Font tests: Passed
  • Unit tests: Passed
  • Regression tests: Passed

@pdfjsbot
Copy link

pdfjsbot commented Feb 8, 2014

From: Bot.io (Linux)


Success

Full output at http://107.21.233.14:8877/bac70aa27711e01/output.txt

Total script time: 23.76 mins

  • Font tests: Passed
  • Unit tests: Passed
  • Regression tests: Passed

@timvandermeij
Copy link
Contributor

/botio-linux preview

@pdfjsbot
Copy link

pdfjsbot commented Feb 8, 2014

From: Bot.io (Linux)


Received

Command cmd_preview from @timvandermeij received. Current queue size: 0

Live output at: http://107.21.233.14:8877/a196da3bbb51d1d/output.txt

@timvandermeij
Copy link
Contributor

@fkaelberer It is indeed loading faster, but I notice the page loading indicators stop spinning when the pages are loading. This isn't the case with the current viewer. Can you reproduce that?

@fkaelberer
Copy link
Contributor Author

No... at least not on Firefox / Windows / pdf.js.xpi

@timvandermeij
Copy link
Contributor

@fkaelberer I see that I should have been more specific, so I'm not sure we were talking about the same issue. I meant that the loading indicator shows up, but doesn't spin when loading pages from the bird book PDF from #2790. The default (Tracemonkey) PDF for example is fine, only PDFs with JPX images seem to be affected.

Steps to reproduce for me are:

  1. Download the bird book PDF from Slow rendering of the books from Archive.org #2790.
  2. Open it with http://107.21.233.14:8877/a196da3bbb51d1d/web/viewer.html. Notice the page loaders not spinning when a page is loading.
  3. Open the same file with http://mozilla.github.io/pdf.js/web/viewer.html. Notice the page loaders spinning when a page is loading.

My configuration: Windows 7 x64, Firefox Nightly 30.0a1 (HWA on, 64 bit) and the viewer from the generated preview above.

@Snuffleupagus
Copy link
Collaborator

@timvandermeij Following your STR, I'm not able to reproduce that issue. The spinners work fine even with this patch applied.

Configuration: Windows 7 (64-bit), Firefox Nightly 30 (buildID: 20140208030207) with HWA on.

@timvandermeij
Copy link
Contributor

Hm, I cleared the cache again and now it's working. That's strange because I have cache disabled by default, but I'm happy that it's not an issue caused by this patch!

for (var v = 0; v < height; v++, k += width, l++)
buffer[l] = items[k];
// if we ran out of buffers, copy several image columns at once
if (currentBuffer === buffersCached) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To improve readability, can you introduce e.g. buffersToProcess that will be set to buffersCached, reduced after var buffer = colBuffers[currentBuffer]; and be used detect when to flush or populate the buffer? (As alternative currentBuffer can be used but in reverse order)

@yurydelendik
Copy link
Contributor

Looks good with the changes above.

@fkaelberer
Copy link
Contributor Author

All right, I'll do that in the next few days.

@fkaelberer
Copy link
Contributor Author

Ok, there you go. I made currentBuffer run in reversed order, so the conditions to fill and flush the buffers are indeed much easier to read. Also, buffersCached is not needed anymore.

@timvandermeij
Copy link
Contributor

/botio-linux preview

@pdfjsbot
Copy link

From: Bot.io (Linux)


Received

Command cmd_preview from @timvandermeij received. Current queue size: 0

Live output at: http://107.21.233.14:8877/df95c2df5e844f8/output.txt

@timvandermeij
Copy link
Contributor

/botio test

@pdfjsbot
Copy link

From: Bot.io (Linux)


Received

Command cmd_test from @timvandermeij received. Current queue size: 0

Live output at: http://107.21.233.14:8877/40ad25e4b57ae91/output.txt

@pdfjsbot
Copy link

From: Bot.io (Windows)


Received

Command cmd_test from @timvandermeij received. Current queue size: 0

Live output at: http://107.22.172.223:8877/15a3c3c609fe2db/output.txt

@pdfjsbot
Copy link

From: Bot.io (Linux)


Failed

Full output at http://107.21.233.14:8877/40ad25e4b57ae91/output.txt

Total script time: 23.62 mins

  • Font tests: Passed
  • Unit tests: Passed
  • Regression tests: FAILED

Image differences available at: http://107.21.233.14:8877/40ad25e4b57ae91/reftest-analyzer.xhtml#web=eq.log

@pdfjsbot
Copy link

From: Bot.io (Windows)


Success

Full output at http://107.22.172.223:8877/15a3c3c609fe2db/output.txt

Total script time: 35.24 mins

  • Font tests: Passed
  • Unit tests: Passed
  • Regression tests: Passed

yurydelendik added a commit that referenced this pull request Feb 24, 2014
@yurydelendik yurydelendik merged commit 5de3e55 into mozilla:master Feb 24, 2014
@yurydelendik
Copy link
Contributor

Thank you for the patch.

@fkaelberer fkaelberer deleted the FasterJPXdecoding branch February 26, 2014 08:28
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants