Skip to content

[MNT]: font_manager.findSystemFonts takes too long on macOS #29658

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

Open
wasimsandhu opened this issue Feb 22, 2025 · 1 comment
Open

[MNT]: font_manager.findSystemFonts takes too long on macOS #29658

wasimsandhu opened this issue Feb 22, 2025 · 1 comment
Labels
Maintenance status: needs clarification Issues that need more information to resolve.

Comments

@wasimsandhu
Copy link

wasimsandhu commented Feb 22, 2025

Summary

The following code takes 10-12 seconds to run on my machine:

import matplotlib.font_manager as font_manager

fonts = font_manager.findSystemFonts(fontext="ttf")

For reference, I have 360 fonts installed according to Font Book.

Proposed fix

I fixed this issue in arcadia-pycolor #58 by just searching within the font directories myself:

def _find_macos_arcadia_fonts() -> list[str]:
    """
    Search for Arcadia fonts in the standard macOS font directories.
    """
    font_paths = []
    for dirpath in MACOS_FONT_DIRECTORIES:
        if not Path(dirpath).exists():
            continue
        paths = [
            str(font_path)
            for font_path in Path(dirpath).glob("*.ttf")
            if FONT_FILTER.lower() in font_path.name.lower()
        ]
        font_paths.extend(paths)
    return font_paths
@anntzer
Copy link
Contributor

anntzer commented Feb 22, 2025

See e.g. #10201: I think we should continue to run system_profiler (and if anything I'd rather drop the manual directory walking, see #10932).
Normally you are not expected to run findSystemFonts "once per session" as noted in Arcadia-Science/arcadia-pycolor#57, as the result gets cached to fontList.json; you should be able to directly call addfont yourself if you want to register your own fonts?

@anntzer anntzer added the status: needs clarification Issues that need more information to resolve. label Mar 6, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Maintenance status: needs clarification Issues that need more information to resolve.
Projects
None yet
Development

No branches or pull requests

2 participants