diff --git a/lib/matplotlib/font_manager.py b/lib/matplotlib/font_manager.py index 73da3c418dd7..aba5b61e2b28 100644 --- a/lib/matplotlib/font_manager.py +++ b/lib/matplotlib/font_manager.py @@ -29,7 +29,6 @@ from base64 import b64encode from collections import namedtuple -import copy import dataclasses from functools import lru_cache from io import BytesIO @@ -902,7 +901,12 @@ def set_math_fontfamily(self, fontfamily): def copy(self): """Return a copy of self.""" - return copy.copy(self) + # Optimize: direct instance creation instead of using copy.copy(self) + # This avoids unnecessary lookup and internal machinery of copy module for simple objects. + cls = self.__class__ + result = cls.__new__(cls) + result.__dict__ = self.__dict__.copy() + return result # Aliases set_name = set_family