Menu

#15 High CPU load when displaying a chart

v1.3
open
7
2010-08-30
2010-06-26
Anonymous
No

Hi,
I'm using the trunk (rev.245)
The "paint" method in "ChartFrame" seems to be called several time per second.
I'm not:
- updating a single thing (I've done my own data provider)
- touching the window, in fact I'm not even touching the mouse

It seems that it recomputes everything everytime even if there doesn't seem to be any reason of doing so.
I'm trying to figure things out...

Discussion

  • John Gonon

    John Gonon - 2010-06-28

    Hi again (I'm the one who posted the bug)
    I've found two points where you have an infinite loop for the painting:

    1) the ChartPanel.paint(...) method contains:
    Font font = chartFrame.getChartProperties().getFont();
    font = font.deriveFont(font.getStyle() ^ Font.BOLD);
    stockInfo.setFont(font);

    however, calling setFont() makes a repain() => infinite loop

    I replaced wth:
    Font oldFont = stockInfo.getFont();
    if (!oldFont.equals(font)) {
    stockInfo.setFont(font);
    }

    2) ChartFrame.updateHorizontalScrollBar() calls "repaint()" even if the "scrollBar" isn't modified => I replaced with the following:
    BoundedRangeModel model = scrollBar.getModel();
    boolean updated = false;
    if (model.getExtent() != items){
    model.setExtent(items);
    updated = true;
    }
    if (model.getMinimum() != 0){
    model.setMinimum(0);
    updated = true;
    }
    if (model.getMaximum() != itemsCount){
    model.setMaximum(itemsCount);
    updated = true;
    }
    if (model.getValue() != last - items){
    model.setValue(last - items);
    updated = true;
    }
    if (updated){
    scrollBar.setModel(model);
    repaint();
    }

    => once this is done, there is no more infinite loop on painting and CPU says "thanks".

    However when moving the scrollbar, it does not answer. The fact is that it counted on "updateHorizontalScrollBar()" to do so (why).
    Changing ChartFrame.adjustmentValueChanged() to call repaint() solves this problem.

     
  • Laurentiu Matei

    Laurentiu Matei - 2010-07-06
    • assigned_to: nobody --> viogheba
     
  • Laurentiu Matei

    Laurentiu Matei - 2010-07-06

    jgonon, thanks a lot for your remarks, they will be included in the next release.

    Vio, please update the code with the suggested changes or other solution.

     
  • krain

    krain - 2010-08-30

    Hi, i would like to use chartsy, unfortunately this bug doesn't allows me to. It's still present in 1.3 wasting my cpu (and energy) which i need for other programs. I hope you can fix it asap, as i really want to use it now and i would rather not wait till the next major update to use chartsy. Otherwise big thanks for chartsy. =)

     
  • Laurentiu Matei

    Laurentiu Matei - 2010-08-30

    I am looking into this and will come up with an answer. I will also check with the team on the exact reason why this was not fixed already.

    But looking at the CPU usage it's too high indeed.

     
  • Laurentiu Matei

    Laurentiu Matei - 2010-08-30
    • priority: 5 --> 7
    • assigned_to: viogheba --> cjlars
     

Log in to post a comment.

MongoDB Logo MongoDB