From 050abe4c41ef5f345625ef0ce87d42aca792e2c3 Mon Sep 17 00:00:00 2001 From: Jordan Powers Date: Wed, 22 Oct 2025 08:28:07 -0700 Subject: [PATCH] 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 --- .../xpack/logsdb/LogsdbIndexModeSettingsProvider.java | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/x-pack/plugin/logsdb/src/main/java/org/elasticsearch/xpack/logsdb/LogsdbIndexModeSettingsProvider.java b/x-pack/plugin/logsdb/src/main/java/org/elasticsearch/xpack/logsdb/LogsdbIndexModeSettingsProvider.java index 441a3d7abec90..421ca5b5180b1 100644 --- a/x-pack/plugin/logsdb/src/main/java/org/elasticsearch/xpack/logsdb/LogsdbIndexModeSettingsProvider.java +++ b/x-pack/plugin/logsdb/src/main/java/org/elasticsearch/xpack/logsdb/LogsdbIndexModeSettingsProvider.java @@ -47,6 +47,7 @@ import java.util.Map; import java.util.Objects; import java.util.Set; +import java.util.function.Function; import java.util.function.Supplier; import java.util.stream.Collectors; import java.util.stream.Stream; @@ -61,6 +62,10 @@ final class LogsdbIndexModeSettingsProvider implements IndexSettingProvider { .stream() .flatMap(v -> Stream.of(v, "_doc." + v)) .collect(Collectors.toSet()); + private static final Function, Map> MAPPING_INCLUDES_FILTER = XContentMapValues.filter( + MAPPING_INCLUDES.toArray(String[]::new), + new String[0] + ); private final LogsdbLicenseService licenseService; private final SetOnce> mapperServiceFactory = new SetOnce<>(); @@ -264,14 +269,13 @@ MappingHints getMappingHints( // The _doc.properties.host* is needed to determine whether host.name field can be injected. // The _doc.subobjects is needed to determine whether subobjects is enabled. List filteredMappings = new ArrayList<>(combinedTemplateMappings.size()); - String[] mappingIncludesArray = MAPPING_INCLUDES.toArray(String[]::new); for (CompressedXContent mappingSource : combinedTemplateMappings) { var ref = mappingSource.compressedReference(); Map map; if (maybeUsesPatternText == false) { var fullMap = XContentHelper.convertToMap(ref, true, XContentType.JSON).v2(); maybeUsesPatternText = checkMappingForPatternText(fullMap); - map = XContentMapValues.filter(fullMap, mappingIncludesArray, new String[0]); + map = MAPPING_INCLUDES_FILTER.apply(fullMap); } else { map = XContentHelper.convertToMap(ref, true, XContentType.JSON, MAPPING_INCLUDES, Set.of()).v2(); }