faust icon indicating copy to clipboard operation
faust copied to clipboard

Scalar variables for 1-sample delay lines

Open mikeoliphant opened this issue 4 years ago • 19 comments

Because single-sample feedback is so common, Faust often generates a lot of 2-value arrays for feedback handling.

This ends up being quite expensive in languages like C# where array access has more overhead than C++.

It would be great if the compiler could instead generate a pair of scalar variables for the single-sample delay case.

ie: instead of:

double[] fRec9 = new double[2];

it would generate something like:

double fRec9_0; double fRec9_1

In C#, this simple change can result in massive performance increases for very typical Faust use cases. It doesn't seem to make much of a difference for C++, but it may help other backends.

mikeoliphant avatar Mar 23 '21 21:03 mikeoliphant

Yes indeed. Yann is currently working on a whole new infrastructure in the compiler that will (in particular but even some more improvements ...) allow to solve this kind of issues. See Yann IFC 2020 presentation: https://ifc20.sciencesconf.org and https://www.youtube.com/watch?v=vb7LU7ue5hk.

sletz avatar Mar 24 '21 09:03 sletz

Great - I look forward to the new compiler!

mikeoliphant avatar Mar 24 '21 15:03 mikeoliphant

@mikeoliphant could not find another way to contact you ! Do you have a small presentation text of the use-case for your contributed C# backend in Faust ?

sletz avatar Jun 01 '22 08:06 sletz

Hi @sletz - my main use case was simply to be able to generate plugins in C# rather than having to use C#/C++ interop (which isn't difficult, but is unpleasant and make for more complicated project structure). I also am using the ability of the C# compiler to do dynamic assembly generation from Faust code. One goal of this would be to have runtime editing of Faust code within a VST inside a DAW (something I've experimented with, but haven't had time to fully explore).

mikeoliphant avatar Jun 01 '22 15:06 mikeoliphant

Thanks. How do you do use the C# compiler to do dynamic assembly generation from Faust code ?

sletz avatar Jun 01 '22 15:06 sletz

Right now, I spawn off Faust to generate the C# code (although it could be integrated more tightly by compiling in the Faust libs). Once I have C# source code, the .NET compiler system can be invoked at runtime to create an in-memory assembly that can be used just like any other. I don't know much about LLVM, but I assume it is similar.

mikeoliphant avatar Jun 01 '22 15:06 mikeoliphant

OK thanks, yes using LLVM backend, we do DSP ==> LLVM IR ==> JIT ==> executable code in memory.

sletz avatar Jun 01 '22 15:06 sletz