Merge #6424: refactor: move expensive CInv initialization out of hot loop

b65f0bab7f refactor: move expensive CInv initialization out of hot loop (pasta)

Pull request description:

  ## Issue being fixed or feature implemented
  Not sure how we introduced this one, but it appears we are calling a CInv construction (pretty cheap) and a GetDSTX ((relatively) EXPENSIVE) for each peer we are connected to in RelayTransaction... I can hope and pray that the compiler somehow was magically optimizing this for us, but I really doubt it

  ## What was done?
  Move the initialization out of the loop

  ## How Has This Been Tested?

  ## Breaking Changes
  N/A

  ## Checklist:
  - [x] I have performed a self-review of my own code
  - [ ] I have commented my code, particularly in hard-to-understand areas
  - [ ] I have added or updated relevant unit/integration/functional/e2e tests
  - [ ] I have made corresponding changes to the documentation
  - [x] I have assigned this pull request to a milestone _(for repository code-owners and collaborators only)_

ACKs for top commit:
  knst:
    utACK b65f0bab7f
  UdjinM6:
    utACK b65f0bab7f
  kwvg:
    utACK b65f0bab7f

Tree-SHA512: f556789042ab9265d5c4d87c3ba2910138ce43ffa69c90ed208c9a3bcd861343f201ce2f00aeb541f345c9ca686dac7227df8d4833cf7fbdf61c36260f627864
This commit is contained in:
pasta 2024-11-22 12:20:23 -06:00
commit 0398b1cd72
No known key found for this signature in database
GPG Key ID: E2F3D7916E722D38

View File

@ -2328,13 +2328,13 @@ void PeerManagerImpl::RelayInvFiltered(CInv &inv, const uint256& relatedTxHash,
void PeerManagerImpl::RelayTransaction(const uint256& txid)
{
const CInv inv{m_cj_ctx->dstxman->GetDSTX(txid) ? MSG_DSTX : MSG_TX, txid};
LOCK(m_peer_mutex);
for(auto& it : m_peer_map) {
Peer& peer = *it.second;
auto tx_relay = peer.GetTxRelay();
if (!tx_relay) continue;
const CInv inv{m_cj_ctx->dstxman->GetDSTX(txid) ? MSG_DSTX : MSG_TX, txid};
PushInv(peer, inv);
};
}