# PowerTable cellUpdate script performance issues

**URL:** <https://forum.inductiveautomation.com/t/powertable-cellupdate-script-performance-issues/17213>\
**Category:** Ignition\
**Created:** [March 4, 2018, 11:22pm UTC](https://forum.inductiveautomation.com/t/powertable-cellupdate-script-performance-issues/17213 "2018-03-04T23:22:10Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![pat.stave1](https://avatars.discourse-cdn.com/v4/letter/p/f19dbf/32.png) [@pat.stave1](https://forum.inductiveautomation.com/u/pat.stave1)\
**Post date:** [March 4, 2018, 11:22pm UTC](https://forum.inductiveautomation.com/t/powertable-cellupdate-script-performance-issues/17213/1 "2018-03-04T23:22:10Z")

</div>

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:

[![](https://us1.discourse-cdn.com/inductiveautomation/original/3X/7/5/75ed2c5446cea1408d880f6de69d4139345796f7.jpeg "Ignition configureCell script performance") ](https://www.youtube.com/watch?v=WUayHMMbHIU)

---

<div class="post-metadata">

**Author:** ![pturmel](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/pturmel/32/3295_2.png) [@pturmel](https://forum.inductiveautomation.com/u/pturmel)\
**Post date:** [March 4, 2018, 11:44pm UTC](https://forum.inductiveautomation.com/t/powertable-cellupdate-script-performance-issues/17213/2 "2018-03-04T23:44:58Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![pat.stave1](https://avatars.discourse-cdn.com/v4/letter/p/f19dbf/32.png) [@pat.stave1](https://forum.inductiveautomation.com/u/pat.stave1)\
**Post date:** [March 5, 2018, 4:11am UTC](https://forum.inductiveautomation.com/t/powertable-cellupdate-script-performance-issues/17213/3 "2018-03-05T04:11:21Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![Sanderd17](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/sanderd17/32/8735_2.png) [@Sanderd17](https://forum.inductiveautomation.com/u/Sanderd17)\
**Post date:** [March 5, 2018, 7:36am UTC](https://forum.inductiveautomation.com/t/powertable-cellupdate-script-performance-issues/17213/4 "2018-03-05T07:36:44Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![jpark](https://avatars.discourse-cdn.com/v4/letter/j/a88e57/32.png) [@jpark](https://forum.inductiveautomation.com/u/jpark)\
**Post date:** [March 5, 2018, 4:29pm UTC](https://forum.inductiveautomation.com/t/powertable-cellupdate-script-performance-issues/17213/5 "2018-03-05T16:29:37Z")

</div>

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.

```auto
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

```

---

<div class="post-metadata">

**Author:** ![Kyle\_Chase](https://avatars.discourse-cdn.com/v4/letter/k/9de0a6/32.png) [@Kyle\_Chase](https://forum.inductiveautomation.com/u/Kyle_Chase)\
**Post date:** [March 7, 2018, 6:48pm UTC](https://forum.inductiveautomation.com/t/powertable-cellupdate-script-performance-issues/17213/6 "2018-03-07T18:48:00Z")

</div>

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

1. Put this in the initialize extension function

```auto
from javax.swing import JLabel
self.putClientProperty("JLabel",JLabel)

```

1. In the configureCell extension function, you can do something like:

```auto
JLabel = self.getClientProperty("JLabel")
img = JLabel()

```

This is just an example.
