From da5644211fe0f2a52220075337596a4489a34334 Mon Sep 17 00:00:00 2001 From: Wilson Snyder Date: Wed, 3 Nov 2021 22:01:27 -0400 Subject: [PATCH] Improve memory usage of V3Partition. Only performance change intended. --- src/V3Partition.cpp | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/src/V3Partition.cpp b/src/V3Partition.cpp index d7290319a..5d67b2fb0 100644 --- a/src/V3Partition.cpp +++ b/src/V3Partition.cpp @@ -705,8 +705,11 @@ public: // Information associated with scoreboarding an MTask class MergeCandidate VL_NOT_FINAL { private: - bool m_removedFromSb = false; // Not on scoreboard, generally ignore - vluint64_t m_id; // Serial number for ordering + // This structure is extremely hot. To save 8 bytes we pack + // one bit indicating removedFromSb with the id. + vluint64_t m_id; // <63> removed, <62:0> Serial number for ordering + static constexpr vluint64_t REMOVED_MASK = 1ULL << 63; + public: // CONSTRUCTORS MergeCandidate() { @@ -717,9 +720,11 @@ public: virtual ~MergeCandidate() = default; virtual bool mergeWouldCreateCycle() const = 0; // METHODS - bool removedFromSb() const { return m_removedFromSb; } - void removedFromSb(bool removed) { m_removedFromSb = removed; } - bool operator<(const MergeCandidate& other) const { return m_id < other.m_id; } + bool removedFromSb() const { return (m_id & REMOVED_MASK) != 0; } + void removedFromSb(bool removed) { m_id |= REMOVED_MASK; } + bool operator<(const MergeCandidate& other) const { + return (m_id & ~REMOVED_MASK) < (other.m_id & ~REMOVED_MASK); + } }; // A pair of associated LogicMTask's that are merge candidates for sibling