Skip to content

Commit

Permalink
Optimize memoizer to avoid touching thread-local unless necessary
Browse files Browse the repository at this point in the history
  • Loading branch information
mcculls committed Apr 28, 2023
1 parent 74f470d commit aa41c87
Showing 1 changed file with 22 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -144,22 +144,38 @@ static final class MemoizingMatcher

@Override
protected boolean doMatch(TypeDescription target) {
if ("java.lang.Object".equals(target.getName()) || target.isPrimitive()) {
return false;
} else if (NoMatchFilter.contains(target.getName())) {
String targetName = target.getName();
if (NoMatchFilter.contains(targetName)
|| "java.lang.Object".equals(targetName)
|| target.isPrimitive()) {
return false;
}

BitSet memo;
SharedTypeInfo<BitSet> sharedMemo = memos.find(targetName);
if (null != sharedMemo) {
memo = sharedMemo.get();
} else {
return doMemoize(target, localMemosHolder.get()).get(matcherId);
memo = doMemoize(target, localMemosHolder.get());
}
return memo.get(matcherId);
}
}

static BitSet memoizeHierarchy(TypeDescription target, Map<String, BitSet> localMemos) {
if (NoMatchFilter.contains(target.getName())) {
String targetName = target.getName();
if (NoMatchFilter.contains(targetName)) {
return NO_MATCH;
}

BitSet memo;
SharedTypeInfo<BitSet> sharedMemo = memos.find(targetName);
if (null != sharedMemo) {
memo = sharedMemo.get();
} else {
return doMemoize(target, localMemos);
memo = doMemoize(target, localMemos);
}
return memo;
}

static BitSet doMemoize(TypeDescription target, Map<String, BitSet> localMemos) {
Expand All @@ -170,11 +186,6 @@ static BitSet doMemoize(TypeDescription target, Map<String, BitSet> localMemos)
return memo; // short-circuit circular references
}

SharedTypeInfo<BitSet> sharedMemo = memos.find(targetName);
if (null != sharedMemo) {
return sharedMemo.get();
}

localMemos.put(targetName, memo = new BitSet(matchers.size()));
boolean wasFullParsing = TypePoolFacade.disableFullDescriptions(); // only need outlines here
try {
Expand Down

0 comments on commit aa41c87

Please sign in to comment.