From a28b73517f1a484c575576402790bdbfa9eb12c1 Mon Sep 17 00:00:00 2001 From: Oliver Hamlet Date: Fri, 17 Jan 2025 17:54:21 +0000 Subject: [PATCH] Use boost::unordered_flat_* for sorting paths cache This improves sorting performance by 31%. --- src/api/sorting/plugin_graph.cpp | 17 ++++++++--------- src/api/sorting/plugin_graph.h | 5 ++++- 2 files changed, 12 insertions(+), 10 deletions(-) diff --git a/src/api/sorting/plugin_graph.cpp b/src/api/sorting/plugin_graph.cpp index 12b44165..2f452047 100644 --- a/src/api/sorting/plugin_graph.cpp +++ b/src/api/sorting/plugin_graph.cpp @@ -28,7 +28,6 @@ #include #include #include -#include #include #include "api/helpers/logging.h" @@ -571,23 +570,23 @@ int ComparePlugins(const PluginSortingData& plugin1, bool PathsCache::IsPathCached(const vertex_t& fromVertex, const vertex_t& toVertex) const { - const auto descendents = pathsCache_.find(fromVertex); + const auto descendants = pathsCache_.find(fromVertex); - if (descendents == pathsCache_.end()) { + if (descendants == pathsCache_.end()) { return false; } - return descendents->second.count(toVertex); + return descendants->second.contains(toVertex); } void PathsCache::CachePath(const vertex_t& fromVertex, const vertex_t& toVertex) { - auto descendents = pathsCache_.find(fromVertex); + const auto descendants = pathsCache_.find(fromVertex); - if (descendents == pathsCache_.end()) { - pathsCache_.emplace(fromVertex, std::unordered_set({toVertex})); + if (descendants == pathsCache_.end()) { + pathsCache_.emplace(fromVertex, boost::unordered_flat_set{toVertex}); } else { - descendents->second.insert(toVertex); + descendants->second.emplace(toVertex); } } @@ -619,7 +618,7 @@ std::optional PluginGraph::GetVertexByName( auto& wideVertexName = wideStringCache_.GetOrInsert(GetPlugin(vertex).GetName()); auto& wideName = wideStringCache_.GetOrInsert(name); - + int comparison = CompareFilenames(wideVertexName, wideName); #else int comparison = CompareFilenames(GetPlugin(vertex).GetName(), name); diff --git a/src/api/sorting/plugin_graph.h b/src/api/sorting/plugin_graph.h index 71930992..da1dc6a7 100644 --- a/src/api/sorting/plugin_graph.h +++ b/src/api/sorting/plugin_graph.h @@ -27,6 +27,8 @@ #include #include +#include +#include #include #include "api/sorting/group_sort.h" @@ -52,7 +54,8 @@ public: void CachePath(const vertex_t& fromVertex, const vertex_t& toVertex); private: - std::unordered_map> pathsCache_; + boost::unordered_flat_map> + pathsCache_; }; #if _WIN32