canvas

FabricJS performance hack

The frame rate can be improved by only rendering inside a rAF callback. let isRendering = false; let isAnimating = false; const render = canvas.renderAll.bind(canvas); const stop = () => isAnimating = false; const play = () => { isAnimating = true; canvas.renderAll(); }; canvas.renderAll = () => { if (!isRendering) { isRendering = true; requestAnimationFrame(() => { render(); isRendering = false; if (isAnimating) { canvas.renderAll(); } }); } }; I started working with FabricJS this week so there’s a big chance things might break.
Read more