Skip to content

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

Closed
@wasimxyz

Description

@wasimxyz

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

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions