From a77c4081f758ebfc4faa38692a4b46a037b2b75a Mon Sep 17 00:00:00 2001 From: Sanne Grinovero Date: Thu, 1 Mar 2018 20:31:56 +0000 Subject: [PATCH] HHH-12340 BasicTypeRegistry would benefit from string interning --- .../src/main/java/org/hibernate/type/BasicTypeRegistry.java | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/hibernate-core/src/main/java/org/hibernate/type/BasicTypeRegistry.java b/hibernate-core/src/main/java/org/hibernate/type/BasicTypeRegistry.java index 72f1a6fe01..6732bacd36 100644 --- a/hibernate-core/src/main/java/org/hibernate/type/BasicTypeRegistry.java +++ b/hibernate-core/src/main/java/org/hibernate/type/BasicTypeRegistry.java @@ -142,6 +142,10 @@ public class BasicTypeRegistry implements Serializable { if ( key == null ) { continue; } + //Use String#intern here as there's high chances of duplicates combined with long term usage: + //just running our testsuite would generate 210,000 instances for the String "java.lang.Class" alone. + //Incidentally this might help with map lookup efficiency too. + key = key.intern(); LOG.debugf( "Adding type registration %s -> %s", key, type ); final Type old = registry.put( key, type ); if ( old != null && old != type ) {