-
Notifications
You must be signed in to change notification settings - Fork 170
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
[master] fix #1596 Major performance issue in case of many new entities #1843
Conversation
…e instead of a linear search Signed-off-by: Patrick Schmitt <[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.
Please update copyright year in the header of updated classes.
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.
Please check and extend tests org.eclipse.persistence.testing.tests.unitofwork.UnregisterUnitOfWorkTest
with primaryKeyToNewObjects
-> getPrimaryKeyToNewObjects()
and
org.eclipse.persistence.testing.tests.unitofwork.DoubleNestedUnitOfWork*
and
org.eclipse.persistence.testing.tests.unitofwork.NestedUnitOfWorkDelete*
...persistence.core/src/main/java/org/eclipse/persistence/internal/sessions/UnitOfWorkImpl.java
Outdated
Show resolved
Hide resolved
...persistence.core/src/main/java/org/eclipse/persistence/internal/sessions/UnitOfWorkImpl.java
Show resolved
Hide resolved
- extended tests - updated copyright year - call removeObjectFromPrimaryKeyToNewObjects in preMergeChanges Signed-off-by: Patrick Schmitt <[email protected]>
...persistence.core/src/main/java/org/eclipse/persistence/internal/sessions/UnitOfWorkImpl.java
Outdated
Show resolved
Hide resolved
...t/src/it/java/org/eclipse/persistence/testing/tests/unitofwork/UnregisterUnitOfWorkTest.java
Outdated
Show resolved
Hide resolved
- remove list from primaryKeyToNewObjects if it is empty - simplify tests Signed-off-by: Patrick Schmitt <[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.
LGTM
Thanks! |
Please make another PR manually. Git cherry pick will not work, as 2.7 was built by Ant and master by Maven (different directory structure, huge refator). Class names are same, but locations are different. |
@rfelcman Alright, we'll do that. |
…ities (eclipse-ee4j#1843) * Issue 1596: use a hash-based collection to lookup objects in the cache instead of a linear search * Adjusted source according to review: - extended tests - updated copyright year - call removeObjectFromPrimaryKeyToNewObjects in preMergeChanges - remove list from primaryKeyToNewObjects if it is empty - simplify tests Signed-off-by: Patrick Schmitt <[email protected]> (cherry picked from commit 76d8274) Signed-off-by: Radek Felcman <[email protected]>
#1863) * Issue 1596: use a hash-based collection to lookup objects in the cache instead of a linear search * Adjusted source according to review: - extended tests - updated copyright year - call removeObjectFromPrimaryKeyToNewObjects in preMergeChanges - remove list from primaryKeyToNewObjects if it is empty - simplify tests (cherry picked from commit 76d8274) Signed-off-by: Patrick Schmitt <[email protected]> Signed-off-by: Radek Felcman <[email protected]> Co-authored-by: Patrick Schmitt <[email protected]>
…ities (eclipse-ee4j#1843) * Issue 1596: use a hash-based collection to lookup objects in the cache instead of a linear search Signed-off-by: Patrick Schmitt <[email protected]> * Adjusted source according to review: - extended tests - updated copyright year - call removeObjectFromPrimaryKeyToNewObjects in preMergeChanges - remove list from primaryKeyToNewObjects if it is empty - simplify tests Signed-off-by: Patrick Schmitt <[email protected]> (cherry picked from commit 76d8274)
When a lookup is performed in a UnitOfWork, eclipselink used to perform a linear search through all new entities. If the UnitOfWork contains many new objects, this becomes a major performance issue, since in the worst case every persisted entity has to be checked and a primary key extraction performed.
By instead maintaining a HashMap of primary key to new objects in the UnitOfWork, the performance impact of a lookup becomes negligible even if there are many persisted entities.
To demonstrate this, I used the UnitTest attached to this comment in the original issue with 10k new entities:
In the original implementation 75% of the execution time is spent in
org.eclipse.persistence.internal.sessions.UnitOfWorkImpl.getObjectFromNewObjects (Class, Object)
and there are ~50k calls toorg.eclipse.persistence.internal.descriptors.ObjectBuilder.extractPrimaryKeyFromObject (Object, org.eclipse.persistence.internal.sessions.AbstractSession, boolean)
:With my new implementation using a HashMap, time spent in
getObjectFromNewObjects (Class, Object)
is reduced to 0.1% and no additional primary key extraction is needed: