HTML canvas is widely used in games and complex image visualization. However, as websites and applications push canvas rendering to the limit, performance becomes a problem.
Here are some suggestions to improve performance:
Pre render similar shapes or duplicate objects on off screen canvas
When we find that there are many complex drawing operations in every frame, please consider creating an off screen canvas, drawing the image on this canvas once (or every time the image changes), and then drawing the canvas beyond the line of sight on each frame.
myEntity.offscreenCanvas = document.createElement("canvas");
myEntity.offscreenCanvas.width = myEntity.width;
myEntity.offscreenCanvas.height = myEntity.height;
myEntity.offscreenContext = myEntity.offscreenCanvas.getContext("2d");
myEntity.render(myEntity.offscreenContext);
Read More