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.
This commit is contained in:
Oliver Hamlet
2022-12-12 11:22:17 +00:00
parent 02570b2063
commit 280a4aab66
2 changed files with 17 additions and 2 deletions
+15 -2
View File
@@ -309,6 +309,16 @@ std::optional<vertex_t> PluginGraph::GetVertexByName(
return std::nullopt;
}
std::optional<vertex_t> 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;
}
+2
View File
@@ -65,6 +65,7 @@ public:
size_t CountVertices() const;
std::pair<vertex_it, vertex_it> GetVertices() const;
std::optional<vertex_t> GetVertexByName(const std::string& name) const;
std::optional<vertex_t> 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<std::string, vertex_t> pluginNameVertexMap;
};
}