aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJon Bratseth <bratseth@oath.com>2021-09-03 15:03:49 +0200
committerGitHub <noreply@github.com>2021-09-03 15:03:49 +0200
commit525f577d12814f5eaad1633d7808968729bd7bbe (patch)
tree15454999149d1ac476ff77e447fd1cad4e6748f5
parent3b64158f77d12a08061638e57eddf2891465f77b (diff)
parent2a7ebcb8f74d63d1de11c1ccb85b7bcc3429b258 (diff)
Merge pull request #18968 from vespa-engine/balder/avoid-computing-new-functions-list-in-the-inner-loop
In order to avoid the quadratic cost of creating a new functions map …
-rw-r--r--config-model/src/main/java/com/yahoo/searchdefinition/RankProfile.java14
1 files changed, 13 insertions, 1 deletions
diff --git a/config-model/src/main/java/com/yahoo/searchdefinition/RankProfile.java b/config-model/src/main/java/com/yahoo/searchdefinition/RankProfile.java
index b9e241a06e4..b6dde58fff0 100644
--- a/config-model/src/main/java/com/yahoo/searchdefinition/RankProfile.java
+++ b/config-model/src/main/java/com/yahoo/searchdefinition/RankProfile.java
@@ -623,6 +623,12 @@ public class RankProfile implements Cloneable {
return Collections.unmodifiableMap(allFunctions);
}
+ private int getNumFunctions() {
+ if (getInherited() != null)
+ return functions.size() + getInherited().getNumFunctions();
+ return functions.size();
+ }
+
public int getKeepRankCount() {
if (keepRankCount >= 0) return keepRankCount;
if (getInherited() != null) return getInherited().getKeepRankCount();
@@ -776,11 +782,17 @@ public class RankProfile implements Cloneable {
// Compile all functions. Why iterate in such a complicated way?
// Because some functions (imported models adding generated macros) may add other functions during compiling.
// A straightforward iteration will either miss those functions, or may cause a ConcurrentModificationException
- while (null != (entry = findUncompiledFunction(functions.get(), compiledFunctions.keySet()))) {
+ Map<String, RankingExpressionFunction> currentFunctions = functions.get();
+ int currentCountOfAllFunctions = getNumFunctions();
+ while (null != (entry = findUncompiledFunction(currentFunctions, compiledFunctions.keySet()))) {
RankingExpressionFunction rankingExpressionFunction = entry.getValue();
RankingExpressionFunction compiled = compile(rankingExpressionFunction, queryProfiles, featureTypes,
importedModels, getConstants(), inlineFunctions, expressionTransforms);
compiledFunctions.put(entry.getKey(), compiled);
+ if (getNumFunctions() > currentCountOfAllFunctions) {
+ currentCountOfAllFunctions = getNumFunctions();
+ currentFunctions = functions.get();
+ }
}
return compiledFunctions;
}