Re: [pygame] Time to load font with pygame.font.SysFont on Mac

2021-04-04 Thread René Dudfield
The Mac font lists are in this closed issue:
https://github.com/pygame/pygame/issues/179


On Sunday, April 4, 2021, René Dudfield  wrote:

> Hi,
>
> There probably should be an open issue for this. The initial query is
> quite slow unfortunately, and I can’t find a quicker query. What can be
> done is to use a known set of fonts for different or some subset of OS
> versions... Apple did/does publish these lists somewhere, so a fix would be
> to first look at these lists and then only query if the font can not be
> found.
>
> For many/most fonts that people use with SysFont (like Arial) this would
> hit the fast path and avoid this slow query.
>
> cheers,
>
> On Sunday, April 4, 2021, Greg Ewing  wrote:
>
>> On 5/04/21 9:29 am, Irv Kalb wrote:
>>
>>> 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.
>>>
>>
>> Is it slow every time you run it, or are subsequent runs faster?
>>
>> I don't have an OSX 11 system handy to try it on, but I tried
>> it on 10.12.6 and got this:
>>
>> First run:
>> Loading System font took 0.015527009963989258
>> Loading Arial font took 4.879987001419067
>>
>> Second run:
>> Loading System font took 0.00061798095703125
>> Loading Arial font took 0.05048775672912598
>>
>> Third run:
>> Loading System font took 0.0006070137023925781
>> Loading Arial font took 0.0516507625579834
>>
>> So for me it took about 4.9 seconds the first time, but was
>> a lot faster once it was warmed up.
>>
>> --
>> Greg
>>
>>


Re: [pygame] Time to load font with pygame.font.SysFont on Mac

2021-04-04 Thread René Dudfield
Hi,

There probably should be an open issue for this. The initial query is quite
slow unfortunately, and I can’t find a quicker query. What can be done is
to use a known set of fonts for different or some subset of OS versions...
Apple did/does publish these lists somewhere, so a fix would be to first
look at these lists and then only query if the font can not be found.

For many/most fonts that people use with SysFont (like Arial) this would
hit the fast path and avoid this slow query.

cheers,

On Sunday, April 4, 2021, Greg Ewing  wrote:

> On 5/04/21 9:29 am, Irv Kalb wrote:
>
>> 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.
>>
>
> Is it slow every time you run it, or are subsequent runs faster?
>
> I don't have an OSX 11 system handy to try it on, but I tried
> it on 10.12.6 and got this:
>
> First run:
> Loading System font took 0.015527009963989258
> Loading Arial font took 4.879987001419067
>
> Second run:
> Loading System font took 0.00061798095703125
> Loading Arial font took 0.05048775672912598
>
> Third run:
> Loading System font took 0.0006070137023925781
> Loading Arial font took 0.0516507625579834
>
> So for me it took about 4.9 seconds the first time, but was
> a lot faster once it was warmed up.
>
> --
> Greg
>
>


Re: [pygame] Time to load font with pygame.font.SysFont on Mac

2021-04-04 Thread Jason Marshall
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  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
>
>
>
>
>


Re: [pygame] Time to load font with pygame.font.SysFont on Mac

2021-04-04 Thread Greg Ewing

On 5/04/21 9:29 am, Irv Kalb wrote:

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.


Is it slow every time you run it, or are subsequent runs faster?

I don't have an OSX 11 system handy to try it on, but I tried
it on 10.12.6 and got this:

First run:
Loading System font took 0.015527009963989258
Loading Arial font took 4.879987001419067

Second run:
Loading System font took 0.00061798095703125
Loading Arial font took 0.05048775672912598

Third run:
Loading System font took 0.0006070137023925781
Loading Arial font took 0.0516507625579834

So for me it took about 4.9 seconds the first time, but was
a lot faster once it was warmed up.

--
Greg



[pygame] Time to load font with pygame.font.SysFont on Mac

2021-04-04 Thread Irv Kalb
[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