mirror of
https://github.com/robbert-vdh/yabridge.git
synced 2026-05-15 13:00:02 +02:00
💥 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:
@@ -1235,8 +1235,18 @@ size_t Vst3Bridge::register_object_instance(
|
||||
return object_instances[request.instance_id]
|
||||
.audio_processor->setProcessing(request.state);
|
||||
},
|
||||
[&](YaAudioProcessor::Process& request)
|
||||
[&](MessageReference<YaAudioProcessor::Process>&
|
||||
request_ref)
|
||||
-> YaAudioProcessor::Process::Response {
|
||||
// NOTE: To prevent allocations we keep this actual
|
||||
// `YaAudioProcessor::Process` object around as
|
||||
// part of a static thread local
|
||||
// `AudioProcessorRequest` object, and we only
|
||||
// store a reference to it in our variant (this is
|
||||
// done during the deserialization in
|
||||
// `bitsery::ext::MessageReference`)
|
||||
YaAudioProcessor::Process& request = request_ref.get();
|
||||
|
||||
// Most plugins will already enable FTZ, but there are a
|
||||
// handful of plugins that don't that suffer from
|
||||
// extreme DSP load increases when they start producing
|
||||
@@ -1251,6 +1261,9 @@ size_t Vst3Bridge::register_object_instance(
|
||||
true, *request.new_realtime_priority);
|
||||
}
|
||||
|
||||
// TODO: This `get()` now moves data. We should avoid
|
||||
// that, since that would require reallocating the
|
||||
// process data next iteration.
|
||||
const tresult result =
|
||||
object_instances[request.instance_id]
|
||||
.audio_processor->process(request.data.get());
|
||||
|
||||
Reference in New Issue
Block a user