-
Notifications
You must be signed in to change notification settings - Fork 873
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
Conversation
Signed-off-by: Ameziane H. <[email protected]>
Signed-off-by: Ameziane H. <[email protected]>
There was a problem hiding this 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()?
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()); |
There was a problem hiding this comment.
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.
Signed-off-by: Ameziane H. <[email protected]>
* 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]>
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.
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?
doc-change-required
label to this PR if updates are required.Locally, you can run these tests to catch failures early:
./gradlew build
./gradlew acceptanceTest
./gradlew integrationTest
./gradlew ethereum:referenceTests:referenceTests