[hibernate-issues] [JIRA] (HHH-14093) Optimize inserted key contains

Alex CD (JIRA) jira at hibernate.atlassian.net
Wed Jul 1 17:56:17 EDT 2020


Alex CD ( https://hibernate.atlassian.net/secure/ViewProfile.jspa?accountId=557058%3A9b0f6d49-bc76-4aca-875b-c8525b2f039d ) *updated* an issue

Hibernate ORM ( https://hibernate.atlassian.net/browse/HHH?atlOrigin=eyJpIjoiNWIxODY1NGU5Y2QzNDQ5M2I5NTIwOTgzZjBhZmU1YTkiLCJwIjoiaiJ9 ) / Improvement ( https://hibernate.atlassian.net/browse/HHH-14093?atlOrigin=eyJpIjoiNWIxODY1NGU5Y2QzNDQ5M2I5NTIwOTgzZjBhZmU1YTkiLCJwIjoiaiJ9 ) HHH-14093 ( https://hibernate.atlassian.net/browse/HHH-14093?atlOrigin=eyJpIjoiNWIxODY1NGU5Y2QzNDQ5M2I5NTIwOTgzZjBhZmU1YTkiLCJwIjoiaiJ9 ) Optimize inserted key contains ( https://hibernate.atlassian.net/browse/HHH-14093?atlOrigin=eyJpIjoiNWIxODY1NGU5Y2QzNDQ5M2I5NTIwOTgzZjBhZmU1YTkiLCJwIjoiaiJ9 )

Change By: Alex CD ( https://hibernate.atlassian.net/secure/ViewProfile.jspa?accountId=557058%3A9b0f6d49-bc76-4aca-875b-c8525b2f039d )

In a transaction where many entities are inserted, the performance when getting an entity is degrading at:
StatefulPersistenceCotnext.java:

{code:java}
@Override
public boolean wasInsertedDuringTransaction(EntityPersister persister, Serializable id) {
// again, we only really care if the entity is cached
if ( persister.canWriteToCache() ) {
if ( insertedKeysMap != null ) {
final List<Serializable> insertedEntityIds = insertedKeysMap.get( persister.getRootEntityName() );
if ( insertedEntityIds != null ) {
return insertedEntityIds.contains( id );
}
}
}
return false;
}
{code}

*insertedEntityIds* list may contain more than 10 100.000 entries that affect performance of *ArrayList.contains* which has *O( n )* complexity.

Please replace *ArrayList* with *HashSet* for better _contains_ performance.

( https://hibernate.atlassian.net/browse/HHH-14093#add-comment?atlOrigin=eyJpIjoiNWIxODY1NGU5Y2QzNDQ5M2I5NTIwOTgzZjBhZmU1YTkiLCJwIjoiaiJ9 ) Add Comment ( https://hibernate.atlassian.net/browse/HHH-14093#add-comment?atlOrigin=eyJpIjoiNWIxODY1NGU5Y2QzNDQ5M2I5NTIwOTgzZjBhZmU1YTkiLCJwIjoiaiJ9 )

Get Jira notifications on your phone! Download the Jira Cloud app for Android ( https://play.google.com/store/apps/details?id=com.atlassian.android.jira.core&referrer=utm_source%3DNotificationLink%26utm_medium%3DEmail ) or iOS ( https://itunes.apple.com/app/apple-store/id1006972087?pt=696495&ct=EmailNotificationLink&mt=8 ) This message was sent by Atlassian Jira (v1001.0.0-SNAPSHOT#100131- sha1:a811519 )
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.jboss.org/pipermail/hibernate-issues/attachments/20200701/0fafc9ac/attachment.html 


More information about the hibernate-issues mailing list