diff options
author | Jon Bratseth <bratseth@gmail.com> | 2023-03-27 22:18:23 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-03-27 22:18:23 +0200 |
commit | 8e29178b660a73b3fe5c399cb5a79186afab500c (patch) | |
tree | 565038e8b2592d1f948ca07a7bf89f3784a14268 | |
parent | ed6879e1f98c6971818c1e2a012db3bbe3b5f18a (diff) | |
parent | 922b34973e58c17f5eb292252fb887295af5ea27 (diff) |
Merge pull request #26600 from vespa-engine/balder/cache-the-compound-keys
Cache the generated temporary CompoundName keys.
-rw-r--r-- | container-search/src/main/java/com/yahoo/search/query/Ranking.java | 10 | ||||
-rw-r--r-- | container-search/src/main/java/com/yahoo/search/query/ranking/RankFeatures.java | 7 |
2 files changed, 8 insertions, 9 deletions
diff --git a/container-search/src/main/java/com/yahoo/search/query/Ranking.java b/container-search/src/main/java/com/yahoo/search/query/Ranking.java index 77c1d0aa621..e8738a19412 100644 --- a/container-search/src/main/java/com/yahoo/search/query/Ranking.java +++ b/container-search/src/main/java/com/yahoo/search/query/Ranking.java @@ -16,10 +16,7 @@ import com.yahoo.search.query.ranking.RankProperties; import com.yahoo.search.query.ranking.SoftTimeout; import com.yahoo.search.result.ErrorMessage; -import java.util.List; -import java.util.Map; import java.util.Objects; -import java.util.Optional; /** * The ranking (hit ordering) settings of a query @@ -30,8 +27,7 @@ import java.util.Optional; public class Ranking implements Cloneable { /** An alias for listing features */ - public static final com.yahoo.processing.request.CompoundName RANKFEATURES = - new com.yahoo.processing.request.CompoundName("rankfeatures"); + public static final CompoundName RANKFEATURES = new CompoundName("rankfeatures"); /** The type representing the property arguments consumed by this */ private static final QueryProfileType argumentType; @@ -291,9 +287,7 @@ public class Ranking implements Cloneable { @Override public boolean equals(Object o) { if (o == this) return true; - if( ! (o instanceof Ranking)) return false; - - Ranking other = (Ranking) o; + if( ! (o instanceof Ranking other)) return false; if ( ! QueryHelper.equals(rankProperties, other.rankProperties)) return false; if ( ! QueryHelper.equals(rankFeatures, other.rankFeatures)) return false; diff --git a/container-search/src/main/java/com/yahoo/search/query/ranking/RankFeatures.java b/container-search/src/main/java/com/yahoo/search/query/ranking/RankFeatures.java index 51be79f8c2e..f288010a633 100644 --- a/container-search/src/main/java/com/yahoo/search/query/ranking/RankFeatures.java +++ b/container-search/src/main/java/com/yahoo/search/query/ranking/RankFeatures.java @@ -1,6 +1,7 @@ // Copyright Yahoo. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. package com.yahoo.search.query.ranking; +import com.yahoo.concurrent.CopyOnWriteHashMap; import com.yahoo.fs4.MapEncoder; import com.yahoo.processing.request.CompoundName; import com.yahoo.search.query.Ranking; @@ -24,6 +25,8 @@ public class RankFeatures implements Cloneable { private final Ranking parent; private final Map<String, Object> features; + /// This caches the + private static final Map<String, CompoundName> compoundNameCache = new CopyOnWriteHashMap<>(); public RankFeatures(Ranking parent) { this(parent, new LinkedHashMap<>()); @@ -49,7 +52,9 @@ public class RankFeatures implements Cloneable { } private void verifyType(String name, Object value) { - parent.getParent().properties().requireSettable(new CompoundName(List.of("ranking", "features", name)), value, Map.of()); + parent.getParent().properties().requireSettable( + compoundNameCache.computeIfAbsent(name, (key) -> new CompoundName(List.of("ranking", "features", key))), + value, Map.of()); } /** |