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.
This commit is contained in:
Robbert van der Helm
2021-05-22 23:38:31 +02:00
parent 90338abe6d
commit da8f4aae19
4 changed files with 15 additions and 6 deletions
+5 -3
View File
@@ -16,9 +16,10 @@
#pragma once
#include "../../bitsery/ext/in-place-variant.h"
#include <pluginterfaces/vst/ivstevents.h>
#include <boost/container/small_vector.hpp>
#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<YaEvent> events;
boost::container::small_vector<YaEvent, 32> 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<Steinberg::Vst::Event> reconstructed_events;
boost::container::small_vector<Steinberg::Vst::Event, 32>
reconstructed_events;
};
#pragma GCC diagnostic pop
@@ -16,9 +16,10 @@
#pragma once
#include <bitsery/traits/vector.h>
#include <pluginterfaces/vst/ivstparameterchanges.h>
#include <boost/container/small_vector.hpp>
#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<std::pair<int32, Steinberg::Vst::ParamValue>> queue;
boost::container::small_vector<std::pair<int32, Steinberg::Vst::ParamValue>,
16>
queue;
};
#pragma GCC diagnostic pop
@@ -17,7 +17,9 @@
#pragma once
#include <pluginterfaces/vst/ivstparameterchanges.h>
#include <boost/container/small_vector.hpp>
#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<YaParamValueQueue> queues;
boost::container::small_vector<YaParamValueQueue, 16> queues;
};
#pragma GCC diagnostic pop