EngineInPlugin - Memory allocations in audio thread

Hi,
I am trying to build a plugin based on EngineInPlugin demo and was facing performance issues. When I investigated memory allocations I found that tracktion allocates memory on every call to processBlock. I built the latest version of the demo plugin (develop branch) and got the same results there.
The issue seems to be realted to an allocation of a vector of Nodes (see attached screenshot with call stack).
I’m sure this is not supposed to be called on every processBlock and there’s some configuration that will solve it. Also, I tested it in different hosts and got the same result.

Will appreciate your help with that!

Hmm, that shouldn’t be the case. I’ll take a look asap!

I had a quick look and this only happens in debug builds:

inline void Node::prepareForNextBlock (juce::Range<int64_t> referenceSampleRange)
{
    // Only do this once as prepare may be called multiple times
    if (retainCount == 0)
    {
        assert (directInputNodes.size() == getDirectInputNodes().size());

I think I’ll just delete the check though as it’s not really thread-safe to call it there.

1 Like

Thanks for the speedy response! I don’t see allocations anymore but unfortunalty I’m still struggling to build my project with tracktion engine v3 so I can’t see if the performance issue is gone :sweat_smile:

Can you let me know what the specific problems are?

Thanks for following up! It was a matter of defining c++ 20 instead of default (probably was 17…).

1 Like

@dave96 Now I see memory allocation coming from the built in sampler plugin, which allocates new SampledNote every time. Is that some misuse of that plugin?
Anyway, it is not the main thing so I understand if I have to implement it differently for use in EngineInPlugin.

Good point… That sample code is probably over 20 years old and not something we actually use in Waveform anymore. It’s more like demo code these days.

Looking at the code though, there doesn’t seem to be any reason why these can’t just be created in place. I’ll try and take a look at some point. I’ve logged it here: [Bug]: SamplerPlugin allocates SampledNotes · Issue #223 · Tracktion/tracktion_engine · GitHub

Thanks for opening a bug for it!
I’ll have a go at fixing it myself later this week and if I’ll be confident enough I’ll create a pull request too.

BTW, I had no idea that tracktion is 20 years old :sweat_smile:

Tracktion Engine is only a few years old but Tracktion the DAW is nearly 25 years old now. 2000 or 2001 I think the first version was.

I also just had a quick look at this and seems like it will be harder than expected as the LagrangeInterpolator isn’t copyable or movable. We might have to use a trick like a std::shared_ptr (and a pointer for the AudioBuffer reference).