From 54b93f9e8c707e707d7cdc52d3f3fcd43728c2eb Mon Sep 17 00:00:00 2001 From: Mark Paluch Date: Wed, 25 Jul 2018 15:31:45 +0200 Subject: [PATCH] DATACMNS-1357 - Use shared DefaultConversionService in ProxyProjectionFactory and ResultProcessor. ProxyProjectionFactory and ResultProcessor require a DefaultConversionService to convert values for projection proxies and to post-process query method results. Creating instances of these types requires an instance of the conversion service which previously created a DefaultConversionService instance (along all converter registrations) upon ProxyProjection/ResultProcessor instantiation. We now use the shared instance that is initialized once and shared across all ProxyProjection/ResultProcessor instances to reduce garbage and improve the CPU profile. --- .../data/projection/ProxyProjectionFactory.java | 3 ++- .../springframework/data/repository/query/ResultProcessor.java | 2 +- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/src/main/java/org/springframework/data/projection/ProxyProjectionFactory.java b/src/main/java/org/springframework/data/projection/ProxyProjectionFactory.java index cd78e1253..8fba85d4a 100644 --- a/src/main/java/org/springframework/data/projection/ProxyProjectionFactory.java +++ b/src/main/java/org/springframework/data/projection/ProxyProjectionFactory.java @@ -41,6 +41,7 @@ import org.springframework.util.ConcurrentReferenceHashMap; * * @author Oliver Gierke * @author Christoph Strobl + * @author Mark Paluch * @see SpelAwareProxyProjectionFactory * @since 1.10 */ @@ -60,7 +61,7 @@ class ProxyProjectionFactory implements ProjectionFactory, BeanClassLoaderAware this.factories.add(MapAccessingMethodInterceptorFactory.INSTANCE); this.factories.add(PropertyAccessingMethodInvokerFactory.INSTANCE); - this.conversionService = new DefaultConversionService(); + this.conversionService = DefaultConversionService.getSharedInstance(); } /* diff --git a/src/main/java/org/springframework/data/repository/query/ResultProcessor.java b/src/main/java/org/springframework/data/repository/query/ResultProcessor.java index f7503b9c2..114839e1d 100644 --- a/src/main/java/org/springframework/data/repository/query/ResultProcessor.java +++ b/src/main/java/org/springframework/data/repository/query/ResultProcessor.java @@ -260,7 +260,7 @@ public class ResultProcessor { * @param factory must not be {@literal null}. */ ProjectingConverter(ReturnedType type, ProjectionFactory factory) { - this(type, factory, new DefaultConversionService()); + this(type, factory, DefaultConversionService.getSharedInstance()); } /**