Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Refactor some parts of ft2font extension #27891

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 5 commits into from
Aug 23, 2024

Conversation

QuLogic
Copy link
Member

@QuLogic QuLogic commented Mar 9, 2024

PR summary

Mainly, this is moving Python-specific code from ftfont.{cpp,h} to ft2font_wrapper.cpp; this keeps the Python code encapsulated in the one file. Also remove the deprecations that can be expired now.

This is based on #27885, and is a first step in moving to pybind11.

PR checklist

@ksunden
Copy link
Member

ksunden commented Mar 9, 2024

My reading of the mypy error is that it simply wants the stub to match the final status of the implementation by adding @final to decorate the class in the pyi. That makes sense to me, though didn't actually try it to check

@ksunden
Copy link
Member

ksunden commented Mar 13, 2024

build failures on windows do appear to be related here.

@QuLogic
Copy link
Member Author

QuLogic commented Mar 13, 2024

Ah, interesting that designated initializers are so new in C++ vs C.

@ksunden
Copy link
Member

ksunden commented Aug 14, 2024

Remains true that the errors on Windows appear to be related.

@QuLogic
Copy link
Member Author

QuLogic commented Aug 15, 2024

I also put in the deprecated function removals here.

@tacaswell
Copy link
Member

Changing the classes to final needs an API change note as they are technically public.

Do we have any sense of the preformance trade off of doing a single pass but maybe multiple memory allocations vs doing two passes but only one memory allocation?

@QuLogic
Copy link
Member Author

QuLogic commented Aug 15, 2024

Do we have any sense of the preformance trade off of doing a single pass but maybe multiple memory allocations vs doing two passes but only one memory allocation?

Running tests with pytest -n4 on my machine, mostly idle, averaging 3 of 5 (dropping best/worst times) gives 236.4 ± 0.3s for the commit before, and 234.4 ± 0.5s after. Now this isn't a true microbenchmark, but at least times aren't horribly worse.

@QuLogic
Copy link
Member Author

QuLogic commented Aug 15, 2024

A possibly reasonable microbenchmark:

import string
import timeit

from matplotlib.text import TextToPath
from matplotlib.font_manager import FontProperties, findfont, get_font

ttp = TextToPath()
fp = FontProperties()
font = get_font(findfont(fp))

timer = timeit.Timer("ttp.get_glyphs_with_font(font, string.ascii_uppercase)",
                     globals={'ttp': ttp, 'font': font, 'string': string})

timer.autorange(print)

This ends at 500 iterations, with average before of 0.236 ± 0.014s, and average after of 0.231 ± 0.004s.

@QuLogic
Copy link
Member Author

QuLogic commented Aug 23, 2024

Snuck in one more thing; noticed that the C++ side's FT2Image.m_dirty is unused, so removed it.

There appears to be no reason for them to be subtyped, as they are
semi-private, and we don't do that.
This improves the encapsulation and separation of concerns between the
files.
This means we only need to do one pass through.
It is set in a few places, but never read.
@QuLogic
Copy link
Member Author

QuLogic commented Aug 23, 2024

And ft2font.Glyph was removed from the API change note because the class part is not public; it isn't exposed in the module and can only be used when returned by some other method.

@oscargus oscargus merged commit 3eda5a3 into matplotlib:main Aug 23, 2024
44 checks passed
@QuLogic QuLogic deleted the ft2font-cleanup branch August 23, 2024 06:12
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants