8000 subset: speed up subsetting of large fonts by aschmitz · Pull Request #2467 · fonttools/fonttools · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

subset: speed up subsetting of large fonts #2467

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

Merged
merged 1 commit into from
Dec 15, 2021

Conversation

aschmitz
Copy link
Contributor

Two small changes that significantly speed up subsetting of large fonts such as Noto Sans CJK:

  1. When emptying a charstring, simply empty its program rather than attempting to decompile it first. (Only relevant when retaining GIDs.)

  2. When reindexing charstrings, swap out an accidentally-quadratic implementation for one that is linear in the number of retained glyphs.

This passes tests locally, works in my test documents, and is much faster while producing the same output (in this admittedly contrived example):

Before:

$ time pyftsubset NotoSansCJK-Regular.ttc --unicodes=U+FF21 --output-file=out.ttf --retain-gids --font-number 0 --ignore-missing-glyphs ; sha1sum out.ttf

real	0m33.038s
user	0m32.896s
sys	0m0.120s
704162b0cb62934160dd0c6e39368891762094a1  out.ttf

After:

$ time pyftsubset NotoSansCJK-Regular.ttc --unicodes=U+FF21 --output-file=out.ttf --retain-gids --font-number 0 --ignore-missing-glyphs ; sha1sum out.ttf

real	0m2.131s
user	0m2.043s
sys	0m0.081s
704162b0cb62934160dd0c6e39368891762094a1  out.ttf

(This is a small change and I don't feel I need to be included in the acknowledgements. If you need me to, let me know and I can add myself.)

Two small changes that significantly speed up subsetting of large fonts
such as Noto Sans CJK:

1. When emptying a charstring, simply empty its program rather than
attempting to decompile it first. (Only relevant when retaining GIDs.)

2. When reindexing charstrings, swap an accidentally-quadratic
implementation for one that is linear in the number of retained glyphs.
@anthrotype
Copy link
Member

Thanks for the PR! It's nice to see what profiler guided optimizations can achieve 👍

Only one thing, I am not 100% sure about the line where you remove c.decompile(), but I can't remember why my previous self did that in #1447. I don't see immediately what other side effect that would have. /cc @behdad wdyt?

if you need me to, let me know and I can add myself

By all means, you're very welcome to add yourself.

@anthrotype anthrotype requested a review from behdad December 15, 2021 16:23
@behdad
Copy link
Member
behdad commented Dec 15, 2021

Lgtm. Nice!

@anthrotype anthrotype merged commit fe2ba42 into fonttools:main Dec 15, 2021
anthrotype added a commit that referenced this pull request Dec 15, 2021
I didn't know their full name so I used their github handle, feel free to amend
#2467
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.

3 participants
0