Skip to content

Commit

Permalink
Optimize IndexTemplateRegistry#clusterChanged (#115347)
Browse files Browse the repository at this point in the history
  • Loading branch information
joegallo authored Oct 22, 2024
1 parent 47c4909 commit ee51f5f
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@
import org.elasticsearch.xcontent.XContentParser;

import java.io.IOException;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Map;
import java.util.Objects;
Expand Down Expand Up @@ -189,9 +191,14 @@ public List<String> getRequiredComponentTemplates() {
if (ignoreMissingComponentTemplates == null) {
return componentTemplates;
}
return componentTemplates.stream()
.filter(componentTemplate -> ignoreMissingComponentTemplates.contains(componentTemplate) == false)
.toList();
// note: this loop is unrolled rather than streaming-style because it's hot enough to show up in a flamegraph
List<String> required = new ArrayList<>(componentTemplates.size());
for (String template : componentTemplates) {
if (ignoreMissingComponentTemplates.contains(template) == false) {
required.add(template);
}
}
return Collections.unmodifiableList(required);
}

@Nullable
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
import java.io.IOException;
import java.util.Collections;
import java.util.EnumSet;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
Expand Down Expand Up @@ -92,10 +93,13 @@ public OperationMode getOperationMode() {
}

public Map<String, LifecyclePolicy> getPolicies() {
return policyMetadatas.values()
.stream()
.map(LifecyclePolicyMetadata::getPolicy)
.collect(Collectors.toMap(LifecyclePolicy::getName, Function.identity()));
// note: this loop is unrolled rather than streaming-style because it's hot enough to show up in a flamegraph
Map<String, LifecyclePolicy> policies = new HashMap<>(policyMetadatas.size());
for (LifecyclePolicyMetadata policyMetadata : policyMetadatas.values()) {
LifecyclePolicy policy = policyMetadata.getPolicy();
policies.put(policy.getName(), policy);
}
return Collections.unmodifiableMap(policies);
}

@Override
Expand Down

0 comments on commit ee51f5f

Please sign in to comment.