sojamo / controlp5

A gui library for processing.org
GNU Lesser General Public License v2.1
490 stars 142 forks source link

Scrolling Textarea is painfully slow #46

Closed feklee closed 8 years ago

feklee commented 8 years ago

When adding text using Textarea.append, eventually scrolling becomes painfully slow. I'm talking of a few dozen lines, though some of them with a few thousand characters.

Is that expected behavior? Any workaround?

sojamo commented 8 years ago

I can confirm that 50k characters long text using PFont (that is if you apply for example .setFont(createFont("arial",12)) to a textarea) and the default renderer results in slow scrolling.

Fix: Changing PFont to the default controlP5 pixel font gives me smooth scrolling (mousewheel and scrollbar) for 400k+ characters. When changing the default renderer to P3D or P2D, both, the pixel font as well as PFont give me smooth scrolling results for 400k+ characters. (I am using a modified version of the ControlP5Textarea example that comes with controlP5 where I append 50k junks of lorem ipsum text read from a file on keyPressed).

feklee commented 8 years ago

Changing PFont to the default controlP5 pixel font gives me smooth scrolling (mousewheel and scrollbar) for 400k+ characters.

Indeed this works, thanks for the suggestion! However, the default font has a couple of disadvantages:

  1. It’s tiny.
  2. It’s not fixed width.

Can it be swapped for another font?

When changing the default renderer to P3D or P2D, both, the pixel font as well as PFont give me smooth scrolling results for 400k+ characters.

Doesn’t work for me, i.e. with fonts set by PFont scrolling is painfully slow also for P3D and P2D. I’m using:

PFont font = createFont("Consolas", 12);
sojamo commented 8 years ago

Can it be swapped for another font?

you can manually set the font with cp5.setFont() for all controllers.

PFont font = createFont("Consolas", 12);
ControlP5 cp5 = ControlP5(this);
cp5.setFont(font);

Doesn’t work for me

Do you have more details about your os, processing version, controlP5 version. A working example which only highlights the issue you are encountering would be useful.

sojamo commented 8 years ago

since there was no follow up, closing issue.

feklee commented 8 years ago

Example code:

import controlP5.*;

void setup() {
  size(800, 600);

  Textarea ta = new ControlP5(this).addTextarea("").setSize(800, 600);

  for (int i = 0; i < 10; i++) {
    for (int j = 0; j < 1000; j++) {
      ta.append(" " + i);
    }
    ta.append("\n");
  }
}

void draw() {
  background(0);
}

Here a scroll bar appears, but scrolling does not work at all.

Memory consumption is insane. For one line, I have two Java processes, each using about 100,000 MB. For ten lines, one of the processes uses about 300,000 MB.

Environment: Processing 3.0.1 (same with 3.0.1), Windows 7 x64

sojamo commented 8 years ago

Hi, I dont find the memory behavior surprising, a lot more characters have to be drawn per frame which consequently will consume more memory. For example the following code consumes ~750MB right after running the sketch for rendering text across the window (I am on osx, Processing's maximum available memory is set to 2048MB):

String txt;
void setup() {
  size(800,600);
  txt = "";
  for (int i = 0; i < 10; i++) {
    for (int j = 0; j < 1000; j++) {
      txt += (" " + i);
    }
    txt += ("\n");
  }
}

void draw() {
  background(0);
  text(txt,0,0,800,600);
}

your given example starts with consuming 250MB for me and increases when scrolling, though settles at ~770MB after continuously scrolling up and down. This is not an unusual memory management behaviour, if memory is available it will be used. Try to decrease the allocated memory for a sketch inside Processing's preferences and you will see that memory usage will behave differently.

Again, scrolling works well for me in both P3D/P2D and default JAVA mode.

sojamo commented 8 years ago

no follow up, closing issue.