Performance - draw vs redraw

when would it be good to use draw() and when would it be good to use redraw()

and could a program ran via a main draw() loop be made faster by only using a redraw-when-needed approach?

if so, is redraw, in a while(true) { redraw(); } faster than just letting the draw loop run?

1 Like

is redraw, in a while(true) { redraw(); } faster than just letting the draw loop run?

In one sense, since while(true) { redraw(); } run at an unbounded rate, whereas draw() runs at a rate targeting frameRate. On the other hand, will it run the contents of draw() any faster? I don’t think so.

Generally, go for the noLoop() + redraw() approach if you’re generating a still image.

If you need to redraw sometimes, drawing into a separate PGraphics cache is probably the best approach – draw it with image() every frame but only update (draw into) it when you need to.

i intend to draw every frame but only if i actually need to draw, for example, a 2 FPS (eg 500 MS draw delay) spinning cube vs a 60FPS spinning cube

Ok, something like this then:

if (frameCount % 30 == 0) {

i meant like…

if one graphics object is updating at 60FPS and another at 2 FPS then would draw() always be called every frame due to the 60 FPS updating graphics object?

No, it isn’t faster, because it doesn’t run at all. redraw() doesn’t do what you think it does. It doesn’t call draw() – it sets a flag so that handleDraw will later fire draw once – even if noLoop is set – and clear the flag.

So, if you endlessly call redraw(), all you are doing is setting the same flag over and over, freezing the sketch. Try it.

void draw() {
  text(frameRate, width/2,height/2);

void mouseReleased() {
  while(true) { redraw(); }
1 Like