Understanding DSP Load
Monitoring CPU Usage
Plugdata displays DSP load in the status bar. High CPU usage (>80%) can cause:- Audio dropouts and clicks
- Increased latency
- Unstable performance
Block Size Impact
Audio processing happens in blocks. Smaller blocks = lower latency but higher CPU usage:| Block Size | Latency @ 44.1kHz | CPU Load | Use Case |
|---|---|---|---|
| 64 | ~1.5 ms | High | Live performance, low latency |
| 128 | ~3 ms | Medium | General use |
| 256 | ~6 ms | Low | Studio production |
| 512 | ~12 ms | Very Low | Non-real-time processing |
Efficient Patch Design
1. Minimize Object Count
❌ Inefficient:Every object has overhead. Remove unnecessary processing.
2. Use Block-Level Processing
Process signals at block rate instead of sample rate when possible: ❌ Sample-rate processing:3. Avoid Redundant Calculations
❌ Recalculating repeatedly:4. Use Efficient Objects
Some objects are more optimized than others:| Instead of | Use | Reason |
|---|---|---|
[expr~] | [*~], [+~] | Built-in operators are faster |
[fexpr~] | Native filters | Compiled filters are optimized |
Multiple [line~] | [vline~] | Handles multiple ramps efficiently |
Subpatch Optimization
Use Subpatches for Organization
Subpatches don’t add overhead and improve readability:Block Size Adjustment
Use[block~] to optimize specific subpatches:
synthesis-engine
effects-chain
Switch~ for Conditional DSP
Disable DSP in inactive subpatches:Signal Processing Tips
1. Pre-compute Static Values
❌ Computing every block:2. Table Lookups
Use tables for complex functions: ❌ Expensive calculation:3. Filter Optimization
Choose appropriate filter types:| Filter | CPU | Quality | Use Case |
|---|---|---|---|
[lop~] / [hip~] | Low | Basic | Simple filtering |
[vcf~] | Medium | Good | Voltage-controlled filter |
[biquad~] | Medium | High | Precise EQ |
[fexpr~] | High | Custom | Only when necessary |
Message Domain Optimization
1. Reduce Message Rate
❌ Flooding with messages:2. Use [trigger] Efficiently
Control message order and avoid fan-out issues:3. Throttle GUI Updates
❌ Updating every message:Profiling with Perfetto
For advanced optimization, use Perfetto profiling:Memory Management
1. Avoid Memory Allocation in DSP
❌ Allocating in perform routine:2. Use Fixed-Size Buffers
Audio Thread Priority
Understanding Real-Time Priority
Plugdata runs audio in a high-priority thread. Keep audio callbacks fast:- ⏱️ Target: < 50% of block time
- ⚠️ Warning: > 80% may cause dropouts
- ❌ Critical: > 100% = guaranteed dropouts
Don’t Block Audio Thread
❌ Never do in DSP:- File I/O
- Network operations
- GUI updates
- Memory allocation
- Mutex locks (if avoidable)
sleep()or delays
- Use lock-free queues for communication
- Pre-load data in non-real-time thread
- Defer non-critical work
Platform-Specific Optimization
macOS
Metal Rendering: Enabled by default for better graphics performance (CMakeLists.txt:53, 376-382). Disable if needed:Windows
Use ASIO for lowest latency (automatically included, CMakeLists.txt:320, 385).Linux
JACK provides better performance than ALSA for real-time audio:- Lower latency
- Better CPU scheduling
- Inter-application routing
Benchmark Example
Create test patches to measure performance:test-oscillators.pd
Quick Optimization Checklist
- Remove unnecessary objects
- Use efficient alternatives ([*
] vs [expr]) - Avoid redundant calculations
- Use appropriate block sizes
- Throttle GUI updates
- Pre-compute static values
- Use [switch~] for inactive sections
- Profile with Perfetto (if needed)
- Check DSP load in status bar
- Test on target hardware
Common Bottlenecks
1. Too Many [expr~] Objects
Problem: Each [expr~] is interpreted at runtime. Solution: Replace with native objects or write C external.2. Excessive GUI Objects
Problem: VU meters, scopes updating every block. Solution: Update at lower rate (20-30 Hz).3. Large FFT Operations
Problem: FFT size too large for block size. Solution: Use power-of-2 sizes, increase block size in subpatch.4. Many Small Subpatches
Problem: Overhead from subpatch management. Solution: Consolidate when possible, but balance with readability.Resources
- Perfetto profiling: CMakeLists.txt:37, Resources/Scripts/add_perfetto_tracepoints.py
- Block size settings: CMakeLists.txt:31, 113-117
- Audio backend config: CMakeLists.txt:308-321
- DSP optimization guide: Pure Data Documentation
Next Steps
Building from Source
Compile optimized builds
Adding Externals
Create optimized C externals
