aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJon Marius Venstad <venstad@gmail.com>2021-01-08 16:26:54 +0100
committerJon Marius Venstad <venstad@gmail.com>2021-01-08 16:26:54 +0100
commit4cd39189f1dcf1659fe689a1e6c12a504b63f4d0 (patch)
treee15f2e2a31f98b3178a6796e81a5e559be278e9b
parent81ea80ddf01ad83ca4ede591151a69265d3a2d4b (diff)
Cache compound names generated during query profile compilation
-rw-r--r--container-search/src/main/java/com/yahoo/search/query/profile/QueryProfileCompiler.java8
-rw-r--r--processing/src/main/java/com/yahoo/processing/request/CompoundName.java4
2 files changed, 8 insertions, 4 deletions
diff --git a/container-search/src/main/java/com/yahoo/search/query/profile/QueryProfileCompiler.java b/container-search/src/main/java/com/yahoo/search/query/profile/QueryProfileCompiler.java
index 38d302e4db2..b3fbc1525e6 100644
--- a/container-search/src/main/java/com/yahoo/search/query/profile/QueryProfileCompiler.java
+++ b/container-search/src/main/java/com/yahoo/search/query/profile/QueryProfileCompiler.java
@@ -11,6 +11,7 @@ import com.yahoo.search.query.profile.types.QueryProfileType;
import java.util.ArrayList;
import java.util.Collection;
+import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
@@ -48,11 +49,13 @@ public class QueryProfileCompiler {
variants.add(new DimensionBindingForPath(DimensionBinding.nullBinding, CompoundName.empty)); // if this contains no variants
log.fine(() -> "Compiling " + in + " having " + variants.size() + " variants");
+ Map<CompoundName, Map<String, CompoundName>> pathCache = new HashMap<>();
for (DimensionBindingForPath variant : variants) {
log.finer(() -> " Compiling variant " + variant);
// TODO jonmv: consider visiting with sets of bindings for each path
for (Map.Entry<String, ValueWithSource> entry : in.visitValues(variant.path(), variant.binding().getContext()).valuesWithSource().entrySet()) {
- CompoundName fullName = variant.path().append(entry.getKey());
+ CompoundName fullName = pathCache.computeIfAbsent(variant.path, path -> new HashMap<>())
+ .computeIfAbsent(entry.getKey(), variant.path::append);
Binding variantBinding = Binding.createFrom(variant.binding());
values.put(fullName, variantBinding, entry.getValue());
if (entry.getValue().isUnoverridable())
@@ -115,10 +118,11 @@ public class QueryProfileCompiler {
for (var variant : variants)
trie.add(variant);
+ // Visit all variant prefixes, grouped on path, and all their unique child bindings.
trie.forEachPrefixAndChildren((prefixes, childBindings) -> {
Set<DimensionBinding> processed = new HashSet<>();
for (DimensionBindingForPath prefix : prefixes)
- if (processed.add(prefix.binding()))
+ if (processed.add(prefix.binding())) // Only compute once for similar bindings, since path is equals.
if (hasWildcardBeforeEnd(prefix.binding()))
for (DimensionBinding childBinding : childBindings)
if (childBinding != prefix.binding()) {
diff --git a/processing/src/main/java/com/yahoo/processing/request/CompoundName.java b/processing/src/main/java/com/yahoo/processing/request/CompoundName.java
index 43cd6fdad80..7e25a649fb3 100644
--- a/processing/src/main/java/com/yahoo/processing/request/CompoundName.java
+++ b/processing/src/main/java/com/yahoo/processing/request/CompoundName.java
@@ -141,7 +141,7 @@ public final class CompoundName {
if (nameParts.length == 0) return this;
if (isEmpty()) return fromComponents(nameParts);
- List<String> newCompounds = new ArrayList<>(nameParts.length+compounds.size());
+ List<String> newCompounds = new ArrayList<>(nameParts.length + compounds.size());
newCompounds.addAll(Arrays.asList(nameParts));
newCompounds.addAll(this.compounds);
return new CompoundName(newCompounds);
@@ -193,7 +193,7 @@ public final class CompoundName {
this + "' only have " + compounds.size() + " components.");
if (n == 1) return rest();
if (compounds.size() == n) return empty;
- return rest.rest(n-1);
+ return rest.rest(n - 1);
}
/**