Skip to content

Commit ec51cba

Browse files
Speedup reading ClusterFeatures from the wire (#112492)
This shows up as rather heavy at times, we can speed it up by skipping collecting the temporary map and reading the lookup into an array instead of a list.
1 parent 435df33 commit ec51cba

File tree

1 file changed

+3
-4
lines changed

1 file changed

+3
-4
lines changed

server/src/main/java/org/elasticsearch/cluster/ClusterFeatures.java

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -140,11 +140,10 @@ private static void writeCanonicalSets(StreamOutput out, Map<String, Set<String>
140140
out.writeMap(nodeFeatureSetIndexes, StreamOutput::writeVInt);
141141
}
142142

143+
@SuppressWarnings("unchecked")
143144
private static Map<String, Set<String>> readCanonicalSets(StreamInput in) throws IOException {
144-
List<Set<String>> featureSets = in.readCollectionAsList(i -> i.readCollectionAsImmutableSet(StreamInput::readString));
145-
Map<String, Integer> nodeIndexes = in.readMap(StreamInput::readVInt);
146-
147-
return nodeIndexes.entrySet().stream().collect(Collectors.toUnmodifiableMap(Map.Entry::getKey, e -> featureSets.get(e.getValue())));
145+
Set<String>[] featureSets = in.readArray(i -> i.readCollectionAsImmutableSet(StreamInput::readString), Set[]::new);
146+
return in.readImmutableMap(streamInput -> featureSets[streamInput.readVInt()]);
148147
}
149148

150149
public static ClusterFeatures readFrom(StreamInput in) throws IOException {

0 commit comments

Comments
 (0)