surge-synthesizer / shortcircuit-xt

Will be a sampler when its done!
GNU General Public License v3.0
258 stars 31 forks source link

Dont process unused busses #1223

Open baconpaul opened 2 months ago

baconpaul commented 2 months ago

currently busses do things like downsample and send to effects and stuff and if you look in Patch::process you can see we do it for all of them. This is part of why we have 3% CPU usage in an idle release run.

So

  1. If no part group or zone routes to a bus or
  2. If no mixer channel sends to an aux
  3. Don't process it

is an obvious optimization

baconpaul commented 2 months ago

Harumpy

I trued this naive diff

diff --git a/src/engine/patch.cpp b/src/engine/patch.cpp
index 3fa7b8d..b38dfbc 100644
--- a/src/engine/patch.cpp
+++ b/src/engine/patch.cpp
@@ -50,6 +50,9 @@ void Patch::process(Engine &e)
         }
     }

+    std::array<bool, numAux> sentToAux{};
+    std::fill(sentToAux.begin(), sentToAux.end(), false);
+
     for (auto &b : busses.partBusses)
     {
         b.process();
@@ -59,6 +62,7 @@ void Patch::process(Engine &e)
             {
                 if (b.busSendStorage.sendLevels[i] != 0.f)
                 {
+                    sentToAux[i] = true;
                     switch (b.busSendStorage.auxLocation[i])
                     {
:
@@ -50,6 +50,9 @@ void Patch::process(Engine &e)
         }
     }

+    std::array<bool, numAux> sentToAux{};
+    std::fill(sentToAux.begin(), sentToAux.end(), false);
+
     for (auto &b : busses.partBusses)
     {
         b.process();
@@ -59,6 +62,7 @@ void Patch::process(Engine &e)
             {
                 if (b.busSendStorage.sendLevels[i] != 0.f)
                 {
+                    sentToAux[i] = true;
                     switch (b.busSendStorage.auxLocation[i])
                     {
                     case Bus::BusSendStorage::PRE_FX:
@@ -86,9 +90,13 @@ void Patch::process(Engine &e)
     }

     // Process my send busses
-    for (auto &b : busses.auxBusses)
-        b.process();
-
+    for (auto i = 0; i < numAux; ++i)
+    {
+        if (sentToAux[i])
+        {
+            busses.auxBusses[i].process();
+        }
+    }
     // TODO - we can be more parsimonious here if we don't use these
     memset(busses.pluginNonMainOutputs, 0, sizeof(busses.pluginNonMainOutputs));

and it worked until I turned an aux back to zero

so really this needs to be a feature of the bus ("everActive") and aux need tail support and the like.