2

I am updating/maintaining an existing graphing program. This is suppose to be a medium duty program (able to handle anything less than a million nodes + their transitions). In the GUI, there is a 'viewport' that visually shows the graph and there is a side panel that contains tabs that contain summaries on the nodes, transitions, etc...

The graphical part works phenominal and is quick but after running a profiler (YourKit) 96-99.8% of the time is spent creating the summary tab/table for the nodes. So for 10,000 nodes, it takes a second or two to generate the graph visually but minutes for it to populate the table!

A summary of the process is this: the tab gets notified that the model changed and gets the node list. If it needs more rows, it adds them, else it reuses or throws old ones away. Then after creating the rows and their cells, it fills them.

The population is one node per row, three cells (JPanel) per row (each contain some information). Each time a cell is created when a new row is added or the row is asked to check for updates, it calls the "positionPanel" method provided below. The layout manager is SpringLayout. According to the profiler, of the 90-odd percent to generate this table, 90-odd percent minus one is the "add(newPanel);" line.

Any suggestions on where the speed is being taken and how to improve it?

private void positionPanel(int row, int col) {

      JPanel upPanel = this;
      JPanel leftPanel = this;
      String upSpring = SpringLayout.NORTH;
      String leftSpring = SpringLayout.WEST;
      if (row != 0) {
        upPanel = cells.get(row - 1)[col];
        upSpring = SpringLayout.SOUTH;
      }
      if (col != 0) {
        leftPanel = cells.get(row)[col-1];
        leftSpring = SpringLayout.EAST;
      }
      Cell newPanel = cells.get(row)[col];
      //cells.get(row).set(col, newPanel);
      add(newPanel);
      layout.putConstraint(SpringLayout.NORTH, newPanel, cellSpacing, upSpring, upPanel);
      layout.putConstraint(SpringLayout.WEST, newPanel, cellSpacing, leftSpring, leftPanel); 
}
tenorsax
  • 21,123
  • 9
  • 60
  • 107
Lan
  • 1,206
  • 1
  • 11
  • 26
  • @Max The class in question was made on July 18th, 2006 according to its documentation. They had their reasons for making their own tables, I think so they could have check boxes. I will run benchmarks to see how JTable will handle the load, probably will change over to that. – Lan Jul 23 '12 at 02:49
  • @jdmaguire: For convenience, the default [renderer](http://docs.oracle.com/javase/tutorial/uiswing/components/table.html#editrender) for `Boolean.class` is `JCheckBox`. – trashgod Jul 23 '12 at 11:18

1 Answers1

3

The suggestion to consider JTable hinges on it's use of the flyweight pattern to implement rendering. The benefit comes from rendering only visible/altered nodes, while ignoring others. JGraph uses a similar approach. The essential mechanism is outlined here. Note that the benefit accrues only to the view, but your profiling suggests it may be worthwhile.

Community
  • 1
  • 1
trashgod
  • 203,806
  • 29
  • 246
  • 1,045