@@ -177,6 +177,8 @@ class Cluster
177177 void Clear (TxGraphImpl& graph, int level) noexcept ;
178178 /* * Change a Cluster's level from 1 (staging) to 0 (main). */
179179 void MoveToMain (TxGraphImpl& graph) noexcept ;
180+ /* * Minimize this Cluster's memory usage. */
181+ void Compact () noexcept ;
180182
181183 // Functions that implement the Cluster-specific side of internal TxGraphImpl mutations.
182184
@@ -910,6 +912,7 @@ void Cluster::ApplyRemovals(TxGraphImpl& graph, int level, std::span<GraphIndex>
910912 [&](auto pos) { return todo[pos]; }), m_linearization.end ());
911913 quality = QualityLevel::NEEDS_SPLIT;
912914 }
915+ Compact ();
913916 graph.SetClusterQuality (level, m_quality, m_setindex, quality);
914917 Updated (graph, level);
915918}
@@ -937,6 +940,13 @@ void Cluster::MoveToMain(TxGraphImpl& graph) noexcept
937940 Updated (graph, /* level=*/ 0 );
938941}
939942
943+ void Cluster::Compact () noexcept
944+ {
945+ m_linearization.shrink_to_fit ();
946+ m_mapping.shrink_to_fit ();
947+ m_depgraph.Compact ();
948+ }
949+
940950void Cluster::AppendChunkFeerates (std::vector<FeeFrac>& ret) const noexcept
941951{
942952 auto chunk_feerates = ChunkLinearization (m_depgraph, m_linearization);
@@ -1050,6 +1060,7 @@ bool Cluster::Split(TxGraphImpl& graph, int level) noexcept
10501060 // Update all the Locators of moved transactions.
10511061 for (Cluster* new_cluster : new_clusters) {
10521062 new_cluster->Updated (graph, level);
1063+ new_cluster->Compact ();
10531064 }
10541065 // Wipe this Cluster, and return that it needs to be deleted.
10551066 m_depgraph = DepGraph<SetType>{};
@@ -1627,6 +1638,7 @@ void TxGraphImpl::Merge(std::span<Cluster*> to_merge, int level) noexcept
16271638 to_merge[0 ]->Merge (*this , level, *to_merge[i]);
16281639 DeleteCluster (*to_merge[i], level);
16291640 }
1641+ to_merge[0 ]->Compact ();
16301642}
16311643
16321644void TxGraphImpl::ApplyDependencies (int level) noexcept
0 commit comments