Skip to content

Commit dd1db50

Browse files
Move calls to FeatureFlag.enabled to class-load time (#125885)
I noticed that we tend to create the flag instance and call this method everywhere. This doesn't compile the same way as a real boolean constant unless you're running with `-XX:+TrustFinalNonStaticFields`. For most of the code spots changed here that's irrelevant but at least the usage in the mapper parsing code is a little hot and gets a small speedup from this potentially. Also we're simply wasting some bytes for the static footprint of ES by using the `FeatureFlag` indirection instead of just a boolean.
1 parent b3e500f commit dd1db50

File tree

18 files changed

+70
-70
lines changed

18 files changed

+70
-70
lines changed

modules/data-streams/src/test/java/org/elasticsearch/datastreams/mapper/DataStreamTimestampFieldMapperTests.java

Lines changed: 29 additions & 29 deletions
Large diffs are not rendered by default.

server/src/internalClusterTest/java/org/elasticsearch/index/shard/SearchIdleIT.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -235,11 +235,11 @@ public void testSearchIdleStats() throws InterruptedException {
235235
}
236236

237237
public void testSearchIdleBoolQueryMatchOneIndex() throws InterruptedException {
238-
checkSearchIdleBoolQueryMatchOneIndex(IndexSettings.DOC_VALUES_SKIPPER.isEnabled());
238+
checkSearchIdleBoolQueryMatchOneIndex(IndexSettings.DOC_VALUES_SKIPPER);
239239
}
240240

241241
public void testSearchIdleBoolQueryMatchOneIndexWithDocValuesSkipper() throws InterruptedException {
242-
assumeTrue("doc values skipper feature should be enabled", IndexSettings.DOC_VALUES_SKIPPER.isEnabled());
242+
assumeTrue("doc values skipper feature should be enabled", IndexSettings.DOC_VALUES_SKIPPER);
243243
checkSearchIdleBoolQueryMatchOneIndex(false);
244244
}
245245

server/src/main/java/org/elasticsearch/cluster/metadata/DataStream.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -71,13 +71,13 @@
7171

7272
public final class DataStream implements SimpleDiffable<DataStream>, ToXContentObject, IndexAbstraction {
7373

74-
public static final FeatureFlag FAILURE_STORE_FEATURE_FLAG = new FeatureFlag("failure_store");
74+
public static final boolean FAILURE_STORE_FEATURE_FLAG = new FeatureFlag("failure_store").isEnabled();
7575
public static final TransportVersion ADDED_FAILURE_STORE_TRANSPORT_VERSION = TransportVersions.V_8_12_0;
7676
public static final TransportVersion ADDED_AUTO_SHARDING_EVENT_VERSION = TransportVersions.V_8_14_0;
7777
public static final TransportVersion ADD_DATA_STREAM_OPTIONS_VERSION = TransportVersions.V_8_16_0;
7878

7979
public static boolean isFailureStoreFeatureFlagEnabled() {
80-
return FAILURE_STORE_FEATURE_FLAG.isEnabled();
80+
return FAILURE_STORE_FEATURE_FLAG;
8181
}
8282

8383
public static final String BACKING_INDEX_PREFIX = ".ds-";

server/src/main/java/org/elasticsearch/common/settings/IndexScopedSettings.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -234,7 +234,7 @@ public final class IndexScopedSettings extends AbstractScopedSettings {
234234
)
235235
);
236236

237-
if (IndexSettings.DOC_VALUES_SKIPPER.isEnabled()) {
237+
if (IndexSettings.DOC_VALUES_SKIPPER) {
238238
settings.add(IndexSettings.USE_DOC_VALUES_SKIPPER);
239239
}
240240
BUILT_IN_INDEX_SETTINGS = Collections.unmodifiableSet(settings);

server/src/main/java/org/elasticsearch/index/IndexSettings.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -674,7 +674,7 @@ public boolean isES87TSDBCodecEnabled() {
674674
Property.Final
675675
);
676676

677-
public static final FeatureFlag DOC_VALUES_SKIPPER = new FeatureFlag("doc_values_skipper");
677+
public static final boolean DOC_VALUES_SKIPPER = new FeatureFlag("doc_values_skipper").isEnabled();
678678
public static final Setting<Boolean> USE_DOC_VALUES_SKIPPER = Setting.boolSetting(
679679
"index.mapping.use_doc_values_skipper",
680680
false,
@@ -1095,7 +1095,7 @@ public IndexSettings(final IndexMetadata indexMetadata, final Settings nodeSetti
10951095
recoverySourceEnabled = RecoverySettings.INDICES_RECOVERY_SOURCE_ENABLED_SETTING.get(nodeSettings);
10961096
recoverySourceSyntheticEnabled = DiscoveryNode.isStateless(nodeSettings) == false
10971097
&& scopedSettings.get(RECOVERY_USE_SYNTHETIC_SOURCE_SETTING);
1098-
useDocValuesSkipper = DOC_VALUES_SKIPPER.isEnabled() && scopedSettings.get(USE_DOC_VALUES_SKIPPER);
1098+
useDocValuesSkipper = DOC_VALUES_SKIPPER && scopedSettings.get(USE_DOC_VALUES_SKIPPER);
10991099
if (recoverySourceSyntheticEnabled) {
11001100
if (DiscoveryNode.isStateless(settings)) {
11011101
throw new IllegalArgumentException("synthetic recovery source is only allowed in stateful");

server/src/main/java/org/elasticsearch/index/codec/CodecService.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@
3131
*/
3232
public class CodecService implements CodecProvider {
3333

34-
public static final FeatureFlag ZSTD_STORED_FIELDS_FEATURE_FLAG = new FeatureFlag("zstd_stored_fields");
34+
public static final boolean ZSTD_STORED_FIELDS_FEATURE_FLAG = new FeatureFlag("zstd_stored_fields").isEnabled();
3535

3636
private final Map<String, Codec> codecs;
3737

@@ -47,7 +47,7 @@ public CodecService(@Nullable MapperService mapperService, BigArrays bigArrays)
4747
final var codecs = new HashMap<String, Codec>();
4848

4949
Codec legacyBestSpeedCodec = new LegacyPerFieldMapperCodec(Lucene101Codec.Mode.BEST_SPEED, mapperService, bigArrays);
50-
if (ZSTD_STORED_FIELDS_FEATURE_FLAG.isEnabled()) {
50+
if (ZSTD_STORED_FIELDS_FEATURE_FLAG) {
5151
codecs.put(DEFAULT_CODEC, new PerFieldMapperCodec(Zstd814StoredFieldsFormat.Mode.BEST_SPEED, mapperService, bigArrays));
5252
} else {
5353
codecs.put(DEFAULT_CODEC, legacyBestSpeedCodec);

server/src/main/java/org/elasticsearch/index/mapper/ObjectMapper.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@
4848
public class ObjectMapper extends Mapper {
4949
private static final Logger logger = LogManager.getLogger(ObjectMapper.class);
5050
private static final DeprecationLogger deprecationLogger = DeprecationLogger.getLogger(ObjectMapper.class);
51-
public static final FeatureFlag SUB_OBJECTS_AUTO_FEATURE_FLAG = new FeatureFlag("sub_objects_auto");
51+
public static final boolean SUB_OBJECTS_AUTO_FEATURE_FLAG = new FeatureFlag("sub_objects_auto").isEnabled();
5252
static final NodeFeature SUBOBJECTS_FALSE_MAPPING_UPDATE_FIX = new NodeFeature("mapper.subobjects_false_mapping_update_fix");
5353

5454
public static final String CONTENT_TYPE = "object";
@@ -80,7 +80,7 @@ public static Subobjects from(Object node) {
8080
if (value.equalsIgnoreCase("false")) {
8181
return DISABLED;
8282
}
83-
if (SUB_OBJECTS_AUTO_FEATURE_FLAG.isEnabled() && value.equalsIgnoreCase("auto")) {
83+
if (SUB_OBJECTS_AUTO_FEATURE_FLAG && value.equalsIgnoreCase("auto")) {
8484
return AUTO;
8585
}
8686
}

server/src/test/java/org/elasticsearch/index/codec/CodecIntegrationTests.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ public void testDefaultCodecLogsdb() {
4848
}
4949

5050
public void testDefaultCodec() {
51-
assumeTrue("Only when zstd_stored_fields feature flag is enabled", CodecService.ZSTD_STORED_FIELDS_FEATURE_FLAG.isEnabled());
51+
assumeTrue("Only when zstd_stored_fields feature flag is enabled", CodecService.ZSTD_STORED_FIELDS_FEATURE_FLAG);
5252

5353
var indexService = createIndex("index1");
5454
var storedFieldsFormat = (Zstd814StoredFieldsFormat) indexService.getShard(0)

server/src/test/java/org/elasticsearch/index/codec/CodecTests.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,14 +47,14 @@
4747
public class CodecTests extends ESTestCase {
4848

4949
public void testResolveDefaultCodecs() throws Exception {
50-
assumeTrue("Only when zstd_stored_fields feature flag is enabled", CodecService.ZSTD_STORED_FIELDS_FEATURE_FLAG.isEnabled());
50+
assumeTrue("Only when zstd_stored_fields feature flag is enabled", CodecService.ZSTD_STORED_FIELDS_FEATURE_FLAG);
5151
CodecService codecService = createCodecService();
5252
assertThat(codecService.codec("default"), instanceOf(PerFieldMapperCodec.class));
5353
assertThat(codecService.codec("default"), instanceOf(Elasticsearch900Lucene101Codec.class));
5454
}
5555

5656
public void testDefault() throws Exception {
57-
assumeTrue("Only when zstd_stored_fields feature flag is enabled", CodecService.ZSTD_STORED_FIELDS_FEATURE_FLAG.isEnabled());
57+
assumeTrue("Only when zstd_stored_fields feature flag is enabled", CodecService.ZSTD_STORED_FIELDS_FEATURE_FLAG);
5858
Codec codec = createCodecService().codec("default");
5959
assertEquals(
6060
"Zstd814StoredFieldsFormat(compressionMode=ZSTD(level=1), chunkSize=14336, maxDocsPerChunk=128, blockShift=10)",

server/src/test/java/org/elasticsearch/index/mapper/CompletionFieldMapperTests.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,7 @@ public void testPostingsFormat() throws IOException {
152152
MapperService mapperService = createMapperService(fieldMapping(this::minimalMapping));
153153
CodecService codecService = new CodecService(mapperService, BigArrays.NON_RECYCLING_INSTANCE);
154154
Codec codec = codecService.codec("default");
155-
if (CodecService.ZSTD_STORED_FIELDS_FEATURE_FLAG.isEnabled()) {
155+
if (CodecService.ZSTD_STORED_FIELDS_FEATURE_FLAG) {
156156
assertThat(codec, instanceOf(PerFieldMapperCodec.class));
157157
assertThat(((PerFieldMapperCodec) codec).getPostingsFormatForField("field"), instanceOf(latestLuceneCPClass));
158158
} else {

0 commit comments

Comments
 (0)