Use boost::unordered_flat_* for sorting paths cache

This improves sorting performance by 31%.
This commit is contained in:
Oliver Hamlet
2025-01-17 20:18:34 +00:00
parent bc8701a7ba
commit a28b73517f
2 changed files with 12 additions and 10 deletions
+8 -9
View File
@@ -28,7 +28,6 @@
#include <boost/graph/breadth_first_search.hpp>
#include <boost/graph/iteration_macros.hpp>
#include <boost/graph/topological_sort.hpp>
#include <boost/unordered/unordered_flat_set.hpp>
#include <queue>
#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<vertex_t>({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<vertex_t> 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);
+4 -1
View File
@@ -27,6 +27,8 @@
#include <boost/graph/adjacency_list.hpp>
#include <boost/graph/graph_traits.hpp>
#include <boost/unordered/unordered_flat_map.hpp>
#include <boost/unordered/unordered_flat_set.hpp>
#include <map>
#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<vertex_t, std::unordered_set<vertex_t>> pathsCache_;
boost::unordered_flat_map<vertex_t, boost::unordered_flat_set<vertex_t>>
pathsCache_;
};
#if _WIN32