Skip to content

Commit

Permalink
Merge pull request quarkusio#20290 from stuartwdouglas/arc-perf
Browse files Browse the repository at this point in the history
ArC build time perf improvement
  • Loading branch information
geoand authored Sep 30, 2021
2 parents 210301e + 4162d5d commit ec0a2d0
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ public class BeanDeployment {
private final Map<DotName, StereotypeInfo> stereotypes;

private final List<BeanInfo> beans;
private volatile Map<Type, List<BeanInfo>> beansByType = null;

private final List<InterceptorInfo> interceptors;
private final List<DecoratorInfo> decorators;
Expand Down Expand Up @@ -248,6 +249,7 @@ void init(Consumer<BytecodeTransformer> bytecodeTransformerConsumer,
List<Predicate<BeanInfo>> additionalUnusedBeanExclusions) {
long start = System.nanoTime();

initBeanByTypeMap();
// Collect dependency resolution errors
List<Throwable> errors = new ArrayList<>();
for (BeanInfo bean : beans) {
Expand Down Expand Up @@ -279,11 +281,25 @@ void init(Consumer<BytecodeTransformer> bytecodeTransformerConsumer,
LOGGER.debugf("Removed %s beans, %s interceptors and %s decorators in %s ms", removedBeans.size(),
removedInterceptors.size(), removedDecorators.size(),
TimeUnit.NANOSECONDS.toMillis(System.nanoTime() - removalStart));
//we need to re-initialize it, so it does not contain removed beans
initBeanByTypeMap();
}
buildContext.putInternal(BuildExtension.Key.REMOVED_BEANS.asString(), Collections.unmodifiableSet(removedBeans));
LOGGER.debugf("Bean deployment initialized in %s ms", TimeUnit.NANOSECONDS.toMillis(System.nanoTime() - start));
}

private void initBeanByTypeMap() {
beansByType = new HashMap<>();
for (var bean : beans) {
for (var beanType : bean.types) {
beansByType.computeIfAbsent(beanType, (s) -> new ArrayList<>()).add(bean);
}
}
for (var e : beansByType.entrySet()) {
e.setValue(Collections.unmodifiableList(e.getValue()));
}
}

private void removeUnusedComponents(Set<BeanInfo> declaresObserver,
List<Predicate<BeanInfo>> allUnusedExclusions, Set<DecoratorInfo> removedDecorators,
Set<InterceptorInfo> removedInterceptors) {
Expand Down Expand Up @@ -407,6 +423,14 @@ public Collection<BeanInfo> getBeans() {
return Collections.unmodifiableList(beans);
}

public Collection<BeanInfo> getBeansByType(Type type) {
var ret = beansByType.get(type);
if (ret == null) {
return Collections.emptyList();
}
return ret;
}

public Collection<BeanInfo> getRemovedBeans() {
return Collections.unmodifiableSet(removedBeans);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@

import io.quarkus.arc.processor.InjectionPointInfo.TypeAndQualifiers;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.HashSet;
import java.util.List;
Expand Down Expand Up @@ -81,7 +82,11 @@ List<BeanInfo> resolve(TypeAndQualifiers typeAndQualifiers) {

private List<BeanInfo> findMatching(TypeAndQualifiers typeAndQualifiers) {
List<BeanInfo> resolved = new ArrayList<>();
for (BeanInfo b : beanDeployment.getBeans()) {
//optimisation for the simple class case
Collection<BeanInfo> potentialBeans = typeAndQualifiers.type.kind() == CLASS
? beanDeployment.getBeansByType(typeAndQualifiers.type)
: beanDeployment.getBeans();
for (BeanInfo b : potentialBeans) {
if (Beans.matches(b, typeAndQualifiers)) {
resolved.add(b);
}
Expand All @@ -91,7 +96,10 @@ private List<BeanInfo> findMatching(TypeAndQualifiers typeAndQualifiers) {

List<BeanInfo> findTypeMatching(Type type) {
List<BeanInfo> resolved = new ArrayList<>();
for (BeanInfo b : beanDeployment.getBeans()) {
//optimisation for the simple class case
Collection<BeanInfo> potentialBeans = type.kind() == CLASS ? beanDeployment.getBeansByType(type)
: beanDeployment.getBeans();
for (BeanInfo b : potentialBeans) {
if (Beans.matchesType(b, type)) {
resolved.add(b);
}
Expand Down

0 comments on commit ec0a2d0

Please sign in to comment.