swesterfeld/liquidsfz

Use of local functions (lambdas) in Voice::process

Opened this issue · 1 comments

Hi, I looked through your code and saw this:

auto get_samples_mono = [csample, this] (uint x, auto& fsamples)

Have you investigated how for instance gcc or clang treats this code? Because the code is very nice, and if compilers can guarantee that everything is inlined (and no heap allocations occur), I'll probably start using local lambdas too in realtime critical code.

As far as I know, a lambda like this is not much more than a class with a few data members (captured variables) and one single method that is called when the lambda is called, so the compiler should inline it as far as I know. But I didn't do systematic benchmarking. So if you do and have results I'd be interested to hear what you found.

Also note that this is not the final optimized variant. To produce a final optimized variant all features must be there, and this code is only doing linear interpolation where it should do higher order sinc interpolation. So although I measured that this isn't slow, full optimization will have to wait until sinc interpolation is implemented.