08-01-2022 09:50 AM - edited 08-01-2022 09:51 AM
What I've been doing lately when I have a lot of code/wires that can be grouped together, I've been putting that into a subVI. I've got another file with a tonnnn of messy wires in it, but I would probably be splitting it up into maybe 3 subVI's for all the different calculations. And then outputting a cluster.
Like the title says, is it slower to use subVI's? Am I slowing down my loop speeds by forcing the program to open a subVI?
Solved! Go to Solution.
08-01-2022 09:54 AM
@David99999 wrote:
Like the title says, is it slower to use subVI's? Am I slowing down my loop speeds by forcing the program to open a subVI?
Short answer: No.
More nuanced answer: The subVI call overhead is so tiny that it is basically non-existant.
08-01-2022 09:59 AM - edited 08-01-2022 10:16 AM
You probably won't see much of a difference, but the problem is complicated and multidimensional
The correct way is to do a better program design from the ground up. Use subVIs for code that is used in several places. Define their behavior and fully debug them so the you can focus on the main logic in the toplevel. There is rarely a need for gigantic diagrams.
SubVIs also should only have a limited number of well defined and labeled inputs and outputs. Just creating subVIs from a huge pile of spaghetti code will blur all the code logic and make things even harder to debug..
Check the code complexity in VI options:
Adjust the threshold if you prefer optimizations over compile time:
We probably could give you much more specific advice after seeing your code. 😄
08-01-2022 10:01 AM
Breaking code up into subVIs based on function is a good reason to create a subVI as well.
08-01-2022 10:35 AM - edited 08-01-2022 10:45 AM
That is a good question But the answer is very complex. I'll try to hit some of the general points and see if I can help you refine what you are concerned about in your code.
There is a cost in time for a vi call. It can vary a lot under certain conditions:
This list is not exhaustive but, illustrates the complexity of the answer.
Generally though, there are very few cases that I have ever come across where absolute performance of a program was impacted more by a subvi call than other code concerns such as;
08-01-2022 12:41 PM
@David99999 wrote:
What I've been doing lately when I have a lot of code/wires that can be grouped together, I've been putting that into a subVI. I've got another file with a tonnnn of messy wires in it, but I would probably be splitting it up into maybe 3 subVI's for all the different calculations. And then outputting a cluster.
Like the title says, is it slower to use subVI's? Am I slowing down my loop speeds by forcing the program to open a subVI?
Since you ask this question, you must be a beginner and to keep things simple, as other experts have commented, the answer is "NO"
The answer becomes a "Maybe" if you call the same subVI in more than one section of code in parallel and the subVI takes a considerable amount of time to execute, now the flat VI method would have been faster. But that is not all, you can change the re-entrancy of the subVI (under careful consideration of what is inside it) to make it as fast as the flat code.
08-01-2022 04:25 PM
Everyone before me covered the technical points, so here's my high-level take:
If you're at a point where you think the call time of a subVI is limiting the performance of your application, then you have bigger problems to worry about than subVI call times.
Most likely the actual problem would truly be one of:
Or something else along those lines.
08-01-2022 05:11 PM
@David99999 wrote:
What I've been doing lately when I have a lot of code/wires that can be grouped together, I've been putting that into a subVI. I've got another file with a tonnnn of messy wires in it, but I would probably be splitting it up into maybe 3 subVI's for all the different calculations. And then outputting a cluster.
Like the title says, is it slower to use subVI's? Am I slowing down my loop speeds by forcing the program to open a subVI?
Why not try it and see for yourself? Make a loop with a bunch of code in it, time that. Then select all the code in the loop, click 'create sub vi from selected code' then time it again.
08-01-2022 07:16 PM
@Jay14159265 wrote:
Why not try it and see for yourself? Make a loop with a bunch of code in it, time that. Then select all the code in the loop, click 'create sub vi from selected code' then time it again.
Creating a valid benchmarking harness is full of landmines. There is a very high change that the results are meaningless. 😄
08-01-2022 08:52 PM
@altenbach wrote:
@Jay14159265 wrote:
Why not try it and see for yourself? Make a loop with a bunch of code in it, time that. Then select all the code in the loop, click 'create sub vi from selected code' then time it again.Creating a valid benchmarking harness is full of landmines. There is a very high change that the results are meaningless. 😄
There's also a very high chance that it will illustrate how in the weeds the question is.