You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@openwebbeans.apache.org by ta...@apache.org on 2026/04/14 14:16:13 UTC
(openwebbeans) branch main updated: OWB-1457 - [perf] Reuse generics “visited” map in InjectionResolver#implResolveByType
This is an automated email from the ASF dual-hosted git repository.
tandraschko pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/openwebbeans.git
The following commit(s) were added to refs/heads/main by this push:
new 87de70f67 OWB-1457 - [perf] Reuse generics “visited” map in InjectionResolver#implResolveByType
87de70f67 is described below
commit 87de70f673ccd9d9cc086e8b6a9042380b6ed013
Author: tandraschko <ta...@apache.org>
AuthorDate: Tue Apr 14 16:11:37 2026 +0200
OWB-1457 - [perf] Reuse generics “visited” map in InjectionResolver#implResolveByType
---
.../webbeans/container/InjectionResolver.java | 35 ++++++++++++++++------
1 file changed, 26 insertions(+), 9 deletions(-)
diff --git a/webbeans-impl/src/main/java/org/apache/webbeans/container/InjectionResolver.java b/webbeans-impl/src/main/java/org/apache/webbeans/container/InjectionResolver.java
index 8d2f8a55e..ad94da21b 100644
--- a/webbeans-impl/src/main/java/org/apache/webbeans/container/InjectionResolver.java
+++ b/webbeans-impl/src/main/java/org/apache/webbeans/container/InjectionResolver.java
@@ -421,6 +421,7 @@ public class InjectionResolver
}
resolvedComponents = new HashSet<>();
+ HashMap<Type, Integer> visitedForGenerics = new HashMap<>();
boolean returnAll = injectionPointType.equals(Object.class) && currentQualifier;
@@ -455,10 +456,10 @@ public class InjectionResolver
{
for (Type componentApiType : component.getTypes())
{
-
+ visitedForGenerics.clear();
if (GenericsUtil.satisfiesDependency(
isDelegate, AbstractProducerBean.class.isInstance(component),
- injectionPointType, componentApiType, new HashMap<>()))
+ injectionPointType, componentApiType, visitedForGenerics))
{
resolvedComponents.add(component);
break;
@@ -470,14 +471,17 @@ public class InjectionResolver
if (!returnAll)
{
+ // Main scan may have left state in visitedForGenerics; refinement uses the same map.
+ visitedForGenerics.clear();
+
// Look for qualifiers
resolvedComponents = findByQualifier(resolvedComponents, injectionPointType, qualifiers);
// have an additional round of checks for assignability of parameterized types.
- Set<Bean<?>> byParameterizedType = findByParameterizedType(resolvedComponents, injectionPointType, isDelegate);
+ Set<Bean<?>> byParameterizedType = findByParameterizedType(resolvedComponents, injectionPointType, isDelegate, visitedForGenerics);
if (byParameterizedType.isEmpty())
{
- resolvedComponents = findByBeanType(resolvedComponents, injectionPointType, isDelegate);
+ resolvedComponents = findByBeanType(resolvedComponents, injectionPointType, isDelegate, visitedForGenerics);
}
else
{
@@ -509,7 +513,11 @@ public class InjectionResolver
return resolvedComponents;
}
- private Set<Bean<?>> findByBeanType(Set<Bean<?>> allComponents, Type injectionPointType, boolean isDelegate)
+ /**
+ * @param visited scratch map for {@link GenericsUtil#satisfiesDependency}; cleared before each call.
+ */
+ private Set<Bean<?>> findByBeanType(Set<Bean<?>> allComponents, Type injectionPointType, boolean isDelegate,
+ Map<Type, Integer> visited)
{
if (allComponents == null || allComponents.isEmpty())
{
@@ -517,13 +525,16 @@ public class InjectionResolver
return allComponents;
}
+ visited.clear();
+
Set<Bean<?>> resolved = new HashSet<>();
for (Bean<?> bean : allComponents)
{
boolean isProducer = AbstractProducerBean.class.isInstance(bean);
for (Type type : bean.getTypes())
{
- if (GenericsUtil.satisfiesDependency(isDelegate, isProducer, injectionPointType, type, new HashMap<>()))
+ visited.clear();
+ if (GenericsUtil.satisfiesDependency(isDelegate, isProducer, injectionPointType, type, visited))
{
resolved.add(bean);
}
@@ -538,18 +549,24 @@ public class InjectionResolver
return resolved;
}
- private Set<Bean<?>> findByParameterizedType(Set<Bean<?>> allComponents, Type injectionPointType, boolean isDelegate)
+ /**
+ * @param visited scratch map for {@link GenericsUtil#satisfiesDependency}; cleared before each call.
+ */
+ private Set<Bean<?>> findByParameterizedType(Set<Bean<?>> allComponents, Type injectionPointType, boolean isDelegate,
+ Map<Type, Integer> visited)
{
Bean<?> rawProducerBean = null;
+ visited.clear();
+
Set<Bean<?>> resolvedComponents = new HashSet<>();
for (Bean<?> component : allComponents)
{
boolean isProducer = AbstractProducerBean.class.isInstance(component);
for (Type componentApiType : component.getTypes())
{
-
- if (GenericsUtil.satisfiesDependency(isDelegate, isProducer, injectionPointType, componentApiType, new HashMap<>()))
+ visited.clear();
+ if (GenericsUtil.satisfiesDependency(isDelegate, isProducer, injectionPointType, componentApiType, visited))
{
resolvedComponents.add(component);
break;