[hibernate-issues] [Hibernate-JIRA] Created: (HHH-6794) Share the same ReflectionManager amongst all Configurations in order to reduce SessionFactoryImpl memory footprint

Julien Kronegg (JIRA) noreply at atlassian.com
Wed Nov 2 07:39:23 EDT 2011


Share the same ReflectionManager amongst all Configurations in order to reduce SessionFactoryImpl memory footprint
------------------------------------------------------------------------------------------------------------------

                 Key: HHH-6794
                 URL: http://opensource.atlassian.com/projects/hibernate/browse/HHH-6794
             Project: Hibernate Core
          Issue Type: New Feature
          Components: core
    Affects Versions: 4.0.0.CR5, 3.6.8
            Reporter: Julien Kronegg
            Priority: Minor


h3. The problem:
About 25% (i.e. about 50 MB in our case) of the memory used by Hibernate mappings is in the JavaReflectionManager instances.
This occurs in the following configuration:
- several persistence-units (5 in our case)
- a lot of entities (about 286 entities)
- each persistence-unit has the same entities (each persistence-unit has a different datasource)

See also the Hibernate forum's [Memory usage after initializing SessionFactory|https://forum.hibernate.org/viewtopic.php?p=2449724#p2449724]

h3. The cause:
Basically, the ReflectionManager caches the reflection stuff (e.g. field->getter) to have faster processing.
Each [org.hibernate.cfg.Configuration|https://fisheye2.atlassian.com/browse/~br=master/Hibernate-Core/hibernate-core/src/main/java/org/hibernate/cfg/Configuration.java?hb=true] has its own ReflectionManager instance.
Thus, since each persistence-unit has the same entities, each ReflectionManager holds the same reflection data (but on different instances so that memory usage increase).

h3. The solution:
It would be nice if all Configuration share the same ReflectionManager (e.g. singleton) so that reflection data are cached only once.
In the case of our setup, this would reduce Hibernate mappings memory usage by about 20%.
This would require to make JavaReflectionManager thread-safe (which not currently the case, see HashMap and unsynchronized methods usage).

h3. The workaround:
We found that disabling Hibernate Validator in the persistence-unit reduced memory usage because the ReflectionManager is not used anymore:

{code}
<property name="hibernate.validator.apply_to_ddl" value="false"/>
<property name="hibernate.validator.autoregister_listeners" value="false"/>
{code}

In our case, the memory usage decreased by about 100 MB.



--
This message is automatically generated by JIRA.
For more information on JIRA, see: http://www.atlassian.com/software/jira

        


More information about the hibernate-issues mailing list