home/ atoms/ sonic-pi-fx-cpu-efficiency

Placing with_fx inside a loop creates one FX instance per iteration, wasting CPU

with_fx creates and destroys an FX instance each time the block is entered. Inside a tight loop this spawns a new reverb/echo/etc. on every iteration. The efficient pattern places the loop inside a single with_fx block. On low-power hardware (Raspberry Pi) this distinction is critical for keeping beats stable. The reps: opt (e.g., with_fx :reverb, reps: 16 do) limits iterations per FX instance without manual nesting.

Examples

efficient: one reverb for all iterations

with_fx :reverb do loop do play 60, release: 0.1 sleep 0.125 end end

Assessment

Predict what happens to CPU if you run with_fx inside a 120 BPM loop playing 16th notes. Show two ways to fix it.

“takes CPU power which may be precious”
corpus · sonic-pi-built-in-tutorial · chunk 16