Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Merged

Conversation

PastaPastaPasta
Copy link
Member

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:

  • 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
  • I have assigned this pull request to a milestone (for repository code-owners and collaborators only)

@PastaPastaPasta PastaPastaPasta added this to the 22.1 milestone Nov 21, 2024
Copy link
Collaborator

@knst knst left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

utACK b65f0ba

@@ -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};
Copy link
Collaborator

@knst knst Nov 21, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

usually it's only 10-12 peers, so, maybe improvements is non-noticeable by benchmark

Copy link
Member Author

@PastaPastaPasta PastaPastaPasta Nov 21, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Well, no, not necessarily, MNs are highly connected. As an example on testnet

ubuntu@masternode-12:~$ dash-cli getpeerinfo | jq .[].id | wc -l
100

and only 4 of them have tx relay disabled

ubuntu@masternode-12:~$ dash-cli getpeerinfo | jq .[].relaytxes | grep false | wc -l
4

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ah yes, I completely forgot about MNs 🫣

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ah yes, I completely forgot about MNs 🫣

Careful about that, they may fire you!

Copy link

@UdjinM6 UdjinM6 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good catch!

utACK b65f0ba

Copy link
Collaborator

@kwvg kwvg left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

utACK b65f0ba

@PastaPastaPasta PastaPastaPasta merged commit 0398b1c into dashpay:develop Nov 22, 2024
28 of 31 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants