From da8f4aae19e757b8701c5fe14fc0e3f2f5284830 Mon Sep 17 00:00:00 2001 From: Robbert van der Helm Date: Sat, 22 May 2021 23:38:31 +0200 Subject: [PATCH] Preallocate small vectors for VST3 queues Events, parameter changes, and the individual queues contained within the parameter changes all use dynamic memory allocation. Preallocating some memory for those things inside of the objects may prevent latency spikes when they those objects are first filled. This is especially useful for the parameter changes since there's no way to reserve memory in a vector of vectors. --- CHANGELOG.md | 2 ++ src/common/serialization/vst3/event-list.h | 8 +++++--- src/common/serialization/vst3/param-value-queue.h | 7 +++++-- src/common/serialization/vst3/parameter-changes.h | 4 +++- 4 files changed, 15 insertions(+), 6 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index a8640f46..88d92038 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -36,6 +36,8 @@ Versioning](https://semver.org/spec/v2.0.0.html). unions yabridge uses to differentiate between single and double precision floating point audio buffers, undoing all of our efforts at reusing objects and preventing memory allocations in the process. +- Further optimized VST3 audio processing by preallocating small vectors for + event and parameter change queues. - Changed the way mutual recursion in VST3 plugins on the plugin side works to counter any potential GUI related timing issues with VST3 plugins. - The deserialization part of yabridge's communication is now slightly faster by diff --git a/src/common/serialization/vst3/event-list.h b/src/common/serialization/vst3/event-list.h index c0eb8cfb..8f8c2520 100644 --- a/src/common/serialization/vst3/event-list.h +++ b/src/common/serialization/vst3/event-list.h @@ -16,9 +16,10 @@ #pragma once -#include "../../bitsery/ext/in-place-variant.h" #include +#include +#include "../../bitsery/ext/in-place-variant.h" #include "base.h" #pragma GCC diagnostic push @@ -259,13 +260,14 @@ class YaEventList : public Steinberg::Vst::IEventList { } private: - std::vector events; + boost::container::small_vector events; /** * On the first `getEvent()` call we'll reconstruct these from `events` all * at once. These event objects may not outlive this event list. */ - std::vector reconstructed_events; + boost::container::small_vector + reconstructed_events; }; #pragma GCC diagnostic pop diff --git a/src/common/serialization/vst3/param-value-queue.h b/src/common/serialization/vst3/param-value-queue.h index 2521ba17..8243bcbe 100644 --- a/src/common/serialization/vst3/param-value-queue.h +++ b/src/common/serialization/vst3/param-value-queue.h @@ -16,9 +16,10 @@ #pragma once -#include #include +#include +#include "../../bitsery/traits/small-vector.h" #include "base.h" #pragma GCC diagnostic push @@ -95,7 +96,9 @@ class YaParamValueQueue : public Steinberg::Vst::IParamValueQueue { * * This contains pairs of `(sample_offset, value)`. */ - std::vector> queue; + boost::container::small_vector, + 16> + queue; }; #pragma GCC diagnostic pop diff --git a/src/common/serialization/vst3/parameter-changes.h b/src/common/serialization/vst3/parameter-changes.h index 43800ce8..dd3e2ce2 100644 --- a/src/common/serialization/vst3/parameter-changes.h +++ b/src/common/serialization/vst3/parameter-changes.h @@ -17,7 +17,9 @@ #pragma once #include +#include +#include "../../bitsery/traits/small-vector.h" #include "base.h" #include "param-value-queue.h" @@ -83,7 +85,7 @@ class YaParameterChanges : public Steinberg::Vst::IParameterChanges { /** * The parameter value changes queues. */ - std::vector queues; + boost::container::small_vector queues; }; #pragma GCC diagnostic pop