Skip to content

Commit

Permalink
Get rid of unnecessary reflective calls at RESTEasy Reactive startup
Browse files Browse the repository at this point in the history
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)
  • Loading branch information
geoand committed Dec 20, 2024
1 parent 00b8eb2 commit ab710d6
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 43 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -177,19 +175,8 @@ public RuntimeResource buildResourceMethod(ResourceClass clazz,
}
}

Annotation[] resourceClassAnnotations = resourceClass.getAnnotations();
Set<String> 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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -20,8 +19,6 @@ public class ResteasyReactiveResourceInfo implements ResourceInfo {
private final String name;
private final Class<?> declaringClass;
private final Class[] parameterTypes;
private final Set<String> classAnnotationNames;
private final Set<String> methodAnnotationNames;
/**
* If it's non-blocking method within the runtime that won't always default to blocking
*/
Expand All @@ -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<String> classAnnotationNames, Set<String> methodAnnotationNames, boolean isNonBlocking) {
this(name, declaringClass, parameterTypes, classAnnotationNames, methodAnnotationNames, isNonBlocking,
declaringClass.getName());
}

public ResteasyReactiveResourceInfo(String name, Class<?> declaringClass, Class[] parameterTypes,
Set<String> classAnnotationNames, Set<String> 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;
}
Expand All @@ -63,14 +50,6 @@ public Class[] getParameterTypes() {
return parameterTypes;
}

public Set<String> getClassAnnotationNames() {
return classAnnotationNames;
}

public Set<String> getMethodAnnotationNames() {
return methodAnnotationNames;
}

public Method getMethod() {
if (method == null) {
synchronized (this) {
Expand All @@ -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();
Expand Down

0 comments on commit ab710d6

Please sign in to comment.