Skip to content

Commit

Permalink
atlas: reduce amount of tag traversal (#1149)
Browse files Browse the repository at this point in the history
Update QueryIndex.forEachMatch to use the proper position
when calling sub-trees. This reduces the need to reprocess
earlier positions in the tags list that will not match.
  • Loading branch information
brharrington authored Aug 2, 2024
1 parent b050f12 commit b9630ce
Showing 1 changed file with 5 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -383,12 +383,13 @@ private void forEachMatch(Id tags, int i, Consumer<T> consumer) {
String v = tags.getValue(j);
int cmp = compare(k, keyRef);
if (cmp == 0) {
final int nextPos = j + 1;
keyPresent = true;

// Find exact matches
QueryIndex<T> eqIdx = equalChecks.get(v);
if (eqIdx != null) {
eqIdx.forEachMatch(tags, i + 1, consumer);
eqIdx.forEachMatch(tags, nextPos, consumer);
}

// Scan for matches with other conditions
Expand All @@ -403,7 +404,7 @@ private void forEachMatch(Id tags, int i, Consumer<T> consumer) {
QueryIndex<T> idx = otherChecks.get(kq);
if (idx != null) {
tmp.add(idx);
idx.forEachMatch(tags, i + 1, consumer);
idx.forEachMatch(tags, nextPos, consumer);
}
}
});
Expand All @@ -414,14 +415,14 @@ private void forEachMatch(Id tags, int i, Consumer<T> consumer) {
// size/get avoids the allocation and has better throughput.
int n = otherMatches.size();
for (int p = 0; p < n; ++p) {
otherMatches.get(p).forEachMatch(tags, i + 1, consumer);
otherMatches.get(p).forEachMatch(tags, nextPos, consumer);
}
}

// Check matches for has key
final QueryIndex<T> hasKeyIdxRef = hasKeyIdx;
if (hasKeyIdxRef != null) {
hasKeyIdxRef.forEachMatch(tags, i, consumer);
hasKeyIdxRef.forEachMatch(tags, j, consumer);
}
}

Expand Down

0 comments on commit b9630ce

Please sign in to comment.