You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@myfaces.apache.org by ta...@apache.org on 2020/06/07 12:26:15 UTC
[myfaces] branch master updated: MYFACES-4337 [perf] avoid lambda
instances / computeIfAbsent
This is an automated email from the ASF dual-hosted git repository.
tandraschko pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/myfaces.git
The following commit(s) were added to refs/heads/master by this push:
new d7241c2 MYFACES-4337 [perf] avoid lambda instances / computeIfAbsent
d7241c2 is described below
commit d7241c2efb8bc3c0b7d8d8bd8a1e442ef1cf18f0
Author: Thomas Andraschko <ta...@apache.org>
AuthorDate: Sun Jun 7 14:26:06 2020 +0200
MYFACES-4337 [perf] avoid lambda instances / computeIfAbsent
---
.../api/shared/lang/PropertyDescriptorUtils.java | 27 ++++++++++++++--------
.../quarkus/runtime/spi/QuarkusCdiELResolver.java | 8 ++++++-
.../application/ApplicationImplEventManager.java | 8 +++----
.../org/apache/myfaces/config/MyfacesConfig.java | 10 ++++++--
.../myfaces/el/resolver/LambdaBeanELResolver.java | 9 +++++---
5 files changed, 43 insertions(+), 19 deletions(-)
diff --git a/api/src/main/java/org/apache/myfaces/core/api/shared/lang/PropertyDescriptorUtils.java b/api/src/main/java/org/apache/myfaces/core/api/shared/lang/PropertyDescriptorUtils.java
index c0c56c8..0578f67 100644
--- a/api/src/main/java/org/apache/myfaces/core/api/shared/lang/PropertyDescriptorUtils.java
+++ b/api/src/main/java/org/apache/myfaces/core/api/shared/lang/PropertyDescriptorUtils.java
@@ -66,14 +66,28 @@ public class PropertyDescriptorUtils
private static Map<String, Map<String, ? extends PropertyDescriptorWrapper>> getCache(ExternalContext ec)
{
- return (Map<String, Map<String, ? extends PropertyDescriptorWrapper>>)
- ec.getApplicationMap().computeIfAbsent(CACHE_KEY, k -> new ConcurrentHashMap<>(1000));
+ Map<String, Map<String, ? extends PropertyDescriptorWrapper>> cache =
+ (Map<String, Map<String, ? extends PropertyDescriptorWrapper>>) ec.getApplicationMap().get(CACHE_KEY);
+ if (cache == null)
+ {
+ cache = new ConcurrentHashMap<>(1000);
+ ec.getApplicationMap().put(CACHE_KEY, cache);
+ }
+
+ return cache;
}
public static Map<String, ? extends PropertyDescriptorWrapper> getCachedPropertyDescriptors(ExternalContext ec,
Class<?> target)
{
- return getCache(ec).computeIfAbsent(target.getName(), k -> getPropertyDescriptors(ec, target, false));
+ Map<String, ? extends PropertyDescriptorWrapper> cache = getCache(ec).get(target.getName());
+ if (cache == null)
+ {
+ cache = getPropertyDescriptors(ec, target);
+ getCache(ec).put(target.getName(), cache);
+ }
+
+ return cache;
}
public static boolean isUseLambdaMetafactory(ExternalContext ec)
@@ -89,8 +103,7 @@ public class PropertyDescriptorUtils
}
public static Map<String, ? extends PropertyDescriptorWrapper> getPropertyDescriptors(ExternalContext ec,
- Class<?> target,
- boolean skipPropertyWithoutReadMethod)
+ Class<?> target)
{
if (isUseLambdaMetafactory(ec))
{
@@ -107,10 +120,6 @@ public class PropertyDescriptorUtils
{
PropertyDescriptor propertyDescriptor = propertyDescriptors[i];
Method readMethod = propertyDescriptor.getReadMethod();
- if (readMethod == null && skipPropertyWithoutReadMethod)
- {
- continue;
- }
map.put(propertyDescriptor.getName(),
new PropertyDescriptorWrapper(target, propertyDescriptor, readMethod));
diff --git a/extensions/quarkus/runtime/src/main/java/org/apache/myfaces/core/extensions/quarkus/runtime/spi/QuarkusCdiELResolver.java b/extensions/quarkus/runtime/src/main/java/org/apache/myfaces/core/extensions/quarkus/runtime/spi/QuarkusCdiELResolver.java
index d4b1c7b..4582ab7 100644
--- a/extensions/quarkus/runtime/src/main/java/org/apache/myfaces/core/extensions/quarkus/runtime/spi/QuarkusCdiELResolver.java
+++ b/extensions/quarkus/runtime/src/main/java/org/apache/myfaces/core/extensions/quarkus/runtime/spi/QuarkusCdiELResolver.java
@@ -79,7 +79,13 @@ public class QuarkusCdiELResolver extends ELResolver
String beanName = (String) property;
- Optional<Object> contextualInstance = cachedProxies.computeIfAbsent(beanName, s -> resolveProxy(s));
+ Optional<Object> contextualInstance = cachedProxies.get(beanName);
+ if (contextualInstance == null)
+ {
+ contextualInstance = resolveProxy(beanName);
+ cachedProxies.put(beanName, contextualInstance);
+ }
+
if (contextualInstance.isPresent())
{
context.setPropertyResolved(true);
diff --git a/impl/src/main/java/org/apache/myfaces/application/ApplicationImplEventManager.java b/impl/src/main/java/org/apache/myfaces/application/ApplicationImplEventManager.java
index 223f0e9..56f4331 100644
--- a/impl/src/main/java/org/apache/myfaces/application/ApplicationImplEventManager.java
+++ b/impl/src/main/java/org/apache/myfaces/application/ApplicationImplEventManager.java
@@ -154,13 +154,13 @@ public class ApplicationImplEventManager
protected SystemEvent createEvent(Class<? extends SystemEvent> systemEventClass, FacesContext facesContext,
Object source)
{
- Constructor<? extends SystemEvent> constructor = constructorCache.computeIfAbsent(systemEventClass,
- k -> getConstructor(k));
+ Constructor<? extends SystemEvent> constructor = constructorCache.get(systemEventClass);
if (constructor == null)
{
- return null;
+ constructor = getConstructor(systemEventClass);
+ constructorCache.put(systemEventClass, constructor);
}
-
+
try
{
if (constructor.getParameterTypes().length == 2)
diff --git a/impl/src/main/java/org/apache/myfaces/config/MyfacesConfig.java b/impl/src/main/java/org/apache/myfaces/config/MyfacesConfig.java
index 6e554b4..92cd0b2 100755
--- a/impl/src/main/java/org/apache/myfaces/config/MyfacesConfig.java
+++ b/impl/src/main/java/org/apache/myfaces/config/MyfacesConfig.java
@@ -942,8 +942,14 @@ public class MyfacesConfig
public static MyfacesConfig getCurrentInstance(ExternalContext extCtx)
{
- return (MyfacesConfig) extCtx.getApplicationMap().computeIfAbsent(
- APPLICATION_MAP_PARAM_NAME, k -> createAndInitializeMyFacesConfig(extCtx));
+ MyfacesConfig config = (MyfacesConfig) extCtx.getApplicationMap().get(APPLICATION_MAP_PARAM_NAME);
+ if (config == null)
+ {
+ config = createAndInitializeMyFacesConfig(extCtx);
+ extCtx.getApplicationMap().put(APPLICATION_MAP_PARAM_NAME, config);
+ }
+
+ return config;
}
public MyfacesConfig()
diff --git a/impl/src/main/java/org/apache/myfaces/el/resolver/LambdaBeanELResolver.java b/impl/src/main/java/org/apache/myfaces/el/resolver/LambdaBeanELResolver.java
index 4cb9f51..9f74039 100644
--- a/impl/src/main/java/org/apache/myfaces/el/resolver/LambdaBeanELResolver.java
+++ b/impl/src/main/java/org/apache/myfaces/el/resolver/LambdaBeanELResolver.java
@@ -134,9 +134,12 @@ public class LambdaBeanELResolver extends BeanELResolver
protected LambdaPropertyDescriptor getPropertyDescriptor(Object base, Object property)
{
- Map<String, ? extends PropertyDescriptorWrapper> beanCache = cache.computeIfAbsent(
- base.getClass().getName(),
- k -> PropertyDescriptorUtils.getCachedPropertyDescriptors(externalContext, base.getClass()));
+ Map<String, ? extends PropertyDescriptorWrapper> beanCache = cache.get(base.getClass().getName());
+ if (beanCache == null)
+ {
+ beanCache = PropertyDescriptorUtils.getCachedPropertyDescriptors(externalContext, base.getClass());
+ cache.put(base.getClass().getName(), beanCache);
+ }
return (LambdaPropertyDescriptor) beanCache.get((String) property);
}