Skip to content

Commit

Permalink
Save some duplicate Codec instances (#113783)
Browse files Browse the repository at this point in the history
A couple of these can be made constants to save some footprint and
indirection.
  • Loading branch information
original-brownbear committed Sep 30, 2024
1 parent 99830f9 commit 6a134ac
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -30,30 +30,32 @@ public class Elasticsearch814Codec extends CodecService.DeduplicateFieldInfosCod

private final StoredFieldsFormat storedFieldsFormat;

private final PostingsFormat defaultPostingsFormat;
private static final PostingsFormat defaultPostingsFormat = new Lucene99PostingsFormat();
private final PostingsFormat postingsFormat = new PerFieldPostingsFormat() {
@Override
public PostingsFormat getPostingsFormatForField(String field) {
return Elasticsearch814Codec.this.getPostingsFormatForField(field);
}
};

private final DocValuesFormat defaultDVFormat;
private static final DocValuesFormat defaultDVFormat = new Lucene90DocValuesFormat();
private final DocValuesFormat docValuesFormat = new PerFieldDocValuesFormat() {
@Override
public DocValuesFormat getDocValuesFormatForField(String field) {
return Elasticsearch814Codec.this.getDocValuesFormatForField(field);
}
};

private final KnnVectorsFormat defaultKnnVectorsFormat;
private static final KnnVectorsFormat defaultKnnVectorsFormat = new Lucene99HnswVectorsFormat();
private final KnnVectorsFormat knnVectorsFormat = new PerFieldKnnVectorsFormat() {
@Override
public KnnVectorsFormat getKnnVectorsFormatForField(String field) {
return Elasticsearch814Codec.this.getKnnVectorsFormatForField(field);
}
};

private static final Lucene99Codec lucene99Codec = new Lucene99Codec();

/** Public no-arg constructor, needed for SPI loading at read-time. */
public Elasticsearch814Codec() {
this(Zstd814StoredFieldsFormat.Mode.BEST_SPEED);
Expand All @@ -64,11 +66,8 @@ public Elasticsearch814Codec() {
* worse space-efficiency or vice-versa.
*/
public Elasticsearch814Codec(Zstd814StoredFieldsFormat.Mode mode) {
super("Elasticsearch814", new Lucene99Codec());
super("Elasticsearch814", lucene99Codec);
this.storedFieldsFormat = new Zstd814StoredFieldsFormat(mode);
this.defaultPostingsFormat = new Lucene99PostingsFormat();
this.defaultDVFormat = new Lucene90DocValuesFormat();
this.defaultKnnVectorsFormat = new Lucene99HnswVectorsFormat();
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,19 +31,17 @@
*/
public class PerFieldFormatSupplier {

private final MapperService mapperService;
private final DocValuesFormat docValuesFormat = new Lucene90DocValuesFormat();
private final KnnVectorsFormat knnVectorsFormat = new Lucene99HnswVectorsFormat();
private final ES87BloomFilterPostingsFormat bloomFilterPostingsFormat;
private final ES87TSDBDocValuesFormat tsdbDocValuesFormat;
private static final DocValuesFormat docValuesFormat = new Lucene90DocValuesFormat();
private static final KnnVectorsFormat knnVectorsFormat = new Lucene99HnswVectorsFormat();
private static final ES87TSDBDocValuesFormat tsdbDocValuesFormat = new ES87TSDBDocValuesFormat();
private static final ES812PostingsFormat es812PostingsFormat = new ES812PostingsFormat();

private final ES812PostingsFormat es812PostingsFormat;
private final ES87BloomFilterPostingsFormat bloomFilterPostingsFormat;
private final MapperService mapperService;

public PerFieldFormatSupplier(MapperService mapperService, BigArrays bigArrays) {
this.mapperService = mapperService;
this.bloomFilterPostingsFormat = new ES87BloomFilterPostingsFormat(bigArrays, this::internalGetPostingsFormatForField);
this.tsdbDocValuesFormat = new ES87TSDBDocValuesFormat();
this.es812PostingsFormat = new ES812PostingsFormat();
}

public PostingsFormat getPostingsFormatForField(String field) {
Expand Down

0 comments on commit 6a134ac

Please sign in to comment.