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

Optimization on load #3464

Merged
merged 1 commit into from Mar 19, 2024
Merged

Optimization on load #3464

merged 1 commit into from Mar 19, 2024

Conversation

simoncozens
Copy link
Collaborator

Some OT tables rely on "aux" fields which are conditions written as strings; a classic example is the Device field which has the condition "DeltaFormat in (1,2,3)". This is currently stored as a string in the Convertor object, and is evaled for each Device table it decompiles.

eval is very slow. You can get a small speedup - quite a large speedup for fonts with lots of Device/VariationIndex tables - by compiling the string and evaling the compiled version later.

@simoncozens simoncozens changed the title Micro-optimization on load Optimization on load Mar 19, 2024
@behdad behdad merged commit 430e364 into main Mar 19, 2024
11 checks passed
@behdad behdad deleted the eval-aux branch March 19, 2024 22:46
@simoncozens
Copy link
Collaborator Author

Thank you! Here's a font with a particularly large GPOS table:

font = TTFont("Bigfont.ttf")
count = len(font["GPOS"].table.LookupList.Lookup)
print(f"I have {count} GPOS lookups")

Before:

$ time python3 open.py
I have 46 GPOS lookups
python3 open.py  3.07s user 0.06s system 98% cpu 3.161 total

After:

$ time PYTHONPATH=Lib python3 open.py
I have 46 GPOS lookups
PYTHONPATH=Lib python3 open.py  2.29s user 0.05s system 99% cpu 2.355 total

@anthrotype
Copy link
Member

thanks. A test would also have been nice, to confirm this trick works reliably on all the pythons we support.

@simoncozens
Copy link
Collaborator Author

That's what the existing test suite is for...

@anthrotype
Copy link
Member

thanks for confirming that the changes are covered by our current test suite

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.

None yet

3 participants