06-14-2012 05:20 AM
My question is about performance issues associated with the unbundling from and bundling into a class structure with quite a lot of private class data in it.
The NI documentation says:
Note Consider using the Bundle By Name and Unbundle By Name functions instead of Bundle or Unbundle whenever possible to prevent VIs from breaking if you insert a new element into the cluster of private data.
I am wondering about the case where some variables are unbundled out of the cluster of private data, operations are performed, and some other variables are bundled into the same cluster, as in the following illustration.
My question is: in such a case, is it worth it using In Place Element Structures for unbundling and bundling instead of simple "Bundle/Unbundle by name" operations ? In the case illustrated in the picture, is there a risk of burdening the memory (or at least the CPU) with the entire private data of the class at some point ?
06-14-2012 06:15 AM
When you expect that the data type and size is not going to be affected, I would use the In Place Element Structure. So mainly for changes of the content.
For rather small operations it's often not worth the trouble of setting it all up.
Anyway, for large data operations I have noticed an better handling of memory, but this isn't scientifically proven / shown in nice figures. For speed, I can't say anything.
06-14-2012 07:58 AM
@calvintiger wrote:
My question is about performance issues associated with the unbundling from and bundling into a class structure with quite a lot of private class data in it.
The NI documentation says:
Note Consider using the Bundle By Name and Unbundle By Name functions instead of Bundle or Unbundle whenever possible to prevent VIs from breaking if you insert a new element into the cluster of private data.
I am wondering about the case where some variables are unbundled out of the cluster of private data, operations are performed, and some other variables are bundled into the same cluster, as in the following illustration.
My question is: in such a case, is it worth it using In Place Element Structures for unbundling and bundling instead of simple "Bundle/Unbundle by name" operations ? In the case illustrated in the picture, is there a risk of burdening the memory (or at least the CPU) with the entire private data of the class at some point ?
The note is a mantenance tip while the question you are posing is performance related.
The "inplace-structure" is not a magic bullet. It only helps you communicate your intentions ot the compiler. Most of the inplace opeartions can be invoked simply by structuring out code such that LV can optimize the data buffers.
The code you posted would have to be reworked a bit to actually be effective using inplace operations.
I believe the "Annealing_Class" data will be handled inplace but the buffer for "Desired Image" seems to be a candidate for inplaceness IF it does not grow inside the donut or as a result of normalizing. The update of the intensity plot will demand a buffer copy of course.
Don't know if I rally helped,
Ben
06-14-2012 08:04 AM
Hello Ben,
Thank you very much for your immensely helpful comment.
Since the "Desired Image" array has a fixed size, it is then a good candidate for an In Place structure..
A quick question: how did you determine that the first Unbundle operation was likely to be handled in place, unlike the Bundle operation that follows it ?
06-14-2012 08:23 AM
@calvintiger wrote:
Hello Ben,
Thank you very much for your immensely helpful comment.
Since the "Desired Image" array has a fixed size, it is then a good candidate for an In Place structure..
A quick question: how did you determine that the first Unbundle operation was likely to be handled in place, unlike the Bundle operation that follows it ?
How did I?
Years in the dark running benchmarks for threads like this one (this may be a good thread to learn for yourself).
How can YOU tell?
Get used to running benchmarks using large data sets (large enough to be measured) and get into the habit of using Profile >>> Show Buffer Allocations.
For your code then you should break-out the image data pass it THROUGH the sub-VI and put it back in the private data.
The "Clear as Mud" thread will tell you how to make sure you are passing the data through and not a copy.
Ben
06-14-2012 09:05 AM - edited 06-14-2012 09:07 AM
Thank you very much for these extra tips !
Another quick question: How about extracting a single class from the private data of the class, without re-bundling it later ? Would this operation suffer from performance issues ? Or can it be left as is ? (see example picture below - Camparams.Camera is a class whose private data has a small footprint, wheras the big class illustrated by the pink wire is massive).
06-14-2012 09:20 AM
@calvintiger wrote:
Thank you very much for these extra tips !
Another quick question: How about extracting a single class from the private data of the class, without re-bundling it later ? Would this operation suffer from performance issues ? Or can it be left as is ? (see example picture below - Camparams.Camera is a class whose private data has a small footprint, wheras the big class illustrated by the pink wire is massive).
i hve step outside my area of expertise but I believe that as long as that component class ends up back in the private data that is legit.
I THINK trying to run that inot a dynamic dispatch method would not be allowed being the LVOOP equivelent of a "dangling participle".
have fun,
Ben
06-14-2012 09:31 AM
Err, what do you mean "ends up back in the private data" ? There are no explicit efforts to put it back there.. I read the value with unbundle, but it is not bundled back later.
06-14-2012 09:37 AM
@calvintiger wrote:
Err, what do you mean "ends up back in the private data" ? There are no explicit efforts to put it back there.. I read the value with unbundle, but it is not bundled back later.
Not putting it back forces LV to guess about the data on that wire.
Since it is not going back LV will decide not to use the buffer that holds the component class inside the private data but rather it will duplicate that buffer and use the new copy. Choosing to do otherwise the changes made to the component class data would result in data flowing bckwards through the wire which is a no-no in LV.
I look at class data like my tools. If I take it out to use it, I put away when I am done. Otherwise I am likely to have to go buy another one since I can't find the one I own.
Ben
06-14-2012 09:46 AM
Ah ok, I see what you mean.
In such a simple case, do you recommend putting it back there with a "bundle by name", or to do the whole thing with an In Place Element Structure ?