Appending and deleting instances is suuuper slow in Glyphs 3

Hi! I have a script that deals with adding and deleting many instances. In Glyphs 2, it barely takes any time, but in Glyphs 3 it takes whole seconds:

import time
start = time.time()
for i in range(50):
	Font.instances.append( GSInstance() )
print("Appending: %s seconds" % (time.time() - start))
start = time.time()
for i in range(50):
	del( Font.instances[i] )
print("Deleting: %s seconds" % (time.time() - start))

Glyphs 2:

Appending: 0.00289988517761 seconds
Deleting: 0.00205993652344 seconds

Glyphs 3:

Appending: 1.7754948139190674 seconds
Deleting: 3.722165822982788 seconds

Is there a way to fix that?

1 Like

Try to put your code between these two lines

Font.disableUpdateInterface()
# your code here
Font.enableUpdateInterface()

Thank you! That helps with appending, but not as much with deleting:

Appending: 0.0012331008911132812 seconds
Deleting: 1.6996557712554932 seconds

Font.removeInstance_ does the job in this case:

Deleting: 0.0017430782318115234 seconds

1 Like

Can you show the code where you use Font.removeInstance_?

I’m thinking of using it instead of del( font.instances[i] ) because it seems faster. Are there any problems with it?

Is it really faster? I suspect there is something else going on as the python method is using the same API under the hood.

Interesting! Here’s what I get from this simple script on an empty new font:

import time
start = time.time()
Font.disableUpdateInterface()
for i in range(100):
	Font.instances.append( GSInstance() )
print("Appending: %s seconds" % (time.time() - start))
Font.enableUpdateInterface()

Font.disableUpdateInterface()
start = time.time()
for i in range(50):
	Font.removeInstance_(Font.instances[49-i])
print("Font.removeInstance_: %s seconds" % (time.time() - start))
Font.enableUpdateInterface()

Font.disableUpdateInterface()
start = time.time()
for i in range(50):
	del( font.instances[49-i] )
print("del(font.instances): %s seconds" % (time.time() - start))
Font.enableUpdateInterface()

Glyphs 3:

Appending: 0.0035860538482666016 seconds
Font.removeInstance_: 0.0017080307006835938 seconds
del(font.instances): 1.7925388813018799 seconds

Glyphs 2:

Appending: 0.00457906723022 seconds
Font.removeInstance_: 0.00204801559448 seconds
del(font.instances): 0.00971293449402 seconds

Interesting. Thanks for the data. I’ll have a look.

The difference between Glyphs 2 and 3 is that the font info window is dynamically build and that has some bottlenecks. We are working on improving on it.

1 Like