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

Estimate the size of decoded streams in advance. #4444

Merged
merged 1 commit into from
Mar 13, 2014

Conversation

nnethercote
Copy link
Contributor

When decoding a stream, the decode buffer is often grown multiple times, its
byte size increasing like so: 512, 1024, 2048, etc. This patch estimates the
minimum size in advance (using the length of the encoded stream), often
allowing the smaller sizes to be skipped. It also renames numerous |length|
variables as |maybeLength| to make it clear that they can be |null|.

I measured this change on eight documents. This change reduces the cumulative
size of decode buffer allocations by 0--32%, with 10--20% being typical. This
reduces peak RSS by 10 or 20 MiB for several of them.

BTW, I think Ascii85 and AsciiHex streams are the only ones for which the decoded data is regularly smaller than the encoded data, and I've accounted for that. Please let me know if any of the other stream kinds have the same behaviour.

@@ -800,6 +808,7 @@ var JpegStream = (function JpegStreamClosure() {
var jpegImage = new JpegImage();
if (this.colorTransform != -1)
jpegImage.colorTransform = this.colorTransform;
dump('x1\n');
Copy link
Collaborator

Choose a reason for hiding this comment

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

It looks like this is a leftover from debugging.

When decoding a stream, the decode buffer is often grown multiple times, its
byte size increasing like so: 512, 1024, 2048, etc. This patch estimates the
minimum size in advance (using the length of the encoded stream), often
allowing the smaller sizes to be skipped. It also renames numerous |length|
variables as |maybeLength| to make it clear that they can be |null|.

I measured this change on eight documents. This change reduces the cumulative
size of decode buffer allocations by 0--32%, with 10--20% being typical. This
reduces peak RSS by 10 or 20 MiB for several of them.
@nnethercote
Copy link
Contributor Author

I removed the stray dump() call.

@Snuffleupagus
Copy link
Collaborator

/botio test

@pdfjsbot
Copy link

From: Bot.io (Linux)


Received

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

Live output at: http://107.21.233.14:8877/5bd5b07dfad125b/output.txt

@pdfjsbot
Copy link

From: Bot.io (Windows)


Received

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

Live output at: http://107.22.172.223:8877/47f982c4bbc8866/output.txt

@pdfjsbot
Copy link

From: Bot.io (Linux)


Success

Full output at http://107.21.233.14:8877/5bd5b07dfad125b/output.txt

Total script time: 26.26 mins

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

@pdfjsbot
Copy link

From: Bot.io (Windows)


Failed

Full output at http://107.22.172.223:8877/47f982c4bbc8866/output.txt

Total script time: 36.95 mins

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

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

yurydelendik added a commit that referenced this pull request Mar 13, 2014
Estimate the size of decoded streams in advance.
@yurydelendik yurydelendik merged commit 1c0e1cc into mozilla:master Mar 13, 2014
@yurydelendik
Copy link
Contributor

Looks good. Thanks

@nnethercote nnethercote deleted the min-length branch March 14, 2014 04:49
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.

4 participants