Reorder java-concurrent matchers

Move the expensive matcher to last.

In theory this should help, but did not seem to make a significant difference in basic startup benchmarks.
This commit is contained in:
Tyler Benson 2020-02-20 11:14:36 -08:00
parent e4a454549d
commit b80e9857d2
2 changed files with 28 additions and 27 deletions

View File

@ -102,33 +102,34 @@ public abstract class AbstractExecutorInstrumentation extends Instrumenter.Defau
@Override
public ElementMatcher<TypeDescription> typeMatcher() {
final ElementMatcher.Junction<TypeDescription> matcher =
not(isInterface()).and(safeHasInterface(named(Executor.class.getName())));
if (TRACE_ALL_EXECUTORS) {
return matcher;
ElementMatcher.Junction<TypeDescription> matcher = not(isInterface());
if (!TRACE_ALL_EXECUTORS) {
matcher =
matcher.and(
new ElementMatcher<TypeDescription>() {
@Override
public boolean matches(final TypeDescription target) {
boolean whitelisted = WHITELISTED_EXECUTORS.contains(target.getName());
// Check for possible prefixes match only if not whitelisted already
if (!whitelisted) {
for (final String name : WHITELISTED_EXECUTORS_PREFIXES) {
if (target.getName().startsWith(name)) {
whitelisted = true;
break;
}
}
}
if (!whitelisted) {
log.debug("Skipping executor instrumentation for {}", target.getName());
}
return whitelisted;
}
});
}
return matcher.and(
new ElementMatcher<TypeDescription>() {
@Override
public boolean matches(final TypeDescription target) {
boolean whitelisted = WHITELISTED_EXECUTORS.contains(target.getName());
// Check for possible prefixes match only if not whitelisted already
if (!whitelisted) {
for (final String name : WHITELISTED_EXECUTORS_PREFIXES) {
if (target.getName().startsWith(name)) {
whitelisted = true;
break;
}
}
}
if (!whitelisted) {
log.debug("Skipping executor instrumentation for {}", target.getName());
}
return whitelisted;
}
});
safeHasInterface(named(Executor.class.getName()))); // Apply expensive matcher last.
}
@Override

View File

@ -79,7 +79,6 @@ public final class FutureInstrumentation extends Instrumenter.Default {
@Override
public ElementMatcher<TypeDescription> typeMatcher() {
return not(isInterface())
.and(safeHasInterface(named(Future.class.getName())))
.and(
new ElementMatcher<TypeDescription>() {
@Override
@ -90,7 +89,8 @@ public final class FutureInstrumentation extends Instrumenter.Default {
}
return whitelisted;
}
});
})
.and(safeHasInterface(named(Future.class.getName()))); // Apply expensive matcher last.
}
@Override