During Initial Block Download, the mempool is usually empty, but CTxMemPool::removeForBlock
is still called for every connected block where we:
- iterate over every transaction in the block even though none will be found in the empty
mapTx
, always leavingtxs_removed_for_block
empty… - which is pre-allocated regardless with
40 bytes * vtx.size()
, even though it will always remain empty.
Similarly to #32730 (review), this change introduces a minor performance & memory optimization by only executing the loop if any of the affected mempool maps have any contents. The second commit is cherry-picked from there since it’s related to this change as well.