Skip to main content
Optimizing your patches ensures smooth real-time performance, reduces CPU usage, and minimizes audio dropouts. This guide covers practical techniques for efficient patch design.

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: Access via: Settings → Audio Settings → Block Size

Efficient Patch Design

1. Minimize Object Count

❌ Inefficient:
✅ Optimized:
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:
✅ Block-rate processing:

3. Avoid Redundant Calculations

❌ Recalculating repeatedly:
✅ Calculate once:

4. Use Efficient Objects

Some objects are more optimized than others: Example: ❌ Slower:
✅ Faster:

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
[block~] must be a multiple or divisor of the parent block size.

Switch~ for Conditional DSP

Disable DSP in inactive subpatches:

Signal Processing Tips

1. Pre-compute Static Values

❌ Computing every block:
✅ Load from message:
For dynamic but infrequent changes:

2. Table Lookups

Use tables for complex functions: ❌ Expensive calculation:
✅ Table lookup:

3. Filter Optimization

Choose appropriate filter types:

Message Domain Optimization

1. Reduce Message Rate

❌ Flooding with messages:
✅ Appropriate rate:

2. Use [trigger] Efficiently

Control message order and avoid fan-out issues:

3. Throttle GUI Updates

❌ Updating every message:
✅ Throttled updates:

Profiling with Perfetto

For advanced optimization, use Perfetto profiling:

Memory Management

1. Avoid Memory Allocation in DSP

❌ Allocating in perform routine:
✅ Pre-allocate in constructor:

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
✅ Do instead:
  • 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
Enabled by default (CMakeLists.txt:308, 313).

Benchmark Example

Create test patches to measure performance:
test-oscillators.pd
Monitor CPU load to compare approaches.

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