Avoid repainting the entire canvas element when possible.