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

[master] fix #1596 Major performance issue in case of many new entities #1843

Merged
merged 3 commits into from Apr 11, 2023
Merged

Conversation

Zuplyx
Copy link
Contributor

@Zuplyx Zuplyx commented Mar 28, 2023

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 to org.eclipse.persistence.internal.descriptors.ObjectBuilder.extractPrimaryKeyFromObject (Object, org.eclipse.persistence.internal.sessions.AbstractSession, boolean):

visualVM_linearSearch

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:

visualVM_HashMap

…e instead of a linear search

Signed-off-by: Patrick Schmitt <Patrick.Schmitt@cpb-software.com>
Copy link
Contributor

@rfelcman rfelcman left a 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.

Copy link
Contributor

@rfelcman rfelcman left a 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*

- extended tests
- updated copyright year
- call removeObjectFromPrimaryKeyToNewObjects in preMergeChanges

Signed-off-by: Patrick Schmitt <Patrick.Schmitt@cpb-software.com>
@Zuplyx Zuplyx requested a review from rfelcman April 6, 2023 11:06
- remove list from primaryKeyToNewObjects if it is empty
- simplify tests

Signed-off-by: Patrick Schmitt <Patrick.Schmitt@cpb-software.com>
@Zuplyx Zuplyx requested a review from rfelcman April 6, 2023 18:12
Copy link
Contributor

@rfelcman rfelcman left a comment

Choose a reason for hiding this comment

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

LGTM

@rfelcman rfelcman merged commit 76d8274 into eclipse-ee4j:master Apr 11, 2023
3 checks passed
@patric-r
Copy link

Thanks!
@rfelcman Can we merge this to 2.7?

@rfelcman
Copy link
Contributor

Thanks! @rfelcman Can we merge this to 2.7?

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.

@patric-r
Copy link

@rfelcman Alright, we'll do that.

rfelcman pushed a commit to rfelcman/eclipselink that referenced this pull request Apr 13, 2023
…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 <Patrick.Schmitt@cpb-software.com>

(cherry picked from commit 76d8274)
Signed-off-by: Radek Felcman <radek.felcman@oracle.com>
rfelcman added a commit that referenced this pull request Apr 17, 2023
#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 <Patrick.Schmitt@cpb-software.com>
Signed-off-by: Radek Felcman <radek.felcman@oracle.com>
Co-authored-by: Patrick Schmitt <13404745+zuplyx@users.noreply.github.com>
dtaimanov pushed a commit to jmix-framework/eclipselink that referenced this pull request Jan 18, 2024
…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 <Patrick.Schmitt@cpb-software.com>

* 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 <Patrick.Schmitt@cpb-software.com>

(cherry picked from commit 76d8274)
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.

Major performance issue in case of many new entities
3 participants