diff options
author | Henning Baldersheim <balder@yahoo-inc.com> | 2021-09-03 14:37:14 +0200 |
---|---|---|
committer | Henning Baldersheim <balder@yahoo-inc.com> | 2021-09-03 14:37:14 +0200 |
commit | 2a7ebcb8f74d63d1de11c1ccb85b7bcc3429b258 (patch) | |
tree | 15454999149d1ac476ff77e447fd1cad4e6748f5 /config-model | |
parent | 3b64158f77d12a08061638e57eddf2891465f77b (diff) |
In order to avoid the quadratic cost of creating a new functions map detect when the
underlying map has changed, and then you take a new snapshot.
Diffstat (limited to 'config-model')
-rw-r--r-- | config-model/src/main/java/com/yahoo/searchdefinition/RankProfile.java | 14 |
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; } |