CanvasRenderingContext2D.drawImage() very slow in Chrome on large canvas CanvasRenderingContext2D.drawImage() very slow in Chrome on large canvas google-chrome google-chrome

CanvasRenderingContext2D.drawImage() very slow in Chrome on large canvas


Your main problem seems to be the number of different Image-objects you use to draw to the canvas. You absolutely should use a Textureatlas, putting as many graphics as possible in a single image.

You should then render your sprites from as few main-images as possible by specifying the relevant rectangle:

void ctx.drawImage(image, sx, sy, sWidth, sHeight, dx, dy, dWidth, dHeight);

instead of the whole image:

void ctx.drawImage(image, dx, dy);

see CanvasRenderingContext2D.drawImage() for details. This way, you avoid too many context switches. As Blindman67 mentioned, you should be careful to switch between texture atlases as few times as possible - for example, you may want to use a single texture atlas for all your rendering to canvas1, another one for all your images for canvas2 etc.