Mitigate performance impact of entity enhancement on Klass's _secondary_super_cache
Description
Activity
Show:
Sanne Grinovero
changed the StatusOctober 30, 2022 at 2:39 PMResolved
Closed
Sanne Grinovero
changed the StatusOctober 30, 2022 at 2:38 PMReopened
Resolved
Sanne Grinovero
updated the ResolutionOctober 30, 2022 at 2:38 PMNone
Fixed
Sanne Grinovero
updated the Fix versionsOctober 30, 2022 at 2:38 PMNone
6.2.0
Sanne Grinovero
changed the StatusOctober 30, 2022 at 2:38 PMClosed
Reopened
Sanne Grinovero
updated the ResolutionOctober 30, 2022 at 2:38 PMFixed
None
Andrea Boriero
changed the StatusOctober 28, 2022 at 12:09 PMResolved
Closed
Christian Beikov
updated the Fix versionsOctober 28, 2022 at 10:07 AMNone
5.6.13
Andrea Boriero
changed the StatusOctober 28, 2022 at 10:05 AMOpen
Resolved
Andrea Boriero
updated the ResolutionOctober 28, 2022 at 10:05 AMNone
Fixed
Christian Beikov
updated the Fix versionsOctober 28, 2022 at 10:02 AMNone
6.1.5
Sanne Grinovero
created the IssueOctober 19, 2022 at 5:47 PMFixed
Details
Details
Assignee
Reporter
Sanne Grinovero
Sanne GrinoveroComponents
Priority
Created October 19, 2022 at 5:47 PM
Updated October 30, 2022 at 2:39 PM
Resolved October 30, 2022 at 2:38 PM
We’ve recently become aware of JDK’s limitation https://bugs.openjdk.org/browse/JDK-8180450 and an investigation via GitHub - franz1981/type-pollution-agent: Agent to detect type pollution due to instanceof/checkcast misuses revealed that Hibernate ORM is affected via various paths.
One of the most significant areas of concern surrounds the techniques used to handle bytecode enhanced entities; the agent reports the following:
1: io.quarkus.benchmark.model.World Count: 51703308 Types: org.hibernate.engine.spi.PersistentAttributeInterceptable org.hibernate.engine.spi.ManagedEntity org.hibernate.engine.spi.SelfDirtinessTracker org.hibernate.engine.spi.Managed Traces: org.hibernate.engine.internal.EntityEntryContext.getAssociatedManagedEntity(EntityEntryContext.java:153) class: org.hibernate.engine.spi.ManagedEntity count: 12108604 org.hibernate.engine.internal.EntityEntryContext.getAssociatedManagedEntity(EntityEntryContext.java:154) class: org.hibernate.engine.spi.ManagedEntity count: 6511885 org.hibernate.property.access.spi.EnhancedSetterImpl.set(EnhancedSetterImpl.java:49) class: org.hibernate.engine.spi.PersistentAttributeInterceptable count: 4770509 org.hibernate.tuple.entity.PojoEntityTuplizer.afterInitialize(PojoEntityTuplizer.java:227) class: org.hibernate.engine.spi.SelfDirtinessTracker count: 4762608 org.hibernate.tuple.entity.PojoEntityTuplizer.afterInitialize(PojoEntityTuplizer.java:210) class: org.hibernate.engine.spi.PersistentAttributeInterceptable count: 3617911 org.hibernate.tuple.entity.PojoEntityTuplizer.afterInitialize(PojoEntityTuplizer.java:228) class: org.hibernate.engine.spi.SelfDirtinessTracker count: 3325834 org.hibernate.tuple.entity.BytecodeEnhancementMetadataPojoImpl.extractLazyInterceptor(BytecodeEnhancementMetadataPojoImpl.java:271) class: org.hibernate.engine.spi.PersistentAttributeInterceptable count: 2883597 org.hibernate.tuple.entity.PojoEntityInstantiator.applyInterception(PojoEntityInstantiator.java:55) class: org.hibernate.engine.spi.PersistentAttributeInterceptable count: 2740804 org.hibernate.engine.internal.StatefulPersistenceContext.clear(StatefulPersistenceContext.java:236) class: org.hibernate.engine.spi.PersistentAttributeInterceptable count: 2617366 org.hibernate.property.access.spi.EnhancedSetterImpl.set(EnhancedSetterImpl.java:50) class: org.hibernate.engine.spi.PersistentAttributeInterceptable count: 2560881 org.hibernate.tuple.entity.AbstractEntityTuplizer.linkToSession(AbstractEntityTuplizer.java:717) class: org.hibernate.engine.spi.PersistentAttributeInterceptable count: 1705389 org.hibernate.engine.internal.StatefulPersistenceContext.clear(StatefulPersistenceContext.java:237) class: org.hibernate.engine.spi.PersistentAttributeInterceptable count: 1464702 org.hibernate.engine.internal.EntityEntryContext.addEntityEntry(EntityEntryContext.java:94) class: org.hibernate.engine.spi.ManagedEntity count: 1391146 org.hibernate.engine.internal.EntityEntryContext.addEntityEntry(EntityEntryContext.java:96) class: org.hibernate.engine.spi.ManagedEntity count: 1242069 org.hibernate.property.access.internal.PropertyAccessStrategyResolverStandardImpl.resolvePropertyAccessStrategy(PropertyAccessStrategyResolverStandardImpl.java:40) class: org.hibernate.engine.spi.Managed count: 2 org.hibernate.tuple.entity.PojoEntityInstantiator.<init>(PojoEntityInstantiator.java:38) class: org.hibernate.engine.spi.PersistentAttributeInterceptable count: 1 --------------------------
Source code matches Hibernate ORM version
5.6.12.Final
- and while the agent is prone to reporting false positives, we believe this is not the case.This issue has - surprisingly - eluded performance diagnostic tools so far, and yet has very significant impact on performance; scalability is particularly affected as an high number of cache to cache communication is triggered, including via false sharing of the type cache information.
I believe we can, at least partially, mitigage the performance hit via a minor refactoring which could be applied to both ORM 5.6 and 6+; a better and more thourough analysis will follow separately but will not be backported to older ORM versions.