From 280a4aab6661604f1236f7cc4d0b1833a2e68e05 Mon Sep 17 00:00:00 2001 From: Oliver Hamlet Date: Mon, 12 Dec 2022 09:37:53 +0000 Subject: [PATCH] Improve performance of adding group edges This reduced the time taken when using a very large userlist (featuring 11 group definitions and 1287 group assignments) and 1619 plugins from 332 seconds to 34 seconds. Without the large userlist, the time taken went from 17 seconds to 1.8 seconds. --- src/api/sorting/plugin_graph.cpp | 17 +++++++++++++++-- src/api/sorting/plugin_graph.h | 2 ++ 2 files changed, 17 insertions(+), 2 deletions(-) diff --git a/src/api/sorting/plugin_graph.cpp b/src/api/sorting/plugin_graph.cpp index a5b18d37..72fe2c78 100644 --- a/src/api/sorting/plugin_graph.cpp +++ b/src/api/sorting/plugin_graph.cpp @@ -309,6 +309,16 @@ std::optional PluginGraph::GetVertexByName( return std::nullopt; } +std::optional PluginGraph::GetVertexByExactName( + const std::string& name) const { + const auto it = pluginNameVertexMap.find(name); + if (it != pluginNameVertexMap.end()) { + return it->second; + } + + return std::nullopt; +} + const PluginSortingData& PluginGraph::GetPlugin(const vertex_t& vertex) const { return graph_[vertex]; } @@ -441,7 +451,8 @@ void PluginGraph::AddEdge(const vertex_t& fromVertex, } void PluginGraph::AddVertex(const PluginSortingData& plugin) { - boost::add_vertex(plugin, graph_); + const auto vertex = boost::add_vertex(plugin, graph_); + pluginNameVertexMap.emplace(plugin.GetName(), vertex); } void PluginGraph::AddPluginVertices(const Game& game, @@ -669,7 +680,9 @@ void PluginGraph::AddGroupEdges( const auto& toPlugin = GetPlugin(vertex); for (const auto& pluginName : toPlugin.GetAfterGroupPlugins()) { - const auto parentVertex = GetVertexByName(pluginName); + // After group plugin names are taken from other PluginSortingData names, + // so exact string comparisons can be used. + const auto parentVertex = GetVertexByExactName(pluginName); if (!parentVertex.has_value()) { continue; } diff --git a/src/api/sorting/plugin_graph.h b/src/api/sorting/plugin_graph.h index 81865add..631ca662 100644 --- a/src/api/sorting/plugin_graph.h +++ b/src/api/sorting/plugin_graph.h @@ -65,6 +65,7 @@ public: size_t CountVertices() const; std::pair GetVertices() const; std::optional GetVertexByName(const std::string& name) const; + std::optional GetVertexByExactName(const std::string& name) const; const PluginSortingData& GetPlugin(const vertex_t& vertex) const; @@ -97,6 +98,7 @@ public: private: RawPluginGraph graph_; PathsCache pathsCache_; + std::map pluginNameVertexMap; }; }