Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Optimization by caching the map of cache key and shouldSkip #34207

Closed
wants to merge 2 commits into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@
import java.util.ArrayList;
import java.util.Comparator;
import java.util.List;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;

import org.aopalliance.aop.Advice;
import org.aspectj.util.PartialOrder;
Expand Down Expand Up @@ -52,6 +54,7 @@ public class AspectJAwareAdvisorAutoProxyCreator extends AbstractAdvisorAutoProx

private static final Comparator<Advisor> DEFAULT_PRECEDENCE_COMPARATOR = new AspectJPrecedenceComparator();

private final Map<Object, Boolean> skippedBeans = new ConcurrentHashMap<>(256);

/**
* Sort the supplied {@link Advisor} instances according to AspectJ precedence.
Expand Down Expand Up @@ -101,15 +104,24 @@ protected void extendAdvisors(List<Advisor> candidateAdvisors) {

@Override
protected boolean shouldSkip(Class<?> beanClass, String beanName) {
// TODO: Consider optimization by caching the list of the aspect names
List<Advisor> candidateAdvisors = findCandidateAdvisors();
for (Advisor advisor : candidateAdvisors) {
if (advisor instanceof AspectJPointcutAdvisor pointcutAdvisor &&
pointcutAdvisor.getAspectName().equals(beanName)) {
return true;
Object cacheKey = getCacheKey(beanClass, beanName);

Boolean skip = this.skippedBeans.get(cacheKey);
if (skip == null) {
List<Advisor> candidateAdvisors = findCandidateAdvisors();
for (Advisor advisor : candidateAdvisors) {
if (advisor instanceof AspectJPointcutAdvisor pointcutAdvisor &&
pointcutAdvisor.getAspectName().equals(beanName)) {
skip = true;
break;
}
}
if (skip == null) {
skip = super.shouldSkip(beanClass, beanName);
}
this.skippedBeans.put(cacheKey, skip);
}
return super.shouldSkip(beanClass, beanName);
return skip;
}

@Override
Expand Down
Loading