From 78f6921cd8f85dd277742b191b551383ee9cff7f Mon Sep 17 00:00:00 2001 From: Robbert van der Helm Date: Fri, 11 Jun 2021 14:57:01 +0200 Subject: [PATCH] Also use hashsets for the VST2 opcode dispatch Should barely make a difference, but it should be as fast or faster. --- CHANGELOG.md | 1 + src/wine-host/bridges/vst2.cpp | 11 ++++++----- src/wine-host/utils.cpp | 2 +- src/wine-host/utils.h | 8 ++++---- 4 files changed, 12 insertions(+), 10 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index dcf7c7df..4ecc4d45 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -16,6 +16,7 @@ Versioning](https://semver.org/spec/v2.0.0.html). during audio processing should now be about as low as it's going to get. - Optimized the management of VST3 plugin instances to reduce the overhead when using many instances of a VST3 plugin. +- Slightly optimized the function call dispatch for VST2 plugins. - Prevented some more potential unnecessary memory operations during yabridge's communication. The underlying serialization library was recreating some objects even when that wasn't needed, which could in theory result in memory diff --git a/src/wine-host/bridges/vst2.cpp b/src/wine-host/bridges/vst2.cpp index 181cab39..cd50c64e 100644 --- a/src/wine-host/bridges/vst2.cpp +++ b/src/wine-host/bridges/vst2.cpp @@ -64,7 +64,7 @@ Vst2Bridge* current_bridge_instance = nullptr; * `audioMasterUpdateDisplay()`, and PG-8X also requires that to be called * from the same thread that called `audioMasterUpdateDisplay()`. */ -static const std::set mutually_recursive_callbacks{ +static const std::unordered_set mutually_recursive_callbacks{ audioMasterUpdateDisplay}; /** @@ -78,8 +78,8 @@ static const std::set mutually_recursive_callbacks{ * just execute the function directly on the calling thread. See above for a * list of situations where this may be necessary. */ -static const std::set safe_mutually_recursive_requests{effGetProgram, - effGetProgramName}; +static const std::unordered_set safe_mutually_recursive_requests{ + effGetProgram, effGetProgramName}; /** * Opcodes that should always be handled on the main thread because they may @@ -92,7 +92,7 @@ static const std::set safe_mutually_recursive_requests{effGetProgram, * Algonaut Atlas doesn't restore chunk data unless `effSetChunk` is run * from the GUI thread */ -static const std::set unsafe_requests{ +static const std::unordered_set unsafe_requests{ effOpen, effClose, effEditGetRect, effEditOpen, effEditClose, effEditIdle, effEditTop, effMainsChanged, effGetChunk, effSetChunk}; @@ -103,7 +103,8 @@ static const std::set unsafe_requests{ * implement thread priorities. Normally these unsafe requests are run on the * main thread, which doesn't use realtime scheduling. */ -static const std::set unsafe_requests_realtime{effOpen, effMainsChanged}; +static const std::unordered_set unsafe_requests_realtime{effOpen, + effMainsChanged}; intptr_t VST_CALL_CONV host_callback_proxy(AEffect*, int, int, intptr_t, void*, float); diff --git a/src/wine-host/utils.cpp b/src/wine-host/utils.cpp index 78cb4d0c..dc6dd5b8 100644 --- a/src/wine-host/utils.cpp +++ b/src/wine-host/utils.cpp @@ -108,7 +108,7 @@ void MainContext::update_timer_interval( MainContext::WatchdogGuard::WatchdogGuard( HostBridge& bridge, - std::set& watched_bridges, + std::unordered_set& watched_bridges, std::mutex& watched_bridges_mutex) : bridge(&bridge), watched_bridges(watched_bridges), diff --git a/src/wine-host/utils.h b/src/wine-host/utils.h index 81254dd7..803d7699 100644 --- a/src/wine-host/utils.h +++ b/src/wine-host/utils.h @@ -21,7 +21,7 @@ #include #include #include -#include +#include #include #include @@ -195,7 +195,7 @@ class MainContext { class WatchdogGuard { public: WatchdogGuard(HostBridge& bridge, - std::set& watched_bridges, + std::unordered_set& watched_bridges, std::mutex& watched_bridges_mutex); ~WatchdogGuard() noexcept; @@ -220,7 +220,7 @@ class MainContext { // References to the same two fields on `MainContext`, so we don't have // to use `friend` - std::reference_wrapper> watched_bridges; + std::reference_wrapper> watched_bridges; std::reference_wrapper watched_bridges_mutex; }; @@ -349,7 +349,7 @@ class MainContext { * pointers for efficiency's sake, since reference wrappers don't implement * any comparison operators. */ - std::set watched_bridges; + std::unordered_set watched_bridges; std::mutex watched_bridges_mutex; /**