LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Darren's Weekly Nugget 11/30/2009

If you're having performance problems in your LabVIEW application, the VI Profiler is one of the easiest ways to pinpoint, at the subVI level, where bottlenecks occur.  The easiest way to illustrate this tool's usefulness is with a real-world example.  While testing the VI Analyzer Toolkit 2009 earlier this year, I noticed that it was taking an unusually long time to launch, both when I was using the interactive UI and the programmatic interface.  So I figured I would use the VI Profiler to benchmark the execution of a very simple VI, that creates, then destroys, a VI Analyzer analysis task:

 

vian_new_destroy.png

 

I launched the VI Profiler from Tools > Profile > Performance and Memory..., clicked "Start", ran my VI, then once it was done, clicked "Snapshot".  Here's what I saw:

 

profile_before.png

 

When sorting these results by the VI Time column, I saw that the VIAnUI Get Test Rankings.vi took way more time than anything else in the VI hierarchy.  I found this rather strange, given the simplicity of that VI's diagram:

 

 get_rankings_diagram.png

 

This VI hasn't changed in a long time, yet I hadn't noticed the VI Analyzer launch slowdown until recent versions of the toolkit.  That's when I realized what the problem was.  As you can see, I am closing the reference to each test VI once I've retrieved its ranking.  Well, in LabVIEW 8.6, all the VI Analyzer Toolkit tests were added to a project library to support licensing of the toolkit.  And when you open a reference to a VI in a library, the library must be loaded into memory as well.  So in the code above, I am loading, then unloading the VI Analyzer Toolkit library on each iteration of the loop.  The fix was to simply build up the VI references on the loop output border, then wire the array of references to a single Close Reference function on the outside of the loop.  Once I did this and reran the benchmark VI, I got these results:

 

profile_after.png

 

This subVI's performance increased 10x, and the overall execution time of the benchmark VI decreased from 7.5 seconds to 1.5 seconds.  The fix was extremely simple, but it would have been very difficult to track down without the help of the VI Profiler.

 

Oh, and I didn't investigate this until after VI Analyzer 2009 released...so you'll have to wait until VI Analyzer 2010 to enjoy the faster launch time.  🙂

Message Edited by Darren on 11-30-2009 12:46 PM
Message 1 of 8
(7,228 Views)

I wonder if there are any particular things to keep in mind while deciding when to use "Close Reference" with all references together after a loop and when to use "Close Reference" inside the loop.

 

When I started off in the world of references, I used to close them once I'm done with them (i.e. in the loop). Then one fine day I realized that I can index the references and close them in one go (i.e. outside the loop), improving the performance significantly. Then just the other day, I find out that it is more advisable to close them as soon as I'm done using them again. Smiley Happy ummm... Pretty clueless... Smiley Very Happy

 

Is this a memory usage vs time taken trade-off?

0 Kudos
Message 2 of 8
(7,074 Views)

About closing references, you might find this blog post by Darren intersting. Also read the comments.

 

Felix 

Message 3 of 8
(7,054 Views)
As I mention in the blog post, it is best to close references when you're done with them.  It tends to yield cleaner diagrams, and in the case of building up an array on a loop border, saves on the array memory allocation.  However, in the example shown in my initial post, I essentially implemented the simplest of caching schemes by building up the VI references on the loop border, thereby keeping the VI Analyzer tests library in memory and speeding up subsequent Open VI Reference calls after the first one.
0 Kudos
Message 4 of 8
(6,994 Views)

Very cool.

And we can use it in the similar structure.

Smiley SurprisedBut I wonder if you will release a patch for VI Analyze2009

0 Kudos
Message 5 of 8
(6,897 Views)

tom.huo wrote:
But I wonder if you will release a patch for VI Analyze2009

If you're running LabVIEW 2009, you can replace VIAnUI Get Test Rankings.vi in [LabVIEW 2009]\vi.lib\addons\analyzer\_vianuishared.llb with the one I have attached here, and you'll get the fix.

Message 6 of 8
(6,890 Views)

Thank you, Darren.

Smiley HappyWhat a great idea! Cheers!

0 Kudos
Message 7 of 8
(6,876 Views)

Darren wrote:

 

The fix was to simply build up the VI references on the loop output border, then wire the array of references to a single Close Reference function on the outside of the loop.


I never knew that the Close Ref function can accept an array of references. Smiley Surprised

- Partha ( CLD until Oct 2027 🙂 )
0 Kudos
Message 8 of 8
(6,823 Views)