Skip to content

Commit 35a6298

Browse files
Optimize entry maps in TSDB doc values codec (#125805)
Currently, the Lucene90DocValuesProducer uses optimized IntObjectHashMaps to track various entries for each field, while the ES87TSDBDocValuesProducer uses regular HashMap<String, Object>. This patch updates the ES87TSDBDocValuesProducer class to also use the optimized hash maps.
1 parent a02241b commit 35a6298

File tree

1 file changed

+31
-32
lines changed

1 file changed

+31
-32
lines changed

server/src/main/java/org/elasticsearch/index/codec/tsdb/ES87TSDBDocValuesProducer.java

Lines changed: 31 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
import org.apache.lucene.index.SortedNumericDocValues;
3030
import org.apache.lucene.index.SortedSetDocValues;
3131
import org.apache.lucene.index.TermsEnum;
32+
import org.apache.lucene.internal.hppc.IntObjectHashMap;
3233
import org.apache.lucene.search.DocIdSetIterator;
3334
import org.apache.lucene.store.ByteArrayDataInput;
3435
import org.apache.lucene.store.ChecksumIndexInput;
@@ -43,33 +44,31 @@
4344
import org.elasticsearch.core.IOUtils;
4445

4546
import java.io.IOException;
46-
import java.util.HashMap;
47-
import java.util.Map;
4847

4948
import static org.elasticsearch.index.codec.tsdb.ES87TSDBDocValuesFormat.SKIP_INDEX_JUMP_LENGTH_PER_LEVEL;
5049
import static org.elasticsearch.index.codec.tsdb.ES87TSDBDocValuesFormat.SKIP_INDEX_MAX_LEVEL;
5150
import static org.elasticsearch.index.codec.tsdb.ES87TSDBDocValuesFormat.TERMS_DICT_BLOCK_LZ4_SHIFT;
5251

5352
public class ES87TSDBDocValuesProducer extends DocValuesProducer {
54-
private final Map<String, NumericEntry> numerics;
55-
private final Map<String, BinaryEntry> binaries;
56-
private final Map<String, SortedEntry> sorted;
57-
private final Map<String, SortedSetEntry> sortedSets;
58-
private final Map<String, SortedNumericEntry> sortedNumerics;
59-
private final Map<String, DocValuesSkipperEntry> skippers;
53+
private final IntObjectHashMap<NumericEntry> numerics;
54+
private final IntObjectHashMap<BinaryEntry> binaries;
55+
private final IntObjectHashMap<SortedEntry> sorted;
56+
private final IntObjectHashMap<SortedSetEntry> sortedSets;
57+
private final IntObjectHashMap<SortedNumericEntry> sortedNumerics;
58+
private final IntObjectHashMap<DocValuesSkipperEntry> skippers;
6059
private final IndexInput data;
6160
private final int maxDoc;
6261
private final int version;
6362
private final boolean merging;
6463

6564
ES87TSDBDocValuesProducer(SegmentReadState state, String dataCodec, String dataExtension, String metaCodec, String metaExtension)
6665
throws IOException {
67-
this.numerics = new HashMap<>();
68-
this.binaries = new HashMap<>();
69-
this.sorted = new HashMap<>();
70-
this.sortedSets = new HashMap<>();
71-
this.sortedNumerics = new HashMap<>();
72-
this.skippers = new HashMap<>();
66+
this.numerics = new IntObjectHashMap<>();
67+
this.binaries = new IntObjectHashMap<>();
68+
this.sorted = new IntObjectHashMap<>();
69+
this.sortedSets = new IntObjectHashMap<>();
70+
this.sortedNumerics = new IntObjectHashMap<>();
71+
this.skippers = new IntObjectHashMap<>();
7372
this.maxDoc = state.segmentInfo.maxDoc();
7473
this.merging = false;
7574

@@ -130,12 +129,12 @@ public class ES87TSDBDocValuesProducer extends DocValuesProducer {
130129
}
131130

132131
private ES87TSDBDocValuesProducer(
133-
Map<String, NumericEntry> numerics,
134-
Map<String, BinaryEntry> binaries,
135-
Map<String, SortedEntry> sorted,
136-
Map<String, SortedSetEntry> sortedSets,
137-
Map<String, SortedNumericEntry> sortedNumerics,
138-
Map<String, DocValuesSkipperEntry> skippers,
132+
IntObjectHashMap<NumericEntry> numerics,
133+
IntObjectHashMap<BinaryEntry> binaries,
134+
IntObjectHashMap<SortedEntry> sorted,
135+
IntObjectHashMap<SortedSetEntry> sortedSets,
136+
IntObjectHashMap<SortedNumericEntry> sortedNumerics,
137+
IntObjectHashMap<DocValuesSkipperEntry> skippers,
139138
IndexInput data,
140139
int maxDoc,
141140
int version,
@@ -160,13 +159,13 @@ public DocValuesProducer getMergeInstance() {
160159

161160
@Override
162161
public NumericDocValues getNumeric(FieldInfo field) throws IOException {
163-
NumericEntry entry = numerics.get(field.name);
162+
NumericEntry entry = numerics.get(field.number);
164163
return getNumeric(entry, -1);
165164
}
166165

167166
@Override
168167
public BinaryDocValues getBinary(FieldInfo field) throws IOException {
169-
BinaryEntry entry = binaries.get(field.name);
168+
BinaryEntry entry = binaries.get(field.number);
170169
if (entry.docsWithFieldOffset == -2) {
171170
return DocValues.emptyBinary();
172171
}
@@ -320,7 +319,7 @@ public boolean advanceExact(int target) throws IOException {
320319

321320
@Override
322321
public SortedDocValues getSorted(FieldInfo field) throws IOException {
323-
SortedEntry entry = sorted.get(field.name);
322+
SortedEntry entry = sorted.get(field.number);
324323
return getSorted(entry);
325324
}
326325

@@ -675,13 +674,13 @@ public int docFreq() throws IOException {
675674

676675
@Override
677676
public SortedNumericDocValues getSortedNumeric(FieldInfo field) throws IOException {
678-
SortedNumericEntry entry = sortedNumerics.get(field.name);
677+
SortedNumericEntry entry = sortedNumerics.get(field.number);
679678
return getSortedNumeric(entry, -1);
680679
}
681680

682681
@Override
683682
public SortedSetDocValues getSortedSet(FieldInfo field) throws IOException {
684-
SortedSetEntry entry = sortedSets.get(field.name);
683+
SortedSetEntry entry = sortedSets.get(field.number);
685684
if (entry.singleValueEntry != null) {
686685
return DocValues.singleton(getSorted(entry.singleValueEntry));
687686
}
@@ -743,7 +742,7 @@ public long cost() {
743742

744743
@Override
745744
public DocValuesSkipper getSkipper(FieldInfo field) throws IOException {
746-
final DocValuesSkipperEntry entry = skippers.get(field.name);
745+
final DocValuesSkipperEntry entry = skippers.get(field.number);
747746

748747
final IndexInput input = data.slice("doc value skipper", entry.offset, entry.length);
749748
// Prefetch the first page of data. Following pages are expected to get prefetched through
@@ -869,18 +868,18 @@ private void readFields(IndexInput meta, FieldInfos infos) throws IOException {
869868
}
870869
byte type = meta.readByte();
871870
if (info.docValuesSkipIndexType() != DocValuesSkipIndexType.NONE) {
872-
skippers.put(info.name, readDocValueSkipperMeta(meta));
871+
skippers.put(info.number, readDocValueSkipperMeta(meta));
873872
}
874873
if (type == ES87TSDBDocValuesFormat.NUMERIC) {
875-
numerics.put(info.name, readNumeric(meta));
874+
numerics.put(info.number, readNumeric(meta));
876875
} else if (type == ES87TSDBDocValuesFormat.BINARY) {
877-
binaries.put(info.name, readBinary(meta));
876+
binaries.put(info.number, readBinary(meta));
878877
} else if (type == ES87TSDBDocValuesFormat.SORTED) {
879-
sorted.put(info.name, readSorted(meta));
878+
sorted.put(info.number, readSorted(meta));
880879
} else if (type == ES87TSDBDocValuesFormat.SORTED_SET) {
881-
sortedSets.put(info.name, readSortedSet(meta));
880+
sortedSets.put(info.number, readSortedSet(meta));
882881
} else if (type == ES87TSDBDocValuesFormat.SORTED_NUMERIC) {
883-
sortedNumerics.put(info.name, readSortedNumeric(meta));
882+
sortedNumerics.put(info.number, readSortedNumeric(meta));
884883
} else {
885884
throw new CorruptIndexException("invalid type: " + type, meta);
886885
}

0 commit comments

Comments
 (0)