Factors like inefficient memory use, poorly designed panels, and too many I/O calls can negatively affect the execution speed of your VI. However, there are several strategies you can use to ensure that your VI runs more efficiently.
Strategies for Improving Execution Speed through Memory Management
Effective memory management can improve the execution speed of your VI. By minimizing memory usage, you can help alleviate slow VI execution speeds, which are affected by allocation and deallocation operations. Execution speed is indirectly affected by the allocation of more space in memory because operations slow down if they reach the memory's capacity.
The more you allocate, deallocate, or move data in memory, the more memory the VI uses. Memory can also indirectly affect execution speed because allocating more space in memory leaves less memory for other operations, causing them to slow down if they reach the memory's capacity.
When creating a VI, consider the following guidelines:
Use consistent data types and watch for coercion dots when passing data to subVIs.
Avoid using hierarchical data types such as arrays of clusters containing large arrays or strings.
Reduce the use of nested subVIs inside of other VIs, as these can cause an exponential increase in the number of VI clones needed to maintain separate data spaces for each call to a subVI.
Avoid the following, which can create additional and unnecessary copies of data:
Repeatedly resizing data—Clearing space in memory or adding and removing data from memory creates overhead and can take time.
Overusing duplicated array and string terminals—Creating more than one corresponding object on the diagram can increase memory usage.
Unintentionally coercing data—Coercion dots appear on nodes when data types are coerced. Data type coercion can decrease execution speed and increase memory usage, especially when you use complex data types or large arrays because they can increase memory usage.
Displaying large arrays and strings on panels—Displaying the smallest array or string on the panel will ensure that copies of data remain small. The larger the array or string, the larger the copy of contained data.
Strategies for Improving Execution Speed by Minimizing I/O Calls
I/O calls can incur a significant amount of overhead and take more time than a computational operation because I/O calls have to wait on external resources. You can improve VI execution speed by using various strategies to troubleshoot or optimize I/O calls.
The following example diagram shows an inefficiently structured loop. The loop is inefficient because the I/O functions within the loop run multiple times unnecessarily and are structured to write a small amount of data each iteration.
When troubleshooting or optimizing your I/O calls, examine the following items to ensure your loop runs efficiently:
I/O calls—You can reduce excessive overhead by reducing the number of I/O Write or Read calls. Limit the use of nodes within your loop that interact with external resources. Nodes like Write to Text File and TCP Write can incur the overhead of the external resource they interact with, like a network card, an OS, or file system.
Data transfer quantities—Instead of making multiple I/O calls with smaller quantities of data, structure the VI to transfer large amounts of data with each call. Consolidate data into large chunks by using arrays and concatenated strings whenever possible.
Unnecessary nodes outside of loops—Avoid putting a node in a loop if the node produces the same value for every iteration. Instead, move the node out of the loop and pass the result into the loop. Also, keep nodes that open or close references such as TCP Open Connection and Close File outside of loops to avoid repetitive overhead delays when interacting with external resources.
The following example diagram shows the loop restructured for efficiency:
- The loop is efficient because it minimizes the number of I/O calls.
- The loop is structured to transfer significant amounts of data with each call.
- The loop does not contain unnecessary computations.
Guidelines for Designing Efficient Panels
Optimizing your panel can improve the execution speed of your VI. Design and configure your panel according to the following guidelines:
Remove unnecessary panel objects and avoid adding objects to the panel that aren't necessary for controlling input to the diagram or observing output data.
Avoid transparent and overlapped panel objects unless necessary.
When using charts, reducing Chart History Length in the Configuration pane will set the maximum number of data points drawn to your chart.
When using graphs and charts, turn off auto-scaling, axis labels, anti-aliased line drawing, and axis grids to prevent drawing more elements. A graph with fewer elements takes less time to redraw every time the graph updates.
Using Parallel Loops to Increase VI Execution Speed
When multiple loops run in parallel, the VI switches between them periodically. Parallel loops can help decrease execution time by simultaneously running independent tasks within individual loops. In the following example diagram, a single loop contains multiple independent tasks. This loop is inefficient because execution speeds can vary due to the lack of loop timing. In this example, the DAQ operation must wait for the slower I/O function and a status check to complete each iteration.
Since all parallel loops share the same processor resources, consider the following practices to make sure other loops do not interrupt the timing or execution of your important tasks:
Important Operations—Because you want this type of operation to execute as frequently as possible, do not add timing nodes inside the loop to delay its execution.
Executions Dependent on Dequeue Element node—The Dequeue Element node can halt the execution of a loop until an element is ready in the queue. This node allows more important loops to use more of the processor's time.
Low-Importance Operations—Because this type of operation is the least important, you can use a Wait node to run the operation less often and yield execution time to the other loops.
The following is an example of a recreated VI using the considerations:
- The Read DAQ loop reads data from a DAQ device and sends the data to a queue. Do not add timing nodes because you want this type of operation to execute as frequently as possible.
- The Write to File loop can execute more slowly as it is logging data points for later analysis. The execution of this loop can be dependent on elements being ready in the queue because it does not need to execute as frequently.
- The Check Temperature loop displays temperature data to the user and uses a Wait node to run less often and yield execution time to the other loops because it is the least important.