Create explicit schema/type for otData.py#4076
Conversation
|
This looks good to me. @justvanrossum ? |
|
No objection, but I would like to know if there’s any measurable performance impact. |
|
Ack, I'll run some performance tests. I can even try out named tuple.
Is there a preference between NamedTuple and DataClass? I kind of like DataClass syntax better but not a strong preference either way |
I think the performance might guide us there. |
|
I switched over to use the class based BenchmarksPython Interpreter LoadingThis is just testing how long it takes to start and stop Python. Around hyperfine --warmup 3 --runs 1000 'python -c "pass"'
Creating classesThis measures how long it takes to run the hyperfine --warmup 3 --runs 1000 'python -c "from fontTools.ttLib.tables.otTables import *"'
|
|
Random thought: What effort would be required to not dynamically generate all these classes on load but instead code-generate them from a schema, kinda like fontations does? It would enable better type checker integration (which doesn't deal with dynamically generated code) and would make loading the file a trivial module load, which Python can cache in a |
The main annoyance would be that, in current design, otTables.py can define a class, and the otBase.py can augment the class based on the fields in otData. If we generate code, it's not clear how to augment generated code with handwritten methods. |
Moves OpenType table definitions from raw tuples to a structured dataclass.
FieldSpec(type, name, repeat, aux, description).otData.pyto use the new dataclass for all schema definitions.otConverters.pyandotTables.pyto consume the dataclass objects.