From 0761024b349048ebf79dbfe71caab11826833464 Mon Sep 17 00:00:00 2001 From: jeffro256 Date: Mon, 3 Nov 2025 17:05:57 -0600 Subject: tx_memory_pool: speedup get_complement() for large requests Changes complexity from M*N to (2*N+M)*log2(M). The FCMP++ stressnet recently hit mempool sizes of ~55k txs. If the requesting node's mempool is populated, this results in an average of (55000*55000)/2 (about 1.5 billion) comparisons for the responding node. Under this commit, this would be reduced to (55000+55000)*log2(55000) comparisons (about 2.6 million), a 99.83% reduction. --- src/crypto/hash.h | 3 +++ 1 file changed, 3 insertions(+) (limited to 'src/crypto') diff --git a/src/crypto/hash.h b/src/crypto/hash.h index 8ea626314..274907076 100644 --- a/src/crypto/hash.h +++ b/src/crypto/hash.h @@ -101,6 +101,9 @@ namespace crypto { constexpr static crypto::hash null_hash = {}; constexpr static crypto::hash8 null_hash8 = {}; + + inline bool operator<(const hash &lhs, const hash &rhs) noexcept { return memcmp(&lhs, &rhs, sizeof(hash)) < 0; } + inline bool operator>(const hash &lhs, const hash &rhs) noexcept { return rhs < lhs; } } CRYPTO_MAKE_HASHABLE(hash) -- cgit v1.2.3