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

Make type 1 font program decryption faster. #6933

Merged
merged 1 commit into from
Feb 9, 2016

Conversation

brendandahl
Copy link
Contributor

Discard the values first so we don't have to slice the array.

I noticed this showed up pretty high in a profile so I checked it out. In chrome I see 31ms improvement and in firefox a 13ms improvement in the decrypt time while loading the first two pages of trace monkey.

@brendandahl
Copy link
Contributor Author

decryptAscii() also probably needs a similar treatment

@brendandahl
Copy link
Contributor Author

Changed it to gracefully handle a bad discard number instead of asserting.

@brendandahl
Copy link
Contributor Author

Last failure was from some debug code to find a decryptASCII use. Interesting that we only have one PDF that uses that.

if (discardNumber > data.length) {
return new Uint8Array(0);
}
var r = key | 0, c1 = 52845, c2 = 22719, i = 0, j = 0;
Copy link
Contributor

Choose a reason for hiding this comment

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

You already initialize i and j to 0 in the loops, so we can remove the initialization here to avoid doing it twice.

Discard the values first so we don't have to slice the array.
}
var r = key | 0, c1 = 52845, c2 = 22719, i, j;
for (i = 0; i < discardNumber; i++) {
r = ((data[i] + r) * c1 + c2) & ((1 << 16) - 1);
Copy link
Collaborator

Choose a reason for hiding this comment

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

Given that ((1 << 16) - 1) is constant in all the loop iterations, would it make sense to cache this value in a variable instead?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Talked with one of the spider monkey people, the value will be constant folded by the parser, so it doesn't matter.

@timvandermeij
Copy link
Contributor

@brendandahl Could you address the comment above? Also, do you want to do this for decryptAscii too or do you want to leave that out? If that is resolved, we should land this.

@brendandahl
Copy link
Contributor Author

Also, do you want to do this for decryptAscii too or do you want to leave that out? If that is resolved, we should land this.

This one is more tricky and we only have one example, so I don't think it's worth it unless we see it show up on performance profile.

@timvandermeij
Copy link
Contributor

/botio-linux preview

@pdfjsbot
Copy link

pdfjsbot commented Feb 9, 2016

From: Bot.io (Linux)


Received

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

Live output at: http://107.21.233.14:8877/951a9d35779dbae/output.txt

@timvandermeij
Copy link
Contributor

/botio test

@pdfjsbot
Copy link

pdfjsbot commented Feb 9, 2016

From: Bot.io (Windows)


Received

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

Live output at: http://107.22.172.223:8877/bcfa87fea2f784e/output.txt

@pdfjsbot
Copy link

pdfjsbot commented Feb 9, 2016

From: Bot.io (Linux)


Received

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

Live output at: http://107.21.233.14:8877/3455e24635d82ec/output.txt

@pdfjsbot
Copy link

pdfjsbot commented Feb 9, 2016

From: Bot.io (Windows)


Success

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

Total script time: 19.94 mins

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

@pdfjsbot
Copy link

pdfjsbot commented Feb 9, 2016

From: Bot.io (Linux)


Success

Full output at http://107.21.233.14:8877/3455e24635d82ec/output.txt

Total script time: 21.25 mins

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

timvandermeij added a commit that referenced this pull request Feb 9, 2016
Make type 1 font program decryption faster.
@timvandermeij timvandermeij merged commit 02b161d into mozilla:master Feb 9, 2016
@timvandermeij
Copy link
Contributor

Nice work, thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants