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

Improve equals performance on Address #8013

Merged
merged 5 commits into from
Dec 11, 2024

Conversation

ahamlat
Copy link
Contributor

@ahamlat ahamlat commented Dec 10, 2024

PR description

We've noticed when profiling the SELFBALANCE during load testing that the throughput issue is related to the equals operation on the address class.
image

This PR introduces a new implementation of the equals method in the Address class to replace the one inherited from AbstractBytes. The issue with equals in AbstractBytes is that it compares each byte from both addresses individually, and the get method used is megamorphic.

Fixed Issue(s)

Thanks for sending a pull request! Have you done the following?

  • Checked out our contribution guidelines?
  • Considered documentation and added the doc-change-required label to this PR if updates are required.
  • Considered the changelog and included an update if required.
  • For database changes (e.g. KeyValueSegmentIdentifier) considered compatibility and performed forwards and backwards compatibility tests

Locally, you can run these tests to catch failures early:

  • unit tests: ./gradlew build
  • acceptance tests: ./gradlew acceptanceTest
  • integration tests: ./gradlew integrationTest
  • reference tests: ./gradlew ethereum:referenceTests:referenceTests

@ahamlat ahamlat marked this pull request as ready for review December 10, 2024 11:10
Copy link
Contributor

@macfarla macfarla left a comment

Choose a reason for hiding this comment

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

do you need to override hashcode() because you've overridden equals()?

@ahamlat
Copy link
Contributor Author

ahamlat commented Dec 10, 2024

The current implementation of the hashcode in AbstractByte is good IMO, it is also stored to avoid recalculation. That's why I didn't override it.

return false;
}
Address other = (Address) obj;
return Arrays.equals(this.toArray(), other.toArray());
Copy link
Contributor

Choose a reason for hiding this comment

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

Consider using toArrayUnsafe, which will use local copies of the bytes if they exist, and will have less GC churn. (if a local copy does not exist it will go back to toArray)

As long as we never manipulate the bytes that are returned it will be safe. The Unsafe part only denotes we are exposing an internal array.

@ahamlat ahamlat merged commit c62cd21 into hyperledger:main Dec 11, 2024
43 checks passed
daniellehrner pushed a commit to daniellehrner/besu that referenced this pull request Dec 18, 2024
* Improve equals performance operation on Address
* Use toArrayUnsafe instead of toArray to reduce GC overhead

Signed-off-by: Ameziane H. <[email protected]>
Co-authored-by: Sally MacFarlane <[email protected]>
Signed-off-by: Daniel Lehrner <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants