Skip to content

Commit 17c9dc4

Browse files
Pre-compile mapping_includes filter in LogsdbIndexModeSettingsProvider (#136899)
Some recent profiling showed that compiling the mapping_includes filter in LogsdbIndexModeSettingsProvider#getMappingHints was very expensive. This PR moves that work so that it only happens once, when the class is constructed
1 parent 01380e8 commit 17c9dc4

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

x-pack/plugin/logsdb/src/main/java/org/elasticsearch/xpack/logsdb/LogsdbIndexModeSettingsProvider.java

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@
4747
import java.util.Map;
4848
import java.util.Objects;
4949
import java.util.Set;
50+
import java.util.function.Function;
5051
import java.util.function.Supplier;
5152
import java.util.stream.Collectors;
5253
import java.util.stream.Stream;
@@ -61,6 +62,10 @@ final class LogsdbIndexModeSettingsProvider implements IndexSettingProvider {
6162
.stream()
6263
.flatMap(v -> Stream.of(v, "_doc." + v))
6364
.collect(Collectors.toSet());
65+
private static final Function<Map<String, Object>, Map<String, Object>> MAPPING_INCLUDES_FILTER = XContentMapValues.filter(
66+
MAPPING_INCLUDES.toArray(String[]::new),
67+
new String[0]
68+
);
6469

6570
private final LogsdbLicenseService licenseService;
6671
private final SetOnce<CheckedFunction<IndexMetadata, MapperService, IOException>> mapperServiceFactory = new SetOnce<>();
@@ -264,14 +269,13 @@ MappingHints getMappingHints(
264269
// The _doc.properties.host* is needed to determine whether host.name field can be injected.
265270
// The _doc.subobjects is needed to determine whether subobjects is enabled.
266271
List<CompressedXContent> filteredMappings = new ArrayList<>(combinedTemplateMappings.size());
267-
String[] mappingIncludesArray = MAPPING_INCLUDES.toArray(String[]::new);
268272
for (CompressedXContent mappingSource : combinedTemplateMappings) {
269273
var ref = mappingSource.compressedReference();
270274
Map<String, Object> map;
271275
if (maybeUsesPatternText == false) {
272276
var fullMap = XContentHelper.convertToMap(ref, true, XContentType.JSON).v2();
273277
maybeUsesPatternText = checkMappingForPatternText(fullMap);
274-
map = XContentMapValues.filter(fullMap, mappingIncludesArray, new String[0]);
278+
map = MAPPING_INCLUDES_FILTER.apply(fullMap);
275279
} else {
276280
map = XContentHelper.convertToMap(ref, true, XContentType.JSON, MAPPING_INCLUDES, Set.of()).v2();
277281
}

0 commit comments

Comments
 (0)