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

Avoid creating intermediate strings in sanitizeMetrics #5219

Merged
merged 1 commit into from
Aug 21, 2014
Merged

Avoid creating intermediate strings in sanitizeMetrics #5219

merged 1 commit into from
Aug 21, 2014

Conversation

Snuffleupagus
Copy link
Collaborator

This patch avoids creating many intermediate strings, by instead writing directly to a Uint8Array, when writing dummy width/lsb entries for glyphs where those are missing.
For the relevant PDF files in our test suite (see https://gist.github.com/Snuffleupagus/27f6586ceac79dadacbe), the average number of intermediate strings are well over 1000.

@@ -3300,14 +3300,15 @@ var Font = (function FontClosure() {
var i, ii;
if (numMissing > 0) {
font.pos = (font.start ? font.start : 0) + metrics.offset;
var entries = '';
var entriesBuf = new Array(metrics.length + numGlyphs);
Copy link
Contributor

Choose a reason for hiding this comment

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

is it + numMissing ?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I thought I changed that already, but I apparently didn't "force" push. Thanks for catching that!

@yurydelendik
Copy link
Contributor

Will it be better to use Uint8Array and construct pure binary data instead?

@Snuffleupagus
Copy link
Collaborator Author

Will it be better to use Uint8Array and construct pure binary data instead?

That sounds like a great idea, thank you! I'll update the patch later today.

@Snuffleupagus
Copy link
Collaborator Author

The patch has been updated to use a Uint8Array instead.

@CodingFabian
Copy link
Contributor

thats elegant!

}
for (i = 0; i < numMissing; i++) {
entries += '\x00\x00';
entries[i] = font.getByte();
Copy link
Contributor

Choose a reason for hiding this comment

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

I wonder if entries.set(font.getBytes(metrics.length)) will do the trick too.

Another question I'm asking is, can we use old metrics.data instead of reading the stuff again from the file?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I wonder if entries.set(font.getBytes(metrics.length)) will do the trick too.

Why didn't I think of that; that obviously works equally well! Thanks for pointing it out :-)

Another question I'm asking is, can we use old metrics.data instead of reading the stuff again from the file?

I see no reason why we need to re-read from the font file. Just to make sure, I've compared the two approaches and they yield identical results for all the test files we have (see link above).

This patch avoids creating many intermediate strings, when adding dummy width/lsb entries for glyphs where those are missing.
For the relevant PDF files in our test suite, the average number of intermediate strings are well over 1000.
@yurydelendik
Copy link
Contributor

/botio test

@pdfjsbot
Copy link

From: Bot.io (Windows)


Received

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

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

@pdfjsbot
Copy link

From: Bot.io (Linux)


Received

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

Live output at: http://107.21.233.14:8877/61991029852620a/output.txt

@pdfjsbot
Copy link

From: Bot.io (Windows)


Success

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

Total script time: 21.85 mins

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

@pdfjsbot
Copy link

From: Bot.io (Linux)


Success

Full output at http://107.21.233.14:8877/61991029852620a/output.txt

Total script time: 22.61 mins

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

yurydelendik added a commit that referenced this pull request Aug 21, 2014
…ermediate-strings

Avoid creating intermediate strings in sanitizeMetrics
@yurydelendik yurydelendik merged commit 4834f1c into mozilla:master Aug 21, 2014
@yurydelendik
Copy link
Contributor

Thank you for the patch

@Snuffleupagus Snuffleupagus deleted the sanitizeMetrics-avoid-intermediate-strings branch August 21, 2014 13:37
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants