CanvasView/interpolationProxy are slow, is there anything faster?

I’m looking for a Python way to draw interpolated shapes live.
I have a working script doing that using the CanvasView and interpolationProxy but it’s too slow (especially when drawing more than one instance).

I’m guessing that there must be a more effective way since Glyphs manages to preview all instances live without any lag (same goes for VariableFontPreview).

Is there a way to get these performances? And if not what would be the way to get higher performances when to drawing a path interpolation using python (I don’t know Objective C)?

The way I’m doing it now:

def draw(self, view):    
    #New virtual instance
    thisInstance = GSInstance()
    #Associate to the font
    #Calculate the incrementation between each step
    wght = value1
    wdth = value2

    #Set the position in the design space
    thisInstance.axes = [wght, wdth]
    #Get bezierpath of the interpolated glyph
    instanceFont = thisInstance.interpolatedFontProxy
    instanceGlyph = instanceFont.glyphs[Glyphs.font.selectedLayers[0]]
    instanceLayer = instanceGlyph.layers[instanceFont.fontMasterID()]   
    #Add inteprolated path to array
    layerCopy = instanceLayer.copyDecomposedLayer()

    #Scale to the Canvas Size
    scale, # x scale factor
    0.0, # x skew factor
    0.0, # y skew factor
    scale, # y scale factor
    valueX, # x position
    valueY  # y position

I simplified/cleaned the code to make it more clear. In reality I’m drawing many glyph in the same canvas.
At first I tried using many canvas (with one interpolated path per canvas), but it didn’t make it better.

You need to keep the instance around. The instance and its font proxy can cache a lot and it is very expensive to recreate it for every frame. And have a look at the variable font preview plugin code.

1 Like

Of course!
That makes all the difference, thanks!

The variable font preview plugin doesn’t include any python, only a binary. But it’s fine now with the re-used instances.