# Control P5 slowdown

**URL:** <https://discourse.processing.org/t/control-p5-slowdown/2250>\
**Category:** Processing for Android\
**Created:** [July 31, 2018, 10:44pm UTC](https://discourse.processing.org/t/control-p5-slowdown/2250 "2018-07-31T22:44:54Z")\
**Posts on this page:** 19\
**Page:** 1

<div class="post-metadata">

**Author:** ![philspitler](https://avatars.discourse-cdn.com/v4/letter/p/f1d935/32.png) [@philspitler](https://discourse.processing.org/u/philspitler)\
**Post date:** [July 31, 2018, 10:44pm UTC](https://discourse.processing.org/t/control-p5-slowdown/2250/1 "2018-07-31T22:44:54Z")

</div>

I have a weird issue where my sketch gets slower and slower the more Control P5 buttons I have. This behavior only shows up in Android mode, it seems fine when running in Java on OSX.

If you look at my code you will see I draw a UI with a bunch of buttons… If I comment out that code my sketch returns a value of 10 seconds which is correct for 24fps. If I leave all the buttons in my sketch the time goes up to 22 seconds… If I leave half the buttons in it is somewhere in the middle… I only create the buttons in setup so it seems odd that I am getting such a drastic slow down…

Any ideas?

Thanks,  
Phil

```auto

import controlP5.*;

Button myButton1;
Button myButton2;
Button myButton3;
Button myButton4;
Button myButton5;
Button myButton6;
Button myButton7;
Button myButton8;
Button myButton9;
Button myButton10;
Button myButton11;

ControlP5 cp5;
int buttonYpos = 0;
int currentFrame = 0;
int Yoffset = -55; 

void setup() {
  frameRate(24);

  size(1200, 1920);

  stroke(255);

  cp5 = new ControlP5(this); // 
  cp5.setFont(new ControlFont(createFont("Arial", 32), 32));
  cp5.setAutoDraw(false);

  // build UI
  myButton1 = cp5.addButton("alloff")

    .setCaptionLabel("All Off")
    .setValue(0)
    .setPosition(100, 250+Yoffset)
    .setSize(500, 60)

    ;

  myButton2 = cp5.addButton("grad")

    .setCaptionLabel("Color Grad")
    .setValue(0)
    .setPosition(100, 350+Yoffset)
    .setSize(500, 60)

    ;

  myButton3 = cp5.addButton("buddah")

    .setCaptionLabel("Pink Buddah")
    .setValue(0)
    .setPosition(100, 450+Yoffset)
    .setSize(500, 60)

    ;

  myButton4 = cp5.addButton("colorwipe")
    .setCaptionLabel("Color Wipe")
    .setValue(0)
    .setPosition(100, 550+Yoffset)
    .setSize(500, 60)

    ;

  myButton5 = cp5.addButton("orange")
    .setCaptionLabel("Orange Blossom")
    .setValue(0)
    .setPosition(100, 650+Yoffset)
    .setSize(500, 60)

    ;

  myButton6 = cp5.addButton("rustySwirl")
    .setCaptionLabel("Embers")
    .setValue(0)
    .setPosition(100, 750+Yoffset)
    .setSize(500, 60)

    ;

  myButton7 = cp5.addButton("psych")
    .setCaptionLabel("psychedelic blue")
    .setValue(0)
    .setPosition(100, 850+Yoffset)
    .setSize(500, 60)

    ;

  myButton8 = cp5.addButton("petals")
    .setCaptionLabel("rainbow petals")
    .setValue(0)
    .setPosition(100, 950+Yoffset)
    .setSize(500, 60)

    ;

  myButton9 = cp5.addButton("sunrise")
    .setCaptionLabel("Sunrise")
    .setValue(0)
    .setPosition(100, 1050+Yoffset)
    .setSize(500, 60)

    ;

  myButton10 = cp5.addButton("smoke")
    .setCaptionLabel("Ice Drops")
    .setValue(0)
    .setPosition(100, 1150+Yoffset)
    .setSize(500, 60)

    ;

  myButton11 = cp5.addButton("allSeq")
    .setCaptionLabel("All Sequences")
    .setValue(0)
    .setPosition(100, 1250+Yoffset)
    .setSize(500, 60)

    ;
} 

void draw() {

  cp5.draw();
  currentFrame = (currentFrame+1);

  if (currentFrame >= 240) { // 10 seconds @ 24fps
    println (millis()/1000); // how many seconds did it actually take?
    stop();
  };
}

```

---

<div class="post-metadata">

**Author:** ![kfrajer](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/kfrajer/32/196_2.png) [@kfrajer](https://discourse.processing.org/u/kfrajer)\
**Post date:** [August 1, 2018, 12:36am UTC](https://discourse.processing.org/t/control-p5-slowdown/2250/2 "2018-08-01T00:36:40Z")

</div>

Do you observe the same problem if you use P2D renderer?

`size(1200, 1920,P2D);` or `fullScreen(P2D);`

Kf

---

<div class="post-metadata">

**Author:** ![philspitler](https://avatars.discourse-cdn.com/v4/letter/p/f1d935/32.png) [@philspitler](https://discourse.processing.org/u/philspitler)\
**Post date:** [August 1, 2018, 6:56pm UTC](https://discourse.processing.org/t/control-p5-slowdown/2250/3 "2018-08-01T18:56:24Z")

</div>

@kfrajer I have some interesting findings…

I would expect the result of looping 240 times at 24FPS to result in a 10 second runtime.

Below are my results.  
size(1200, 1920,P2D) with no cp5.draw() 12 seconds  
size(1200, 1920,P2D) with cp5.draw() 15 seconds

size(1200, 1920) with no cp5.draw() 10 seconds  
size(1200, 1920) with cp5.draw() 23 seconds

So basically the sketch runs slower with P2D unless I am using CP5 in which case it runs faster… But still 50% slower than expected.

This is very perplexing… I would be interested for somebody else to run the code to see what results they get…

Cheers.

Phil

---

<div class="post-metadata">

**Author:** ![philspitler](https://avatars.discourse-cdn.com/v4/letter/p/f1d935/32.png) [@philspitler](https://discourse.processing.org/u/philspitler)\
**Post date:** [August 2, 2018, 12:45am UTC](https://discourse.processing.org/t/control-p5-slowdown/2250/4 "2018-08-02T00:45:32Z")

</div>

I wonder if something like G4P might be easy to implement without modifying too much of my code…

Or if G4P would actually be any faster…

Thoughts?

Cheers

Phil

---

<div class="post-metadata">

**Author:** ![Kevin](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/kevin/32/2297_2.png) [@Kevin](https://discourse.processing.org/u/Kevin)\
**Post date:** [August 2, 2018, 12:53am UTC](https://discourse.processing.org/t/control-p5-slowdown/2250/5 "2018-08-02T00:53:19Z")

</div>

It looks like you’re measuring startup time, not the frame rate.

What happens if you measure the actual frame rate instead of the startup time?

---

<div class="post-metadata">

**Author:** ![philspitler](https://avatars.discourse-cdn.com/v4/letter/p/f1d935/32.png) [@philspitler](https://discourse.processing.org/u/philspitler)\
**Post date:** [August 2, 2018, 2:09am UTC](https://discourse.processing.org/t/control-p5-slowdown/2250/6 "2018-08-02T02:09:18Z")

</div>

@Kevin the numbers I show are the runtime. I modified my code from what is shown above to start once I get into the draw function.

I didn’t realize I could use the frameRate function to detect the framerate, I will try that when I’m next back with my Android device… Thanks

Phil

---

<div class="post-metadata">

**Author:** ![Kevin](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/kevin/32/2297_2.png) [@Kevin](https://discourse.processing.org/u/Kevin)\
**Post date:** [August 2, 2018, 2:14am UTC](https://discourse.processing.org/t/control-p5-slowdown/2250/7 "2018-08-02T02:14:07Z")

</div>

Hmm I’m a little confused. The code that’s in your original post measures this:

```
[setup time] + [draw time] * [10 frames]

```

I would expect adding stuff to the `setup()` function to increase the result of this calculation.

Instead, can you measure the framerate itself? Processing provides some handy variables for this. I’d try something like this:

```auto
void draw(){
  cp5.draw();

  // print out frame rate once per second
  if(frameCount % 24 == 0){
    println(frameRate);
  }
}

```

---

<div class="post-metadata">

**Author:** ![philspitler](https://avatars.discourse-cdn.com/v4/letter/p/f1d935/32.png) [@philspitler](https://discourse.processing.org/u/philspitler)\
**Post date:** [August 2, 2018, 2:15am UTC](https://discourse.processing.org/t/control-p5-slowdown/2250/8 "2018-08-02T02:15:14Z")

</div>

@Kevin your method is much better than I had and I will test it tomorrow for sure.

Cheers

Phil

---

<div class="post-metadata">

**Author:** ![Kevin](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/kevin/32/2297_2.png) [@Kevin](https://discourse.processing.org/u/Kevin)\
**Post date:** [August 2, 2018, 2:22am UTC](https://discourse.processing.org/t/control-p5-slowdown/2250/9 "2018-08-02T02:22:37Z")

</div>

Cool sounds good. Also note that startup time with programs is especially hard to accurately measure, since so much is going on. It’s much better to measure the framerate or performance after the program is up and running.

That being said, it does seem suspicious that a few buttons would increase your startup time by 10 seconds!

---

<div class="post-metadata">

**Author:** ![kfrajer](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/kfrajer/32/196_2.png) [@kfrajer](https://discourse.processing.org/u/kfrajer)\
**Post date:** [August 2, 2018, 4:09am UTC](https://discourse.processing.org/t/control-p5-slowdown/2250/10 "2018-08-02T04:09:36Z")

</div>

I suggest you run examples provided by the library. Are they responsive?

I am not sure if printing to the console is helping here. Could you elaborate about your profiling? Are you synchronizing some event in the background or are you just testing the performance. If I were you, I would put an actual example together and test it. For instance, I ran your code without your printing and without altering the run cycle of cp5 and it is responsive.

I am using `fullScreen()`, I did not disable the autodraw and I am not calling stop within `draw()`. So yes, I am not calling `cp5.draw()` in draw with the above changes.

Kf

---

<div class="post-metadata">

**Author:** ![philspitler](https://avatars.discourse-cdn.com/v4/letter/p/f1d935/32.png) [@philspitler](https://discourse.processing.org/u/philspitler)\
**Post date:** [August 2, 2018, 5:08am UTC](https://discourse.processing.org/t/control-p5-slowdown/2250/11 "2018-08-02T05:08:24Z")

</div>

@kfrajer The slowness was not the responsiveness of the UI, the UI is snappy as expected.

The code listed is just sample code to illustrate the issue. My actual code loops through a folder of tiny PNG files and plays them as an animation. I did my animation at 24fps but noticed on playback it looked really slow.

That’s when I striped down my code to the minimum and still had the issue.

I’ll test the frame Rate tomorrow and report back…

Thanks for all the help.

Phil

---

<div class="post-metadata">

**Author:** ![kfrajer](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/kfrajer/32/196_2.png) [@kfrajer](https://discourse.processing.org/u/kfrajer)\
**Post date:** [August 2, 2018, 5:43am UTC](https://discourse.processing.org/t/control-p5-slowdown/2250/12 "2018-08-02T05:43:22Z")

</div>

I see now. Thxs for clarifying. Your best bet is to follow @Kevin’s advice then. Stick to java2d as it seems to be faster than P2D. Not sure why that is though… as I have seen cases of frame rate improvement switching to P2D.

Kf

---

<div class="post-metadata">

**Author:** ![Kevin](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/kevin/32/2297_2.png) [@Kevin](https://discourse.processing.org/u/Kevin)\
**Post date:** [August 2, 2018, 4:22pm UTC](https://discourse.processing.org/t/control-p5-slowdown/2250/13 "2018-08-02T16:22:02Z")

</div>

> [@philspitler](#):
>
> My actual code loops through a folder of tiny PNG files and plays them as an animation.

This I could see slowing things down at startup. Is it possible to create a small example that does this?

---

<div class="post-metadata">

**Author:** ![philspitler](https://avatars.discourse-cdn.com/v4/letter/p/f1d935/32.png) [@philspitler](https://discourse.processing.org/u/philspitler)\
**Post date:** [August 2, 2018, 9:05pm UTC](https://discourse.processing.org/t/control-p5-slowdown/2250/14 "2018-08-02T21:05:19Z")

</div>

@Kevin I thought it was the image sequence that was slowing things down but even with all that code stripped out cp5.draw() is slowing everything down…

I added the snippet you provided and it gave a very interesting result.

I switched to 48FPS and without cp5.draw() I get 48 FPS and with cp5.draw I get 23fps…

````auto

import controlP5.*;
Button myButton1;
Button myButton2;
Button myButton3;
Button myButton4;
Button myButton5;

ControlP5 cp5;
int buttonYpos = 0;
int currentFrame = 0;
int Yoffset = -55; 

void setup() {
  frameRate(48);

 size(1200, 1920);
 stroke(255);

  cp5 = new ControlP5(this); // 
  cp5.setFont(new ControlFont(createFont("Arial", 32), 32));
  cp5.setAutoDraw(false);

  // build UI
  myButton1 = cp5.addButton("alloff")

    .setCaptionLabel("All Off")
    .setValue(0)
    .setPosition(100, 250+Yoffset)
    .setSize(500, 60)

    ;

  myButton2 = cp5.addButton("grad")

    .setCaptionLabel("Color Grad")
    .setValue(0)
    .setPosition(100, 350+Yoffset)
    .setSize(500, 60)

    ;

  myButton3 = cp5.addButton("buddah")

    .setCaptionLabel("Pink Buddah")
    .setValue(0)
    .setPosition(100, 450+Yoffset)
    .setSize(500, 60)

    ;

  myButton4 = cp5.addButton("colorwipe")
    .setCaptionLabel("Color Wipe")
    .setValue(0)
    .setPosition(100, 550+Yoffset)
    .setSize(500, 60)

    ;

  myButton5 = cp5.addButton("orange")
    .setCaptionLabel("Orange Blossom")
    .setValue(0)
    .setPosition(100, 650+Yoffset)
    .setSize(500, 60)

    ;

} 

void draw() {

  cp5.draw();
   
    
 if(frameCount % 24 == 0){
    println(frameRate);
  }
 
}```
````

---

<div class="post-metadata">

**Author:** ![kfrajer](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/kfrajer/32/196_2.png) [@kfrajer](https://discourse.processing.org/u/kfrajer)\
**Post date:** [August 3, 2018, 1:00am UTC](https://discourse.processing.org/t/control-p5-slowdown/2250/15 "2018-08-03T01:00:11Z")

</div>

Samsung Galaxy S8 here…

- Running your code as in your previous post, I am getting between 27-31fps. However, if I touch the screen I notice the frameRate jumps to 47fps.

- Removing cp5.draw and autodraw(false) reflects about the same values for frame rate.

- Using `fullscreen()` aka. 1080x2220, frame rate falls back to 28-26fps and it changes up to the upper limit when the screen is touched.

- Removing all the buttons… yes, the rate is consistent at 48fps.

- Now, using fullScreen(P2D) and removing autoDraw(flase) and removing cp5.draw()… I get 48fps consistent.

So use P2D and do not disable the autodraw. I suggest you continue your project and ignore this for now, unless that it interfere with your project.

Kf

---

<div class="post-metadata">

**Author:** ![philspitler](https://avatars.discourse-cdn.com/v4/letter/p/f1d935/32.png) [@philspitler](https://discourse.processing.org/u/philspitler)\
**Post date:** [August 3, 2018, 2:26am UTC](https://discourse.processing.org/t/control-p5-slowdown/2250/16 "2018-08-03T02:26:55Z")

</div>

Great, I can’t check this until Tuesday but will certainly give that ago.

Thanks

Phil

---

<div class="post-metadata">

**Author:** ![philspitler](https://avatars.discourse-cdn.com/v4/letter/p/f1d935/32.png) [@philspitler](https://discourse.processing.org/u/philspitler)\
**Post date:** [August 7, 2018, 5:55pm UTC](https://discourse.processing.org/t/control-p5-slowdown/2250/17 "2018-08-07T17:55:45Z")

</div>

Thanks so much @kfrajer and @Kevin for all your help.

Using fullScreen(P2D) and removing autoDraw(false) and removing cp5.draw() worked perfectly.

Phil;

---

<div class="post-metadata">

**Author:** ![philspitler](https://avatars.discourse-cdn.com/v4/letter/p/f1d935/32.png) [@philspitler](https://discourse.processing.org/u/philspitler)\
**Post date:** [August 7, 2018, 7:25pm UTC](https://discourse.processing.org/t/control-p5-slowdown/2250/18 "2018-08-07T19:25:21Z")

</div>

As an FYI… the Processing sketch is used to control the lighting on our artcar at Burning Man

Much, much appreciated.

Phil

 ![P1150489-2](https://canada1.discourse-cdn.com/flex036/uploads/processingfoundation1/original/2X/3/358772112a23371a1b621a22010d152e09c33a75.jpeg)

---

<div class="post-metadata">

**Author:** ![Kevin](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/kevin/32/2297_2.png) [@Kevin](https://discourse.processing.org/u/Kevin)\
**Post date:** [August 7, 2018, 7:32pm UTC](https://discourse.processing.org/t/control-p5-slowdown/2250/19 "2018-08-07T19:32:07Z")

</div>

Wow that’s pretty cool. You should make a post about this in the [gallery](https://discourse.processing.org/c/gallery).
