Hi everybody! It's been a while since I posted an occasional nugget, but it looks like y'all have been getting some great ones in the meantime from the usual suspects. I wanted to post today about three great new easy-to-use features in LabVIEW 8.5 that can improve your VI performance.
Feature: For Loop with Break
Why you should use it: How many times have you written a subVI that iterates over array contents in a While Loop, and stops when you find an element of interest *or* when you reach the end of the array? I've written that code dozens (maybe hundreds) of times, and I always have to stop and double-check my boolean logic that ends the loop to make sure it doesn't run infinitely, handles empty input arrays, outputs the correct element, etc. An example of that kind of code is shown below. In LabVIEW 8.5, we don't have to worry about those logic pitfalls with the For Loop with Break. In addition to making the code easier to write (and read), the equivalent For Loop with Break code will execute more efficiently than the While Loop code due to internal memory optimizations that can be done with a For Loop that are not possible with a While Loop.
Feature: Feedback Nodes outside of Loops
Why you should use it: I've been using Functional Globals (AKA "LabVIEW 2"-style globals) in my code for several years. In LabVIEW 8.5, we now have Feedback Nodes that can exist outside of loops. Not only does this clean up my code by allowing me to remove that extraneous loop, but the Feedback Node executes slightly more efficiently than it's Functional Global counterpart due to the fact that a small amount of overhead associated with executing the loop is eliminated. Here's some sample code.
Feature: In Place Element Structure
Why you should use it: If you need to modify an element inside a cluster, typically you will unbundle the element, make a change to it, then bundle it back into the cluster. Similarly, if you need to modify an array element, you index out that element, make a change, then use Replace Array Subset to stick it back in. Using these methods allows you to change the data without making an extra copy of the cluster (or array), but memory still needs to be allocated for the item you pull out (and then stick back in) to the cluster or array. In LabVIEW 8.5, we can use the In Place Element Structure to ensure that when we perform these kinds of operations, memory is reused in such a way that extra copies of those elements are not made. When you're dealing with complex data structures like clusters of arrays of clusters of etc., this can be a huge performance benefit. At the What's New in LabVIEW presentation at NI Week last week, I saw a demonstration where some code that processed a large array of complex clusters became 40 times faster when the index/unbundle/bundle/replace code was replaced with a couple of In Place Element Structures. One of my teammates recently replaced some similar code in his codebase and his execution speed increased by a factor of 8. I've already replaced several instances of this code in my current project, here's an example in which I use an In Place Element Structure nested inside another one.
I've been keeping a tally of the number of times I've used these new features in my current project. Taking into account the fact that NI Week took up a lot of my time last week, within the past two weeks, I've already dropped 11 For Loop with Breaks, 8 In Place Element Structures, and 6 Feedback Nodes. I'm really excited about continuing to incorporate these performance-enhancing features into my daily development.
-D
P.S. - Check out past nuggets
here.
Message Edited by Darren on 08-15-2007 01:49 PM