From ab710d6b101dbf73fa71dd3e9bbda1c1591d70a8 Mon Sep 17 00:00:00 2001 From: Georgios Andrianakis Date: Fri, 20 Dec 2024 10:33:41 +0200 Subject: [PATCH] Get rid of unnecessary reflective calls at RESTEasy Reactive startup These calls were originally done to support REST Links, but the information they obtained has long been available at build time, meaning the reflective calls are totally unnecessary (and wasteful) --- .../startup/RuntimeResourceDeployment.java | 15 +--------- .../spi/ResteasyReactiveResourceInfo.java | 30 +------------------ 2 files changed, 2 insertions(+), 43 deletions(-) diff --git a/independent-projects/resteasy-reactive/server/runtime/src/main/java/org/jboss/resteasy/reactive/server/core/startup/RuntimeResourceDeployment.java b/independent-projects/resteasy-reactive/server/runtime/src/main/java/org/jboss/resteasy/reactive/server/core/startup/RuntimeResourceDeployment.java index 2bc5999117537..2b655205434df 100644 --- a/independent-projects/resteasy-reactive/server/runtime/src/main/java/org/jboss/resteasy/reactive/server/core/startup/RuntimeResourceDeployment.java +++ b/independent-projects/resteasy-reactive/server/runtime/src/main/java/org/jboss/resteasy/reactive/server/core/startup/RuntimeResourceDeployment.java @@ -17,11 +17,9 @@ import java.util.Arrays; import java.util.Collections; import java.util.HashMap; -import java.util.HashSet; import java.util.List; import java.util.Map; import java.util.Optional; -import java.util.Set; import java.util.concurrent.Executor; import java.util.function.Supplier; @@ -177,19 +175,8 @@ public RuntimeResource buildResourceMethod(ResourceClass clazz, } } - Annotation[] resourceClassAnnotations = resourceClass.getAnnotations(); - Set classAnnotationNames; - if (resourceClassAnnotations.length == 0) { - classAnnotationNames = Collections.emptySet(); - } else { - classAnnotationNames = new HashSet<>(resourceClassAnnotations.length); - for (Annotation annotation : resourceClassAnnotations) { - classAnnotationNames.add(annotation.annotationType().getName()); - } - } - ResteasyReactiveResourceInfo lazyMethod = new ResteasyReactiveResourceInfo(method.getName(), resourceClass, - parameterDeclaredUnresolvedTypes, classAnnotationNames, method.getMethodAnnotationNames(), + parameterDeclaredUnresolvedTypes, !defaultBlocking && !method.isBlocking(), method.getActualDeclaringClassName()); RuntimeInterceptorDeployment.MethodInterceptorContext interceptorDeployment = runtimeInterceptorDeployment diff --git a/independent-projects/resteasy-reactive/server/runtime/src/main/java/org/jboss/resteasy/reactive/server/spi/ResteasyReactiveResourceInfo.java b/independent-projects/resteasy-reactive/server/runtime/src/main/java/org/jboss/resteasy/reactive/server/spi/ResteasyReactiveResourceInfo.java index b370a8cf5a309..143269aefa619 100644 --- a/independent-projects/resteasy-reactive/server/runtime/src/main/java/org/jboss/resteasy/reactive/server/spi/ResteasyReactiveResourceInfo.java +++ b/independent-projects/resteasy-reactive/server/runtime/src/main/java/org/jboss/resteasy/reactive/server/spi/ResteasyReactiveResourceInfo.java @@ -3,7 +3,6 @@ import java.lang.annotation.Annotation; import java.lang.reflect.Method; import java.lang.reflect.Type; -import java.util.Set; import jakarta.ws.rs.container.ResourceInfo; @@ -20,8 +19,6 @@ public class ResteasyReactiveResourceInfo implements ResourceInfo { private final String name; private final Class declaringClass; private final Class[] parameterTypes; - private final Set classAnnotationNames; - private final Set methodAnnotationNames; /** * If it's non-blocking method within the runtime that won't always default to blocking */ @@ -30,27 +27,17 @@ public class ResteasyReactiveResourceInfo implements ResourceInfo { * This class name will only differ from {@link this#declaringClass} name when the {@link this#method} was inherited. */ private final String actualDeclaringClassName; - private volatile Annotation[] classAnnotations; private volatile Method method; private volatile Annotation[] annotations; private volatile Type returnType; private volatile String methodId; - @Deprecated - public ResteasyReactiveResourceInfo(String name, Class declaringClass, Class[] parameterTypes, - Set classAnnotationNames, Set methodAnnotationNames, boolean isNonBlocking) { - this(name, declaringClass, parameterTypes, classAnnotationNames, methodAnnotationNames, isNonBlocking, - declaringClass.getName()); - } - public ResteasyReactiveResourceInfo(String name, Class declaringClass, Class[] parameterTypes, - Set classAnnotationNames, Set methodAnnotationNames, boolean isNonBlocking, + boolean isNonBlocking, String actualDeclaringClassName) { this.name = name; this.declaringClass = declaringClass; this.parameterTypes = parameterTypes; - this.classAnnotationNames = classAnnotationNames; - this.methodAnnotationNames = methodAnnotationNames; this.isNonBlocking = isNonBlocking; this.actualDeclaringClassName = actualDeclaringClassName; } @@ -63,14 +50,6 @@ public Class[] getParameterTypes() { return parameterTypes; } - public Set getClassAnnotationNames() { - return classAnnotationNames; - } - - public Set getMethodAnnotationNames() { - return methodAnnotationNames; - } - public Method getMethod() { if (method == null) { synchronized (this) { @@ -89,13 +68,6 @@ public Method getMethod() { return method; } - public Annotation[] getClassAnnotations() { - if (classAnnotations == null) { - classAnnotations = declaringClass.getAnnotations(); - } - return classAnnotations; - } - public Annotation[] getAnnotations() { if (annotations == null) { getMethod();