We're updating the issue view to help you get more done. 

Add caching to MetamodelImpl

Description

Hello,

This is a proposal for a simple improvement that made an appreciable difference in CPU utilization while testing our app:

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 --- C:\project\MetamodelImpl.java 2018-04-16 15:00:38.193608600 -0400 +++ C:\project\src\main\java\org\hibernate\metamodel\internal\MetamodelImpl.java 2018-04-16 15:21:41.331046300 -0400 @@ -87,6 +87,7 @@ private final Map<String, EntityTypeImpl<?>> jpaEntityTypesByEntityName = new ConcurrentHashMap<>(); private final transient Map<String,EntityGraph> entityGraphMap = new ConcurrentHashMap<>(); + private final Map<String,String[]> implementorsMap = new ConcurrentHashMap<>(); public MetamodelImpl(SessionFactoryImplementor sessionFactory) { this.sessionFactory = sessionFactory; @@ -542,7 +543,9 @@ * @throws MappingException */ public String[] getImplementors(String className) throws MappingException { - + if(implementorsMap.containsKey(className)){ + return implementorsMap.get(className); + } final Class clazz; try { clazz = getSessionFactory().getServiceRegistry().getService( ClassLoaderService.class ).classForName( className ); @@ -586,7 +589,10 @@ } } } - return results.toArray( new String[results.size()] ); + + String[] ret = results.toArray( new String[results.size()] ); + implementorsMap.put(className, ret); + return ret; } @Override \ No newline at end of file

Basically, the code above add caching to getImplementors.

With this change we could obtain about 4 to 5% improvement in CPU utilization across the application.

Environment

None

Status

Assignee

Unassigned

Reporter

Marc Boudreault

Fix versions

None

Labels

None

backPortable

None

Suitable for new contributors

None

Requires Release Note

None

Pull Request

None

backportDecision

None

Components

Affects versions

5.2.5

Priority

Minor