💥 Reduce allocations in VST3 audio sockets

We do this by using this new `MessageReference<T>` type to avoid copying
our `YaAudioProcessor::Process` struct and the contained `YaProcessData`
object. This is only part of the work, but this redesign lets us keep
the these objects alive on both the plugin and the host side. On the
plugin side, we'll simply serialize the data from the referred to object
without copying it. On the Wine side, we'll write the data to a
persistent thread local object, and then reassign the
`MessageReference<T>` to point to that object. This lets us serialize
'references', thus avoiding potentially expensive allocations. With
these last few changes alone VST3 plugins are already at the same
performance level as our optimized VST2 plugin groups.
This commit is contained in:
Robbert van der Helm
2021-05-07 16:32:08 +02:00
parent d08ec70f2c
commit fcaac219a6
9 changed files with 159 additions and 38 deletions
+22 -2
View File
@@ -237,7 +237,12 @@ class Vst3MessageHandler : public AdHocSocketHandler<Thread> {
auto [logger, is_host_vst] = *logging;
return logger.log_request(is_host_vst, object);
},
request);
// In the case of `AudioProcessorRequest`, we need to
// actually fetch the variant field since our object
// also contains a persistent object to store process
// data into so we can prevent allocations during audio
// processing
get_request_variant(request));
}
// We do the visiting here using a templated lambda. This way we
@@ -258,7 +263,8 @@ class Vst3MessageHandler : public AdHocSocketHandler<Thread> {
write_object(socket, response);
}
},
request);
// See above
get_request_variant(request));
};
this->receive_multi(logging
@@ -442,6 +448,20 @@ class Vst3Sockets : public Sockets {
audio_processor_buffers.at(object.instance_id));
}
/**
* Overload for use with `MessageReference<T>`, since we cannot
* directly get the instance ID there.
*/
template <typename T>
typename T::Response send_audio_processor_message(
const MessageReference<T>& object_ref,
std::optional<std::pair<Vst3Logger&, bool>> logging) {
return audio_processor_sockets.at(object_ref.get().instance_id)
.send_message(
object_ref, logging,
audio_processor_buffers.at(object_ref.get().instance_id));
}
/**
* For sending messages from the host to the plugin. After we have a better
* idea of what our communication model looks like we'll probably want to