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

[#2121] Move _key() after reference/null checks in JPABase.equals() #1141

Merged
merged 1 commit into from
May 24, 2017

Conversation

davidcostanzo
Copy link
Contributor

The pull request moves _key() and adds unit tests for JPABase.equals() to give confidence that there were no behavioral changes.

@asolntsev
Copy link
Contributor

@davidcostanzo Can you describe what problem you are trying to solve? Why the check should be moved? Why are you confident that it will not break existing applications?

@davidcostanzo
Copy link
Contributor Author

Thanks for considering the pull request. Answers to your questions follow:

Can you describe what problem you are trying to solve?

Briefly, the problem I'm trying to solve is to improve performance of my application. The problem is described abstractly in the lighthouse ticket, but essentially I have an inner loop within a long-running Job which needs to test GenericModel objects for equality and in most cases the objects are equal (if they're not, then some additional work is done). Due to the entity manager's persistence context, objects are not duplicated within the job, so references to objects that are equal are references to the same object. That is, the object references are equal. So the change improves performance.

The application could test for reference equality before calling equals() (which is what I effectively did to work around the problem) but that's ugly because it's the job of equals() to encapsulate equality logic, not the caller.

Why the check should be moved?

The check should be moved because improves in the case where the object references are equal without hurting performance in the other cases. Because of Play's and Hibernate's architecture, object references will usually be equal whenever the objects are equal.

Why are you confident that it will not break existing applications?

I don't see how it could. It's a simple optimization that delays computing a value until it's used and follows the pattern that was recommended in Effective Java. It doesn't change the computed result. I added unit tests to be sure of that.

@asolntsev
Copy link
Contributor

asolntsev commented May 24, 2017 via email

@asolntsev asolntsev self-requested a review May 24, 2017 10:16
@asolntsev asolntsev self-assigned this May 24, 2017
@asolntsev asolntsev added this to the 1.5.0 milestone May 24, 2017
@asolntsev asolntsev merged commit 637e717 into playframework:master May 24, 2017
@davidcostanzo davidcostanzo deleted the lighthouse-2121-patch branch May 24, 2017 15:30
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.

2 participants