From Friday, April 19th (11:00 PM CDT) through Saturday, April 20th (2:00 PM CDT), 2024, ni.com will undergo system upgrades that may result in temporary service interruption.

We appreciate your patience as we improve our online experience.

LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Best way to remove local variables

I will explore how much time is being used by using the profiler, and see where the fat can be cut.

0 Kudos
Message 11 of 15
(1,910 Views)

 


@altenbach wrote:

 

[...]

As others have said, local variables typically don't cause slowdown (They cause additional datacopies in memory, have the potential of causing race conditions and cause messy code).[...]

 


 

While i totally agree with you, altenbach, creation of data copies DOES take time (variable configured for reading!), esp. if the system is already loaded and/or if the memory is already very fragmented.

So it *could* be possible, that usage of variables does induce a slowdown in addition to all other risks.....

 

But in most cases, the overhead for variables does not really fall into account. So everyone stating to search for other possible reasons is absolutly correct!

 

Just wanted to clearify this for everyone.

 

thanks,

Norbert

 

PS:  Short listing of "Pace of writing":

Terminal (being fastest)

Global variable

Local Variable

VI Server method "Set Control Value"

Property node "Value" (being slowest)

Norbert
----------------------------------------------------------------------------------------------------
CEO: What exactly is stopping us from doing this?
Expert: Geometry
Marketing Manager: Just ignore it.
Message 12 of 15
(1,888 Views)

@Norbert B wrote:

 

...

thanks,

Norbert

 

PS:  Short listing of "Pace of writing":

Terminal (being fastest)

Global variable

Local Variable

VI Server method "Set Control Value"

Property node "Value" (being slowest)


The order of those last two items would have been flop-flopped in my book. I'm willing to reset my memory if you can provide a reason why (or bench-marks) an operation that requires a text look-up of the "control name" can execute faster than an operation that laready has the reference.

 

Curious,

 

Ben

Retired Senior Automation Systems Architect with Data Science Automation LabVIEW Champion Knight of NI and Prepper LinkedIn Profile YouTube Channel
0 Kudos
Message 13 of 15
(1,876 Views)

Ben,

 

on my machine (Dell Latitude E6500) running Windows 7 and LV 2010f2, the property node value is about fourty times slower than using the VI Server method "Set Control Value". But there are not many controls on the panel though....

I do not know if the method gets slower in relation to the number of controls on the panel. This might reduce the difference, nevertheless i would think that "Set Control Value" is always faster than the prop node....

 

Norbert

 

SetControlValue.png

 

The code above is about 40 times faster than this one below (beware: DEPENDENT ON MACHINE!):

 

PropertyNode.png

Norbert
----------------------------------------------------------------------------------------------------
CEO: What exactly is stopping us from doing this?
Expert: Geometry
Marketing Manager: Just ignore it.
0 Kudos
Message 14 of 15
(1,871 Views)

 


@Norbert B wrote:

 

While i totally agree with you, altenbach, creation of data copies DOES take time (variable configured for reading!), esp. if the system is already loaded and/or if the memory is already very fragmented.

So it *could* be possible, that usage of variables does induce a slowdown in addition to all other risks.....


 

"takes time" is not the same as "causing slowdown". Unless the program is operating with huge data structures, todays computers are easily able to deal with it. So we have a few additional data copies. Another program without locals might have 10x larger data structures to begin with and still does not run slow.

Memory fragmentation problems arise if data structures constantly change size (e.g. insert into array, delete from array, built array) and that can easily be achieved without local variables. OTOH, local variables of fixed size data are typically not a problem.

 

We need to see the actual code to determine what the problem is.

 

 

0 Kudos
Message 15 of 15
(1,849 Views)