From 41550846f596427e5323536ba238bf444b6ad79d Mon Sep 17 00:00:00 2001 From: imilinovic Date: Mon, 10 Mar 2025 22:02:13 +0100 Subject: [PATCH 1/3] memory optimizations --- cpp/pagerank_module/algorithm/pagerank.cpp | 10 ++++++++++ cpp/pagerank_module/algorithm/pagerank.hpp | 2 ++ cpp/pagerank_module/pagerank_module.cpp | 2 ++ 3 files changed, 14 insertions(+) diff --git a/cpp/pagerank_module/algorithm/pagerank.cpp b/cpp/pagerank_module/algorithm/pagerank.cpp index a98eedf52..a6f4982ba 100644 --- a/cpp/pagerank_module/algorithm/pagerank.cpp +++ b/cpp/pagerank_module/algorithm/pagerank.cpp @@ -178,6 +178,16 @@ const std::vector &PageRankGraph::GetOrderedEdges() const { return ord std::uint64_t PageRankGraph::GetOutDegree(const std::uint64_t node_id) const { return out_degree_[node_id]; } +void PageRankGraph::ClearUnusedVectors() { + ordered_edges_.clear(); + out_degree_.clear(); + memgraph_to_id.clear(); + + ordered_edges_.shrink_to_fit(); + out_degree_.shrink_to_fit(); + id_to_memgraph.shrink_to_fit(); +} + std::vector ParallelIterativePageRank(const PageRankGraph &graph, std::size_t max_iterations, double damping_factor, double stop_epsilon, uint32_t number_of_threads) { number_of_threads = std::min(number_of_threads, std::thread::hardware_concurrency()); diff --git a/cpp/pagerank_module/algorithm/pagerank.hpp b/cpp/pagerank_module/algorithm/pagerank.hpp index 1b4dd85c1..eb38e6b05 100644 --- a/cpp/pagerank_module/algorithm/pagerank.hpp +++ b/cpp/pagerank_module/algorithm/pagerank.hpp @@ -47,6 +47,8 @@ class PageRankGraph { /// @return -- out degree of node node_id std::uint64_t GetOutDegree(std::uint64_t node_id) const; + void ClearUnusedVectors(); + private: /// node_count equals number of nodes in graph std::uint64_t node_count_; diff --git a/cpp/pagerank_module/pagerank_module.cpp b/cpp/pagerank_module/pagerank_module.cpp index feb8ee04f..829298b3d 100644 --- a/cpp/pagerank_module/pagerank_module.cpp +++ b/cpp/pagerank_module/pagerank_module.cpp @@ -90,6 +90,8 @@ void PagerankWrapper(mgp_list *args, mgp_graph *memgraph_graph, mgp_result *resu auto pageranks = pagerank_alg::ParallelIterativePageRank(pagerank_graph, max_iterations, damping_factor, stop_epsilon, num_threads); + pagerank_graph.ClearUnusedVectors(); + mgp_result_reserve(result, pagerank_graph.GetNodeCount()); for (std::uint64_t node_id = 0; node_id < pagerank_graph.GetNodeCount(); ++node_id) { InsertPagerankRecord(memgraph_graph, result, memory, pagerank_graph.GetMemgraphNodeId(node_id), pageranks[node_id]); From 2ea30943b7e823cf788c534aa1bb91f057b1ab4b Mon Sep 17 00:00:00 2001 From: imilinovic Date: Mon, 14 Apr 2025 10:01:47 +0200 Subject: [PATCH 2/3] fix --- cpp/pagerank_module/algorithm/pagerank.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/cpp/pagerank_module/algorithm/pagerank.cpp b/cpp/pagerank_module/algorithm/pagerank.cpp index a6f4982ba..f1565666c 100644 --- a/cpp/pagerank_module/algorithm/pagerank.cpp +++ b/cpp/pagerank_module/algorithm/pagerank.cpp @@ -3,6 +3,7 @@ #include #include #include +#include namespace pagerank_alg { @@ -182,10 +183,10 @@ void PageRankGraph::ClearUnusedVectors() { ordered_edges_.clear(); out_degree_.clear(); memgraph_to_id.clear(); + memgraph_to_id = std::unordered_map{}; ordered_edges_.shrink_to_fit(); out_degree_.shrink_to_fit(); - id_to_memgraph.shrink_to_fit(); } std::vector ParallelIterativePageRank(const PageRankGraph &graph, std::size_t max_iterations, From b4f47921b874b5870712905fc007399903268428 Mon Sep 17 00:00:00 2001 From: imilinovic Date: Thu, 17 Apr 2025 16:52:02 +0200 Subject: [PATCH 3/3] change submodule to v3.2.0 rc --- cpp/memgraph | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cpp/memgraph b/cpp/memgraph index f76cd1c93..974f9217c 160000 --- a/cpp/memgraph +++ b/cpp/memgraph @@ -1 +1 @@ -Subproject commit f76cd1c93055bde76ee1938524503af5cb4340fd +Subproject commit 974f9217c72c69fff358c9c3ef692447fd89ea9b