# Performance - draw vs redraw

**URL:** <https://discourse.processing.org/t/performance-draw-vs-redraw/21763>\
**Category:** Coding Questions\
**Created:** [June 11, 2020, 7:10am UTC](https://discourse.processing.org/t/performance-draw-vs-redraw/21763 "2020-06-11T07:10:45Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![mgood7123](https://avatars.discourse-cdn.com/v4/letter/m/54ee81/32.png) [@mgood7123](https://discourse.processing.org/u/mgood7123)\
**Post date:** [June 11, 2020, 7:10am UTC](https://discourse.processing.org/t/performance-draw-vs-redraw/21763/1 "2020-06-11T07:10:45Z")

</div>

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?

---

<div class="post-metadata">

**Author:** ![micycle](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/micycle/32/201_2.png) [@micycle](https://discourse.processing.org/u/micycle)\
**Post date:** [June 11, 2020, 11:07am UTC](https://discourse.processing.org/t/performance-draw-vs-redraw/21763/2 "2020-06-11T11:07:20Z")

</div>

> 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.

---

<div class="post-metadata">

**Author:** ![mgood7123](https://avatars.discourse-cdn.com/v4/letter/m/54ee81/32.png) [@mgood7123](https://discourse.processing.org/u/mgood7123)\
**Post date:** [June 11, 2020, 11:10am UTC](https://discourse.processing.org/t/performance-draw-vs-redraw/21763/3 "2020-06-11T11:10:52Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![micycle](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/micycle/32/201_2.png) [@micycle](https://discourse.processing.org/u/micycle)\
**Post date:** [June 11, 2020, 11:19am UTC](https://discourse.processing.org/t/performance-draw-vs-redraw/21763/4 "2020-06-11T11:19:46Z")

</div>

Ok, something like this then:

```auto
if (frameCount % 30 == 0) {
    updatePGraphics();
}
drawPGraphics();

```

---

<div class="post-metadata">

**Author:** ![mgood7123](https://avatars.discourse-cdn.com/v4/letter/m/54ee81/32.png) [@mgood7123](https://discourse.processing.org/u/mgood7123)\
**Post date:** [June 11, 2020, 11:23am UTC](https://discourse.processing.org/t/performance-draw-vs-redraw/21763/5 "2020-06-11T11:23:00Z")

</div>

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?

---

<div class="post-metadata">

**Author:** ![jeremydouglass](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/jeremydouglass/32/20_2.png) [@jeremydouglass](https://discourse.processing.org/u/jeremydouglass)\
**Post date:** [June 11, 2020, 6:16pm UTC](https://discourse.processing.org/t/performance-draw-vs-redraw/21763/6 "2020-06-11T18:16:26Z")

</div>

> [@mgood7123](#):
>
> is redraw, in a `while(true) { redraw(); }` faster than just letting the draw loop run?

> [@micycle](#):
>
> In one sense, since `while(true) { redraw(); }` run at an unbounded rate

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.

> <https://github.com/processing/processing/blob/0ac37bca1d0c7c12667a9c0628fba63b31c1f135/core/src/processing/core/PApplet.java#L2393-L2398>

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

```auto
void draw() {
  background(128);
  text(frameRate, width/2,height/2);
}

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

```
