jupyter-widgets-contrib / ipycanvas

Interactive Canvas in Jupyter
https://ipycanvas.readthedocs.io/en/latest/
BSD 3-Clause "New" or "Revised" License
688 stars 64 forks source link

canvas.draw_image is slow #261

Open martinRenou opened 2 years ago

martinRenou commented 2 years ago

The slow part in ipycanvas is here when we use an Image widget: https://github.com/martinRenou/ipycanvas/blob/master/src/widget.ts#L786-L789 the slowness comes from this function https://github.com/martinRenou/ipycanvas/blob/658929381918dd89dc7f38a735fa7f9148a85f2b/src/widget.ts#L43-L62 which transforms the Image widget into an actual JavaScript HTMLImageElement object

We could probably do it only once for each image widget (keeping the resulting HTMLImageElement in memory in a {"widget-model-id": HTMLImageElement} object, we can also automatically update this mapping if we see changes in the Image model).

That way animating an image would be more performant.