Added arch specific write int/long

This commit is contained in:
expani 2024-12-02 15:29:29 +05:30
parent 702580a96d
commit 11821194ee
2 changed files with 22 additions and 10 deletions

View File

@ -204,11 +204,6 @@ public class DocIdEncodingBenchmark {
.toList(); .toList();
} }
public static DocIdEncoder fromClazz(Class<? extends DocIdEncoder> clazz) {
String parsedEncoderName = parsedClazzName(clazz);
return getInternal(parsedEncoderName);
}
private static DocIdEncoder getInternal(String parsedEncoderName) { private static DocIdEncoder getInternal(String parsedEncoderName) {
if (ENCODER_NAME_TO_INSTANCE_MAPPING.containsKey(parsedEncoderName)) { if (ENCODER_NAME_TO_INSTANCE_MAPPING.containsKey(parsedEncoderName)) {
return ENCODER_NAME_TO_INSTANCE_MAPPING.get(parsedEncoderName); return ENCODER_NAME_TO_INSTANCE_MAPPING.get(parsedEncoderName);
@ -493,6 +488,10 @@ public class DocIdEncodingBenchmark {
} }
} }
/**
* Last fallback in org.apache.lucene.util.bkd.DocIdsWriter#writeDocIds() when no optimisation
* works
*/
class Bit32Encoder implements DocIdEncoder { class Bit32Encoder implements DocIdEncoder {
@Override @Override
@ -510,6 +509,7 @@ public class DocIdEncodingBenchmark {
} }
} }
/** Variation of @{@link Bit32Encoder} using readLong and writeLong methods. */
class Bit32OnlyRWLongEncoder implements DocIdEncoder { class Bit32OnlyRWLongEncoder implements DocIdEncoder {
@Override @Override

View File

@ -121,7 +121,7 @@ final class DocIdsWriter {
out.writeByte(BPV_21); out.writeByte(BPV_21);
int i = 0; int i = 0;
// See // See
// @org.apache.lucene.benchmark.jmh.DocIdEncodingBenchmark.DocIdEncoder.Bit21With3StepsEncoder // @org.apache.lucene.benchmark.jmh.DocIdEncodingBenchmark$DocIdEncoder$Bit21With3StepsEncoder
if (!IS_ARCH_64) { if (!IS_ARCH_64) {
for (; i < count - 8; i += 9) { for (; i < count - 8; i += 9) {
long l1 = long l1 =
@ -148,9 +148,15 @@ final class DocIdsWriter {
| (docIds[i + 2] & BPV_21_MASK); | (docIds[i + 2] & BPV_21_MASK);
out.writeLong(packedLong); out.writeLong(packedLong);
} }
if (IS_ARCH_64) {
for (; i < count; i++) { for (; i < count; i++) {
out.writeInt(docIds[i]); out.writeInt(docIds[i]);
} }
} else {
for (; i < count; i++) {
out.writeLong(docIds[i]);
}
}
} else if (max <= 0xFFFFFF) { } else if (max <= 0xFFFFFF) {
out.writeByte(BPV_24); out.writeByte(BPV_24);
// write them the same way we are reading them. // write them the same way we are reading them.
@ -332,9 +338,15 @@ final class DocIdsWriter {
docIDs[i + 1] = (int) ((packedLong >>> 21) & BPV_21_MASK); docIDs[i + 1] = (int) ((packedLong >>> 21) & BPV_21_MASK);
docIDs[i + 2] = (int) (packedLong & BPV_21_MASK); docIDs[i + 2] = (int) (packedLong & BPV_21_MASK);
} }
if (IS_ARCH_64) {
for (; i < count; i++) { for (; i < count; i++) {
docIDs[i] = in.readInt(); docIDs[i] = in.readInt();
} }
} else {
for (; i < count; i++) {
docIDs[i] = (int) in.readLong();
}
}
} }
private static void readInts24(IndexInput in, int count, int[] docIDs) throws IOException { private static void readInts24(IndexInput in, int count, int[] docIDs) throws IOException {