enhance the UI performance by using getShape() - especially in reference panels

Find and share HowTos to various installations / configurations!
5 posts • Page 1 of 1
leoknipp
Posts:2928
Joined: Tue Aug 24, 2010 7:28 pm

enhance the UI performance by using getShape() - especially in reference panels

Post by leoknipp »

If an attribute of an object is modified or read during runtime the function setValue()/getValue() or the dot notation is used.
The UI has to find the correct shape everytime when the function is called. Finding the correct shape might take some time, especially when there are a lot of objects in the panel.

The performance can be increased by using the getShape() function in the script where the object attributes are set/read. The function to find the correct shape is called only once. Afterwards the result of the getShape() function is used which leads to a better performance and decreased CPU usage.

There is no need to modify all scriipts in your panels. It can be used in objects with scripts that are called very often. A common use case are objects displaying values updated in a short interval (e.g. a measured value from the PLC with 1 value change / second).

script without getShape()

=============

Code: Select all

main()
{
  s_dp = $dpe + ".in.value";
  
  if (dpExists(s_dp))
    dpConnect("show_value", 1, s_dp);
}

show_value(string s_dp, float f_val)
{
  // everytime when when the work function is called and the attribute is set the correct shape must be identified
  setValue("value", "text", f_val);
}
=============


script with getShape()

=============

Code: Select all

shape s_shape;

main()
{
  // the shape information is read when the script is started
  s_shape = getShape("value");

  s_dp = $dpe + ".in.value";
  
  if (dpExists(s_dp))
    dpConnect("show_value", 1, s_dp);
}

show_value(string s_dp, float f_val)
{
  // the shape information is used when the attribute is set
  setValue(s_shape, "text", f_val);
}
=============


Best Regards
Leopold Knipp
Senior Support Specialist

RudiKreiner
Posts:198
Joined: Mon May 16, 2011 2:10 pm

Re: enhance the UI performance by using getShape() - especially in reference panels

Post by RudiKreiner »

Will this also improve performance if the code is in the init script of the shape itself?
In this case I would just write this in the work function:
this.text = fval;
I would expect that no searching for the shape is required in this case.

mkoller
Posts:741
Joined: Fri Sep 17, 2010 9:03 am

Re: enhance the UI performance by using getShape() - especially in reference panels

Post by mkoller »

You are right, in this case it would not improve. "this" and the empty string in set/getValue are immediately known and no search is needed.

Lbortolozzo
Posts:20
Joined: Tue Oct 03, 2017 12:33 pm

Re: enhance the UI performance by using getShape() - especially in reference panels

Post by Lbortolozzo »

Does the performance improvement offered by this method outweigh the performance increase offered by using setMultiValue rather than lots of individual setValues?

For instance, suppose I have a large number of shape Names and associated shapes that I need to change.

Would it be better to do:

dyn_string shapeNames;
dyn_anytype values;

setMultiValue( shapeNames[1] , attribute , values[1]
shapeNames[2] , attribute , values[2],
shapeNames[3] , attribute , values[3],
.....................................................)


Or:

dyn_shape shapes;
dyn_anytype values;

for(int i =1; i

leoknipp
Posts:2928
Joined: Tue Aug 24, 2010 7:28 pm

Re: enhance the UI performance by using getShape() - especially in reference panels

Post by leoknipp »

Using getShape() and the shape information instead of the object name is not the same like using setValue() or setMultiValue().
The shape information can be used at setValue() and setMultiValue().

Using setMultiValue() with the shape information instead of the object name will result in a better performance, it is the same for setValue().

Best Regards
Leopold Knipp
Senior Support Specialist

5 posts • Page 1 of 1