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

Alex CD (JIRA) jira at hibernate.atlassian.net
Wed Jul 1 15:31:46 EDT 2020


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

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

Issue Type: Bug Affects Versions: 5.4.17 Assignee: Unassigned Created: 01/Jul/2020 12:31 PM Priority: Major Reporter: 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:

	@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 ;
	}

*insertedEntityIds* list may contain more than 10.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=eyJpIjoiMGVmYjNhMWU4YTNkNDhiNDgxOTMzMWYxMjg4MDI0MzQiLCJwIjoiaiJ9 ) Add Comment ( https://hibernate.atlassian.net/browse/HHH-14093#add-comment?atlOrigin=eyJpIjoiMGVmYjNhMWU4YTNkNDhiNDgxOTMzMWYxMjg4MDI0MzQiLCJwIjoiaiJ9 )

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/8ae4519f/attachment.html 


More information about the hibernate-issues mailing list