If I remember correctly, there's a external call to fc-list that is very slow. At one time, I intended to improve this situation by removing the fc-list dependency on Mac and Linux and instead collecting only the needed font data by using freetype and/or Mike C. Fletcher's TTFQuery, but I got too busy.
Jason On Sun, Apr 4, 2021, 4:36 PM Irv Kalb <i...@furrypants.com> wrote: > [I apologize if this is a duplicate, but I haven't seen this message show > up on the list.] > > > I have tracked down a huge slowdown on loading fonts with > pygame.font.SysFont > > Mac OSX 11.2.3 > Python 3.9.1 > Pygame 2.0.1 > > If I load a font like the system font using None with a call to > pygame.font.font, it happens almost immediately. > > But if I load a font by name using pygame.font.SysFont, it's taking over 7 > seconds on my Mac to load. It doesn't seem to matter which font I try to > use. > > Sample program: > > import sys > import pygame > import time > > pygame.init() > screen = pygame.display.set_mode((400, 400)) > clock = pygame.time.Clock() > > now = time.time() > font1 = pygame.font.Font(None, 24) > print('Loading System font took', time.time() - now) > > now = time.time() > font2 = pygame.font.SysFont('Arial', 24) > print('Loading Arial font took', time.time() - now) > > while True: > for event in pygame.event.get(): > if event.type == pygame.QUIT: > pygame.quit() > sys.exit() > > screen.fill((255, 255, 255)) > > pygame.display.flip() > clock.tick(30) > > > Output: > pygame 2.0.1 (SDL 2.0.14, Python 3.9.1) > Hello from the pygame community. https://www.pygame.org/contribute.html > Loading System font took 0.0006210803985595703 > Loading Arial font took 7.058471202850342 > > > (I don't have a setup to test this on Windows.) > > This seems like a rather excessive amount of time as it slows down that > start up of many of my programs. > > It seems to be related to how long it takes to get the list of fonts. If > I add this before the call to SysFont: > > now = time.time() > fontList = pygame.font.get_fonts() > print('Getting fonts took', time.time() - now) > > I get: > > Loading System font took 0.0006549358367919922 > Getting fonts took 7.013390064239502 > Loading Arial font took 0.0004830360412597656 > > > Anyone else seeing this? > > Can someone tell me how to send in a bug report for this? > > Thanks, > > Irv > > > > >