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

Optimize JPG.js receiveAndExtend for 1 bit case. #4894

Merged
merged 1 commit into from Jun 5, 2014
Merged

Optimize JPG.js receiveAndExtend for 1 bit case. #4894

merged 1 commit into from Jun 5, 2014

Conversation

CodingFabian
Copy link
Contributor

Profiling showed that receiveAndExtend is frequently called with the length of
one bit. This happens for example in decodeBaseline.
For a single bit, the loop and shift in receive, as well as the shifts in
receiveAndExtend are overhead.
This shortcut manually calculates the shifts by either returning 1 or -1 from
receiveAndExtend by reading the bit and deciding on the return value.
While it comes with an overhead for each non-one length, the speedup is at about
10% in the hot parse/decode path.

Profiling showed that receiveAndExtend is frequently called with the length of
one bit. This happens for example in decodeBaseline.
For a single bit, the loop and shift in receive, as well as the shifts in
receiveAndExtend are overhead.
This shortcut manually calculates the shifts by either returning 1 or -1 from
receiveAndExtend by reading the bit and deciding on the return value.
While it comes with an overhead for each non-one length, the speedup is at about
10% in the hot parse/decode path.
@CodingFabian
Copy link
Contributor Author

another improvement in the hot path of our documents. For me it gets about 10%.
I would appreciate if others, maybe @p01 could verify with their benchmarks.

Disclaimer: I do not know the algorithms involved. I just found it interesting that receiveAndExtends returns -1 when the bit is 0. Initially I thought it should be 0.

@Snuffleupagus
Copy link
Collaborator

/botio test

@pdfjsbot
Copy link

pdfjsbot commented Jun 5, 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/84c7968428e4527/output.txt

@pdfjsbot
Copy link

pdfjsbot commented Jun 5, 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/d52226fdd54092b/output.txt

@pdfjsbot
Copy link

pdfjsbot commented Jun 5, 2014

From: Bot.io (Windows)


Failed

Full output at http://107.22.172.223:8877/d52226fdd54092b/output.txt

Total script time: 21.82 mins

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

Image differences available at: http://107.22.172.223:8877/d52226fdd54092b/reftest-analyzer.html#web=eq.log

@pdfjsbot
Copy link

pdfjsbot commented Jun 5, 2014

From: Bot.io (Linux)


Success

Full output at http://107.21.233.14:8877/84c7968428e4527/output.txt

Total script time: 26.19 mins

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

@p01
Copy link
Contributor

p01 commented Jun 5, 2014

This commit speeds up receiveAndExtend from 40.4 to 35.4ms on my system on a PDF with 4 CMYK JPGs.

@yurydelendik
Copy link
Contributor

/botio-windows test

@pdfjsbot
Copy link

pdfjsbot commented Jun 5, 2014

From: Bot.io (Windows)


Received

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

Live output at: http://107.22.172.223:8877/76b8f15a540ec51/output.txt

@pdfjsbot
Copy link

pdfjsbot commented Jun 5, 2014

From: Bot.io (Windows)


Success

Full output at http://107.22.172.223:8877/76b8f15a540ec51/output.txt

Total script time: 23.48 mins

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

@yurydelendik
Copy link
Contributor

Thank you for the patch

yurydelendik added a commit that referenced this pull request Jun 5, 2014
…xtend

Optimize JPG.js receiveAndExtend for 1 bit case.
@yurydelendik yurydelendik merged commit 9308b52 into mozilla:master Jun 5, 2014
@CodingFabian CodingFabian deleted the optimize-jpgjs-receiveAndExtend branch June 5, 2014 18:35
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.

None yet

5 participants