This PR addresses the tx relay trickle case specifically, but the snapshot feature can be used in other places as well, where a known set of mempool transactions are being juggled around.
A new class TxMemPoolSnapshot is introduced (63e7997) which is instantiated from CTxMemPool via the snapshot() method. This generates a minimalized, no-locks mempool which can be queried and discarded at will. It is obviously not thread safe.
In 499f14f, this is used for the tx trickle code in SendMessages. This code is executed roughly 5-6 times per second. The number of LOCK(cs) inside the mempool are proportional to the number of entries in vInvTx (because of the sorting part using CompareInvMempoolOrder), which ranges in size from 0 to over 4000.
I began investigating this after seeing 131703419 occurrences of LOCK(cs) in the mempool caused by 504302 entries into the tx relay trickle code path (that's ~250 locks per entry). This was after less than 24 hours of running.