Complexity and Performance

Hi,

lately I have some ideas of what I would like to do with Sonic Pi on the long run. Amonst these are the integration of different devices to control Sonic Pi or to record and refeed output (in other words: there is much stuff going before I even produce sound) or speedy arrangements with filter movements aso. Obviously I am stressing my hardware (right now a Lenovo Thinkpad with a 4-core i7 and 16 GB RAM) to its limits. It is a challenge of its own to just cope with what I have and adjust my music to it. But on the other side …

… I am courious what sort of hardware I would need to run e. g. things like the following, if I wanted to add even more stuff to it. It runs but gives a time warning right from the start and will quit eventually after a while or if I add another dynamic factor):

use_bpm 180

with_fx :reverb, room: 0.75, mix: 1 do
  live_loop :line do

    use_synth :fm
    use_synth_defaults attack: (line 0.5, 0, steps: 256).mirror.tick, release: (line 2, 0.25, steps: 512).mirror.look, depth: 1, divisor: 1
    with_fx :lpf, cutoff: (line 30, 120, steps: 1024).mirror.look do
    play (
      (scale :c3, :minor_pentatonic).drop_last + (ring :eb4, :r, :f4) +
      (scale :c3, :minor_pentatonic).drop_last + (ring :eb4, :r, :f4) +
      (scale :c3, :minor_pentatonic).drop_last + (ring :eb4, :r, :f4) +
      (scale :c3, :minor_pentatonic).drop_last + (ring :eb4, :r, :f4) +
      (scale :c3, :minor_pentatonic).drop_last + (ring :eb4, :r, :f4) +
      (scale :c3, :minor_pentatonic).drop_last + (ring :eb4, :r, :f4) +
      (scale :c3, :minor_pentatonic).drop_last + (ring :eb4, :r, :f4) +
      (ring :c4, :f4, :c4, :g4, :c4, :f4, :c4, :r) +
      (ring :c4, :f4, :c4, :bb4, :c4, :c5, :c4, :bb4)
      ).look
    end
    sleep 0.25
  end
end

Any ideas about that? Any hardware recommendations?

Cheers
Martin

I tried this on my macBookPro with 4-core intel i7 2.8GHz with 16Gb of ram and there weren’t any problems.
Looking at the activity monitor the processor is hardly taxed (90% idle or thereabouts) and no problems with memory pressure either. I suspect it is much more down to other factors one of which might be sound interface/latency.
I even tried a second instances of Sonic Pi running in a virtual Mac on the same machine at the same time, and that was happy too!

Hi Martin,

Ran this on my years-old (Dell T1500) PC running Win10 Pro. No problems, even with an online game in progress, etc.

Check your setups, I reckon.

Eli…

Hi @robin.newman, hi @Eli,

okay, thanks for checking. That’s good news and bad news. It’s bad because it then seems to be either my setup (no idea where to look) or my current SP version (I can check older ones) or the fact that I am running SP on Linux (also no idea where to look or what to do). Or a combination of these three factors.

@robin.newman + @Eli May i ask: With which version of SP were you testing?

I did check the example again with SP 3.1 (for the first run I used a developer version 3.2 from some months ago). It is better.

And could you kindly check two more things so that I have some ideas about what performance I should expect?

  1. What, if you put the reverb inside the loop? I do get quite a lot of xruns (at least with my internal soundcard; will have to check with my USB Audio device again):
use_bpm 180

live_loop :test do
  with_fx :reverb, room: 0.75, mix: 1 do
    use_synth :fm
    use_synth_defaults attack: (line 0.5, 0, steps: 256).mirror.tick,
      release: (line 2, 0.25, steps: 512).mirror.look,
      depth: (line 0.5, 2, steps: 512).mirror.look, divisor: 1
    with_fx :lpf, cutoff: (line 30, 120, steps: 1024).mirror.look do
      play (
        (scale :c3, :minor_pentatonic).drop_last + (ring :eb4, :r, :f4) +
        (scale :c3, :minor_pentatonic).drop_last + (ring :eb4, :r, :f4) +
        (scale :c3, :minor_pentatonic).drop_last + (ring :eb4, :r, :f4) +
        (scale :c3, :minor_pentatonic).drop_last + (ring :eb4, :r, :f4) +
        (scale :c3, :minor_pentatonic).drop_last + (ring :eb4, :r, :f4) +
        (scale :c3, :minor_pentatonic).drop_last + (ring :eb4, :r, :f4) +
        (scale :c3, :minor_pentatonic).drop_last + (ring :eb4, :r, :f4) +
        (ring :c4, :f4, :c4, :g4, :c4, :f4, :c4, :r) +
        (ring :c4, :f4, :c4, :bb4, :c4, :c5, :c4, :bb4)
      ).look
    end
    sleep 0.25
  end
end
  1. What about this:
use_bpm 180

with_fx :reverb, room: 0.75, mix: 1 do
 live_loop :test1 do
    
    use_synth :fm
    use_synth_defaults attack: (line 0.5, 0, steps: 256).mirror.tick,
      release: (line 2, 0.25, steps: 512).mirror.look,
      depth: (line 0.5, 2, steps: 512).mirror.look, divisor: 1
    with_fx :lpf, cutoff: (line 30, 120, steps: 1024).mirror.look do
      play (
        (scale :c3, :minor_pentatonic).drop_last + (ring :eb4, :r, :f4) +
        (scale :c3, :minor_pentatonic).drop_last + (ring :eb4, :r, :f4) +
        (scale :c3, :minor_pentatonic).drop_last + (ring :eb4, :r, :f4) +
        (scale :c3, :minor_pentatonic).drop_last + (ring :eb4, :r, :f4) +
        (scale :c3, :minor_pentatonic).drop_last + (ring :eb4, :r, :f4) +
        (scale :c3, :minor_pentatonic).drop_last + (ring :eb4, :r, :f4) +
        (scale :c3, :minor_pentatonic).drop_last + (ring :eb4, :r, :f4) +
        (ring :c4, :f4, :c4, :g4, :c4, :f4, :c4, :r) +
        (ring :c4, :f4, :c4, :bb4, :c4, :c5, :c4, :bb4)
      ).look
    end
    sleep 0.25
  end
  
  live_loop :test2 do
    
    use_synth :fm
    use_synth_defaults attack: (line 0.5, 0, steps: 256).mirror.tick,
      release: (line 2, 0.25, steps: 512).mirror.look,
      depth: (line 0.5, 2, steps: 512).mirror.look, divisor: 1
    sleep 0.25
    with_fx :hpf, cutoff: (line 120, 30, steps: 1024).mirror.look do
      play (
        (scale :c4, :minor_pentatonic).drop_last + (ring :eb5, :r, :f5) +
        (scale :c4, :minor_pentatonic).drop_last + (ring :eb5, :r, :f5) +
        (scale :c4, :minor_pentatonic).drop_last + (ring :eb5, :r, :f5) +
        (scale :c4, :minor_pentatonic).drop_last + (ring :eb5, :r, :f5) +
        (scale :c4, :minor_pentatonic).drop_last + (ring :eb5, :r, :f5) +
        (scale :c4, :minor_pentatonic).drop_last + (ring :eb5, :r, :f5) +
        (scale :c4, :minor_pentatonic).drop_last + (ring :eb5, :r, :f5) +
        (ring :c5, :f5, :c5, :g5, :c5, :f5, :c5, :r) +
        (ring :c5, :f5, :c5, :bb5, :c5, :c5, :c5, :bb5)
      ).look
    end
  end
  
end

Thanks a lot in case you have the time to check!

Martin

I’m on 3.1.0 … been quite unwell, so havent looked for upgrades.

Also why my Patreon has gone - cards expired whilst I was in hospital
and new ones delivered to home, of course.

Probably renew it… but the forums seem to have drifted (as the users
mature in their use of SP?) from posting code to much more technical
subjects such as OSC/Midi, etc… me, I’m still just an old code tinkerer…

Eli…

Oh, hope you are better now! I don’t really know if there was an official update, but as I am on Linux I have to compile it anyway. From time to time I check the developer versions. But this confirms the fact, that there seems to be a performance difference between 3.1.0 and my last compiled 3.2.x version.

Thanks a lot for testing!

Neither of your test loops gives any errors in 3.1.0.

I went further and ran both at once in the same buffer, and
still got no delays, messages or sound glitches.

Hope this helps.

Eli…

Oh… thanks. I am a bit confused. My laptop is not what you would call slow so I have no idea what to do. I suspect you are running Windows, right?

Hi Martin
Checked both these in 3.1 and 3.2dev Both worked fine on my Mac.

I would tend to suspect your internal audio card. When I run linux (Ubuntu) on an older machine here I get better performance with an external Steinberg UR22 MKII interface.
(incidentally, o build 3.1 just select the 3.1 release tag on github and build from that.

Oh and your examples above sound nice. Quite mesmerising!

Hi @robin.newman,

thanks again. Yes, I did check that with my internal card. I will also test with my Focusrite. That might also be an important factor. Still I suspect with what I am planning I will have to upgrade my system. I just want to find out if there are some systematic performance issues with Linux.

One more question, if you can answer that: So the time warning from SP is not just from processing the pure code but also from the fact that the soundcard can’t deliver the expected result (as opposed to possible xruns, which are also a sign of a lack of performance)?

And yeah, ‘mesmerising’ is an apt description. You’ll tend to hear more notes and different durations as actually have been coded.

I think that may be the case. Certainly when altering the settings in linux for jackd can affect this. Trade off between latency and breakup of the sound with xruns. With a better card you should find this is less of a problem.

My results are - no wonder - better with my Scarlett 2i2. I get occasional time warnings but I added some percussion stuff. I tend to use external plugins for reverb (e. g. Tal) as this seems to lessen the system load considerably. I also did increase Jack’s period setting from 2 to 6 which seem to work well (with a latency just above 10 ms). The funny thing is: All my processor are mostly under 20% and I have around 10 GB free RAM.

Neverthess I would like to have more (actually much more) ‘Max Headroom’ to go wild. Any hints to a systematic approach to find out what the bottleneck is? And if this is not about optimisation of my current system I guess I would primarily have to invest in processor power, right?

Not sure what to suggest for such an approach. However someone like @xavierriley who understands the inner working of Sonic Pi and scsynth better than I may be able to suggest any further bottleneck.

Thanks for your response Robin! I did some googling about Linux and audio some time ago. Seems to be a complex thing - allthough, this probably is not limited to Linux, once you are dealing with performance issues…

(E. g. the occurrance of xruns does not seem entirely to be related to processor use. Neither seem to be timing errors in SP. I guess, that is especially what puzzles me.)

Also of course, trying to keep fx calls outside liveloops where possible helps otherwise you eat up resources in Sonic Pi.

Yes, of course. I know that especially the reverb is eating much. Unless you want to stick to a pure approach (using just SP) the use of plugins (I made some good experiences with Carla and the available Open Source plugins) seems to be quite fruitful because you can change the sound during runtime.

Just in case anyone is interested:

Better results with Jack setting the ‘-S’ option, using realtimeconfigquickscan and subsequently making sure my laptop is on high performance mode as well as changing swapiness.