LabVIEW Performance and Memory Management
LabVIEW Performance and Memory Management
Goals
Understand the LabVIEW Execution
System
Learn to improve performance by:
Reducing data copies
Reducing overall memory usage
Clump 0
LabVIEW Clumping
ClumpAlgorithm
1
Clump 0
Clump 2
LabVIEW Clumping
Algorithm
Clump 1
Clump 0
Start of diagram:
Reads controls, then
schedules Clumps 1
and 2
Then sleeps...
Clump 2
Bottom For Loop
Indicator is
updated
Clump 0
Scheduled
Sleep...
Clump 1 Sleeping
Completion of
diagram:
Divide nodes, display
of
indicators, then VI
exit.
Clump 2 Sleeping
Going to sleep
When a node goes to sleep it puts itself on a
wait queue and then returns to the execution
system
E.g., Queues, SubVI calls, debugging, etc.
Switching Execution
Systems
Happens when code needs to run in a different
execution system than the caller or previous code
Most common with UI code
Switching execution systems can cause
performance problems
Requires going to sleep and then waking up on another
execution system thread
Switching back takes just as long
Can sometimes set Preferred Execution System to
avoid extra switches
Priorities
SubVI priorities affect the priority of the queue
elements for that VI within an execution
system
Higher priority queue elements are pulled off
first
The priority setting does not affect the priority
of the execution system thread itself
The OS may preempt the whole thread to run the
thread for another execution system (or other
process)
Use Timed Loops to control priority more reliably
Subroutine Priority
Not a real priority
Reduces execution system overhead for very
commonly called code
Forces the whole VI to be in a single clump
Prevents the VI from ever going to sleep
No calls which may sleep (like queue operations)
No switching execution systems
Can only call other subroutine VIs
No parallelism
Can be set to Skip Subroutine Call If Busy
Usually not recommended
Inline VIs
Preferred replacement for Subroutine Priority
Entire block diagram is inserted into caller when
the caller is compiled
Zero call overhead
Wire Semantics
Every wire is a buffer
Branches create copies
Optimizations by LabVIEW
The theoretical 5 copies become 1 copy
operation.
Copy
Bottom Up
In place information is propagated
bottom up through the call
hierarchy
Branched wire
Copy because
of increment
No copies required
Example of In Place
Optimization
changes
into
changes
into
Transfer Buffers
Copy
Copy
Transfer Buffers
protect data transfer
between Operate and
Execution Buffers
Only updated if front
panel is in memory
Property Nodes
Must run in UI thread
Copies to/from operate buffer
Writes cause second copy into transfer buffer
Force front panel in memory
Use when synchronous display is necessary
Data by Reference
Manipulate references to the data instead
of the data itself
Data
Reference
Data Copy
Reference
Data Copy
Reference
By reference: points to
memory location
Memory Reallocation
Preallocate an
array if you:
Conditionally
add values to
an array
Can determine
an upper limit
on the array
size
Conditional Indicators
An indicator inside a Case structure
or For Loop
Prevents LabVIEW from reusing data
buffers
LabVIEW Cleanup
LabVIEW cleans up many references
when the owning VI goes idle and others
when the process closes
Manually close references to avoid
undesirable memory growth, particularly
for long-running applications.
Memory Fragmentation
1.6 GB
0.4 GB
Report
ed
0.34
GB
0.16 GB
0.42 GB
0.38
GB
0.3 GB
Actual
0.1 GB
0.16 GB
0.14 GB
Used
Available
Questions