-
Notifications
You must be signed in to change notification settings - Fork 10.2k
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
Avoid creating intermediate strings in sanitizeMetrics #5219
Conversation
@@ -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); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
is it + numMissing
?
There was a problem hiding this comment.
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!
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. |
The patch has been updated to use a |
thats elegant! |
} | ||
for (i = 0; i < numMissing; i++) { | ||
entries += '\x00\x00'; | ||
entries[i] = font.getByte(); |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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.
/botio test |
From: Bot.io (Windows)ReceivedCommand cmd_test from @yurydelendik received. Current queue size: 0 Live output at: http://107.22.172.223:8877/ba07bf8eab48963/output.txt |
From: Bot.io (Linux)ReceivedCommand cmd_test from @yurydelendik received. Current queue size: 0 Live output at: http://107.21.233.14:8877/61991029852620a/output.txt |
From: Bot.io (Windows)SuccessFull output at http://107.22.172.223:8877/ba07bf8eab48963/output.txt Total script time: 21.85 mins
|
From: Bot.io (Linux)SuccessFull output at http://107.21.233.14:8877/61991029852620a/output.txt Total script time: 22.61 mins
|
…ermediate-strings Avoid creating intermediate strings in sanitizeMetrics
Thank you for the patch |
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.