💥 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
@@ -216,13 +216,12 @@ Vst3PluginProxyImpl::process(Steinberg::Vst::ProcessData& data) {
}
// We reuse this existing object to avoid allocations
process_data.repopulate(data);
process_request.instance_id = instance_id();
process_request.data.repopulate(data);
process_request.new_realtime_priority = new_realtime_priority;
ProcessResponse response =
bridge.send_audio_processor_message(YaAudioProcessor::Process{
.instance_id = instance_id(),
.data = process_data,
.new_realtime_priority = new_realtime_priority});
ProcessResponse response = bridge.send_audio_processor_message(
MessageReference<YaAudioProcessor::Process>(process_request));
response.output_data.write_back_outputs(data);
+9 -3
View File
@@ -478,10 +478,16 @@ class Vst3PluginProxyImpl : public Vst3PluginProxy {
std::atomic_size_t current_context_menu_id;
/**
* We'll reuse this process data object and simply fill the objects
* contained with new data to avoid allocations during audio processing.
* NOTE: We'll reuse the request objects for the audio processor so we can
* keep the process data object (which contains vectors and other heap
* allocated data structure) alive. We'll then just fill this object
* with new data every processing cycle to prevent allocations. Then,
* we pass a `MessageReference<YaAudioProcessor::Process>` to our
* sockets. This together with `bitisery::ext::MessageReference` will
* let us serialize from and to existing objects without having to
* copy or reallocate them.
*/
YaProcessData process_data;
YaAudioProcessor::Process process_request;
// Caches