Skip to content

Commit b7e1d01

Browse files
authored
Merge pull request quarkusio#48201 from gsmet/build-optimizations
Micro build optimizations for ArC
2 parents 2964bf4 + 5e4632e commit b7e1d01

File tree

2 files changed

+38
-6
lines changed

2 files changed

+38
-6
lines changed

independent-projects/arc/processor/src/main/java/io/quarkus/arc/processor/BeanDeployment.java

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,7 @@ public class BeanDeployment {
8989
private final List<DecoratorInfo> decorators;
9090

9191
private final List<ObserverInfo> observers;
92+
private Set<MethodInfo> observerAndProducerMethods;
9293

9394
private final Set<InvokerInfo> invokers;
9495

@@ -317,6 +318,8 @@ void init(Consumer<BytecodeTransformer> bytecodeTransformerConsumer,
317318
List<Predicate<BeanInfo>> additionalUnusedBeanExclusions) {
318319
long start = System.nanoTime();
319320

321+
initObserverAndProducerMethods(observers, beans);
322+
320323
// Collect dependency resolution errors
321324
List<Throwable> errors = new ArrayList<>();
322325
for (BeanInfo bean : beans) {
@@ -789,6 +792,15 @@ Integer computeAlternativePriority(AnnotationTarget target, List<StereotypeInfo>
789792
}
790793

791794
Set<MethodInfo> getObserverAndProducerMethods() {
795+
if (observerAndProducerMethods == null) {
796+
throw new IllegalStateException(
797+
"getObserverAndProducerMethods() has been called but observerAndProducerMethods has not been initialized yet");
798+
}
799+
800+
return observerAndProducerMethods;
801+
}
802+
803+
private void initObserverAndProducerMethods(List<ObserverInfo> observers, List<BeanInfo> beans) {
792804
Set<MethodInfo> ret = new HashSet<>();
793805
for (ObserverInfo observer : observers) {
794806
if (!observer.isSynthetic()) {
@@ -800,7 +812,8 @@ Set<MethodInfo> getObserverAndProducerMethods() {
800812
ret.add(bean.getTarget().get().asMethod());
801813
}
802814
}
803-
return ret;
815+
816+
observerAndProducerMethods = Collections.unmodifiableSet(ret);
804817
}
805818

806819
private boolean isRuntimeAnnotationType(ClassInfo annotationType) {

independent-projects/arc/processor/src/main/java/io/quarkus/arc/processor/Methods.java

Lines changed: 24 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -337,15 +337,27 @@ static class MethodKey {
337337
final List<DotName> params;
338338
final DotName returnType;
339339
final MethodInfo method; // this is intentionally ignored for equals/hashCode
340+
private final int hashCode;
340341

341342
public MethodKey(MethodInfo method) {
342343
this.method = Objects.requireNonNull(method, "Method must not be null");
343344
this.name = method.name();
344345
this.returnType = method.returnType().name();
345-
this.params = new ArrayList<>();
346-
for (Type i : method.parameterTypes()) {
347-
params.add(i.name());
348-
}
346+
this.params = switch (method.parametersCount()) {
347+
case 0 -> List.of();
348+
case 1 -> List.of(method.parameterTypes().get(0).name());
349+
case 2 -> List.of(method.parameterTypes().get(0).name(), method.parameterTypes().get(1).name());
350+
default -> {
351+
List<DotName> ret = new ArrayList<>(method.parametersCount());
352+
for (Type parameterType : method.parameterTypes()) {
353+
ret.add(parameterType.name());
354+
}
355+
yield ret;
356+
}
357+
};
358+
359+
// the Map can be resized several times so it's worth caching the hashCode
360+
this.hashCode = buildHashCode(this.name, this.params, this.returnType);
349361
}
350362

351363
@Override
@@ -362,7 +374,14 @@ public boolean equals(Object o) {
362374

363375
@Override
364376
public int hashCode() {
365-
return Objects.hash(name, params, returnType);
377+
return hashCode;
378+
}
379+
380+
private static int buildHashCode(String name, List<DotName> params, DotName returnType) {
381+
int result = Objects.hashCode(name);
382+
result = 31 * result + Objects.hashCode(params);
383+
result = 31 * result + Objects.hashCode(returnType);
384+
return result;
366385
}
367386
}
368387

0 commit comments

Comments
 (0)