PowerTable cellUpdate script performance issues

I have a window containing a Power Table component.
This power table needs to display images (stored as SQL blobs) in one particular column.

Based on scripts from this forum (jdfrankston) i have the following script firing on the power table “cellUpdate” event that creates a JComponent in the cell, and also scales the image to fit.

def configureCell(self, value, textvalue, selected, rowIndex, colIndex, colName, rowView, colView)
if colName == “alarmimage” and value != None:

  	from javax.swing import JLabel,ImageIcon,JPanel
  	from java.awt import Font,Image,GridLayout,Color
  			
  	image = ImageIcon(value)
  	
  	maxWidth = 100
  	width = image.getIconWidth()
  	height = image.getIconHeight()
  	scaledWidth = maxWidth
  	scaledHeight = height * (float(scaledWidth)/width)
  	
  	#Diagnostics
  	print ("Start of scaling table JLabel Image")
  	print ("Width: ") + str(width)
  	print ("Height: ") + str(height)
  	print ("Max Width: ") + str(maxWidth)
  	print ("Scaled width: ") + str(scaledWidth)
  	print ("Scaled height: ") + str(scaledHeight)
  	
  	image = ImageIcon(image.getImage().getScaledInstance(int(scaledWidth),int(scaledHeight),Image.SCALE_SMOOTH))
  	img = JLabel(image,JLabel.LEFT)   

  	return {"renderer":img}

The script works fine, except on performance.

  • The client is slow and lagging all the time when this particular window is opened (even when no data is updating)
  • The byte-size of the images does not seem to make a imact. Even small images (10 kB) creates this problem.
  • When using the controls on the PoweTable, the cellUpdate script fires “continously”, But the performance issue seems to be present even when the script is not firing.

See video:

Do you have any animation or other object layered on top of this table? That will trigger many repaint events, which will each have to call your function for any visible rows.

No animations or other objects, only the PowerTable with a SQL database binding and cellUpdate script.

Can you try to make a cache in a project script?

You could keep a dictionary there that holds the JLabel instance for every image URL, and pass that when queried (or calculate a new JLabel when it’s queried for the first time).

It’s very easy to make the cellUpdate code too slow, as that’s executed for every cell repaint.

The problem is those imports happening for every cell on every repaint.
Move the code that generates the image into a project script and then call that function from configureCell.

from javax.swing import JLabel,ImageIcon,JPanel
from java.awt import Font,Image,GridLayout,Color


def getMyRenderer(value):
	image = ImageIcon(value)

	maxWidth = 100
	width = image.getIconWidth()
	height = image.getIconHeight()
	scaledWidth = maxWidth
	scaledHeight = height * (float(scaledWidth)/width)

	image = ImageIcon(image.getImage().getScaledInstance(int(scaledWidth),int(scaledHeight),Image.SCALE_SMOOTH))
	img = JLabel(image,JLabel.LEFT)
	return img
1 Like

If you want to keep everything bundled into the component, you could also do this:

  1. Put this in the initialize extension function
from javax.swing import JLabel
self.putClientProperty("JLabel",JLabel)
  1. In the configureCell extension function, you can do something like:
JLabel = self.getClientProperty("JLabel")
img = JLabel()

This is just an example.

1 Like