Skip to content

Commit 6a134ac

Browse files
Save some duplicate Codec instances (#113783)
A couple of these can be made constants to save some footprint and indirection.
1 parent 99830f9 commit 6a134ac

File tree

2 files changed

+12
-15
lines changed

2 files changed

+12
-15
lines changed

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

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -30,30 +30,32 @@ public class Elasticsearch814Codec extends CodecService.DeduplicateFieldInfosCod
3030

3131
private final StoredFieldsFormat storedFieldsFormat;
3232

33-
private final PostingsFormat defaultPostingsFormat;
33+
private static final PostingsFormat defaultPostingsFormat = new Lucene99PostingsFormat();
3434
private final PostingsFormat postingsFormat = new PerFieldPostingsFormat() {
3535
@Override
3636
public PostingsFormat getPostingsFormatForField(String field) {
3737
return Elasticsearch814Codec.this.getPostingsFormatForField(field);
3838
}
3939
};
4040

41-
private final DocValuesFormat defaultDVFormat;
41+
private static final DocValuesFormat defaultDVFormat = new Lucene90DocValuesFormat();
4242
private final DocValuesFormat docValuesFormat = new PerFieldDocValuesFormat() {
4343
@Override
4444
public DocValuesFormat getDocValuesFormatForField(String field) {
4545
return Elasticsearch814Codec.this.getDocValuesFormatForField(field);
4646
}
4747
};
4848

49-
private final KnnVectorsFormat defaultKnnVectorsFormat;
49+
private static final KnnVectorsFormat defaultKnnVectorsFormat = new Lucene99HnswVectorsFormat();
5050
private final KnnVectorsFormat knnVectorsFormat = new PerFieldKnnVectorsFormat() {
5151
@Override
5252
public KnnVectorsFormat getKnnVectorsFormatForField(String field) {
5353
return Elasticsearch814Codec.this.getKnnVectorsFormatForField(field);
5454
}
5555
};
5656

57+
private static final Lucene99Codec lucene99Codec = new Lucene99Codec();
58+
5759
/** Public no-arg constructor, needed for SPI loading at read-time. */
5860
public Elasticsearch814Codec() {
5961
this(Zstd814StoredFieldsFormat.Mode.BEST_SPEED);
@@ -64,11 +66,8 @@ public Elasticsearch814Codec() {
6466
* worse space-efficiency or vice-versa.
6567
*/
6668
public Elasticsearch814Codec(Zstd814StoredFieldsFormat.Mode mode) {
67-
super("Elasticsearch814", new Lucene99Codec());
69+
super("Elasticsearch814", lucene99Codec);
6870
this.storedFieldsFormat = new Zstd814StoredFieldsFormat(mode);
69-
this.defaultPostingsFormat = new Lucene99PostingsFormat();
70-
this.defaultDVFormat = new Lucene90DocValuesFormat();
71-
this.defaultKnnVectorsFormat = new Lucene99HnswVectorsFormat();
7271
}
7372

7473
@Override

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

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -31,19 +31,17 @@
3131
*/
3232
public class PerFieldFormatSupplier {
3333

34-
private final MapperService mapperService;
35-
private final DocValuesFormat docValuesFormat = new Lucene90DocValuesFormat();
36-
private final KnnVectorsFormat knnVectorsFormat = new Lucene99HnswVectorsFormat();
37-
private final ES87BloomFilterPostingsFormat bloomFilterPostingsFormat;
38-
private final ES87TSDBDocValuesFormat tsdbDocValuesFormat;
34+
private static final DocValuesFormat docValuesFormat = new Lucene90DocValuesFormat();
35+
private static final KnnVectorsFormat knnVectorsFormat = new Lucene99HnswVectorsFormat();
36+
private static final ES87TSDBDocValuesFormat tsdbDocValuesFormat = new ES87TSDBDocValuesFormat();
37+
private static final ES812PostingsFormat es812PostingsFormat = new ES812PostingsFormat();
3938

40-
private final ES812PostingsFormat es812PostingsFormat;
39+
private final ES87BloomFilterPostingsFormat bloomFilterPostingsFormat;
40+
private final MapperService mapperService;
4141

4242
public PerFieldFormatSupplier(MapperService mapperService, BigArrays bigArrays) {
4343
this.mapperService = mapperService;
4444
this.bloomFilterPostingsFormat = new ES87BloomFilterPostingsFormat(bigArrays, this::internalGetPostingsFormatForField);
45-
this.tsdbDocValuesFormat = new ES87TSDBDocValuesFormat();
46-
this.es812PostingsFormat = new ES812PostingsFormat();
4745
}
4846

4947
public PostingsFormat getPostingsFormatForField(String field) {

0 commit comments

Comments
 (0)