Skip to content

Commit 2d16fb7

Browse files
author
MarcoFalke
committed
Merge #14984: rpc: Speedup getrawmempool when verbose=true
2d5cf4c rpc: Speedup getrawmempool when verbose=true (João Barbosa) Pull request description: Instead of calling `pushKV(hash, info)`, which incurs in duplicate key checks, call `__pushKV` which (currently) doesn't. Improves RPC `getrawmempool` and REST `/rest/mempool/contents.json`. Fixes #14765. ACKs for commit 2d5cf4: Tree-SHA512: c3e91371bb41f39e79dcef820815e1dc27fb689ca3c4bf3a00467d2215b3baecd44d9792f7a481577a5b7ae1fc6cbaa07b1cd62123b845082eba65b35c2b3ca5
2 parents 65526fc + 2d5cf4c commit 2d16fb7

File tree

1 file changed

+4
-1
lines changed

1 file changed

+4
-1
lines changed

src/rpc/blockchain.cpp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -486,7 +486,10 @@ UniValue MempoolToJSON(const CTxMemPool& pool, bool verbose)
486486
const uint256& hash = e.GetTx().GetHash();
487487
UniValue info(UniValue::VOBJ);
488488
entryToJSON(pool, info, e);
489-
o.pushKV(hash.ToString(), info);
489+
// Mempool has unique entries so there is no advantage in using
490+
// UniValue::pushKV, which checks if the key already exists in O(N).
491+
// UniValue::__pushKV is used instead which currently is O(1).
492+
o.__pushKV(hash.ToString(), info);
490493
}
491494
return o;
492495
} else {

0 commit comments

Comments
 (0)