Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions lucene/CHANGES.txt
Original file line number Diff line number Diff line change
Expand Up @@ -239,6 +239,8 @@ Optimizations

* GITHUB#14980: Add bulk off-heap scoring for float32 vectors (Chris Hegarty)

* GITHUB#15045: Use FixedBitSet#cardinality for counting liveDocs in CheckIndex (Zhang Chao)

Changes in Runtime Behavior
---------------------
* GITHUB#14823: Decrease TieredMergePolicy's default number of segments per
Expand Down
29 changes: 23 additions & 6 deletions lucene/core/src/java/org/apache/lucene/index/CheckIndex.java
Original file line number Diff line number Diff line change
Expand Up @@ -1297,12 +1297,7 @@ public static Status.LiveDocStatus testLiveDocs(
if (liveDocs == null) {
throw new CheckIndexException("segment should have deletions, but liveDocs is null");
} else {
int numLive = 0;
for (int j = 0; j < liveDocs.length(); j++) {
if (liveDocs.get(j)) {
numLive++;
}
}
int numLive = bitsCardinality(liveDocs);
if (numLive != numDocs) {
throw new CheckIndexException(
"liveDocs count mismatch: info=" + numDocs + ", vs bits=" + numLive);
Expand Down Expand Up @@ -1348,6 +1343,28 @@ public static Status.LiveDocStatus testLiveDocs(
return status;
}

/**
* Returns the cardinality of the given {@code Bits}.
*
* <p>This method processes bits in batches of 1024 using {@link Bits#applyMask} and {@link
* FixedBitSet#cardinality}, which is faster than checking bits one by one.
*/
static int bitsCardinality(Bits bits) {
int cardinality = 0;
FixedBitSet copy = new FixedBitSet(1024);
for (int offset = 0; offset < bits.length(); offset += copy.length()) {
int numBitsToCopy = Math.min(bits.length() - offset, copy.length());
copy.set(0, copy.length());
if (numBitsToCopy < copy.length()) {
// Clear ghost bits
copy.clear(numBitsToCopy, copy.length());
}
bits.applyMask(copy, offset);
cardinality += copy.cardinality();
}
return cardinality;
}

/** Test field infos. */
public static Status.FieldInfoStatus testFieldInfos(
CodecReader reader, PrintStream infoStream, boolean failFast) throws IOException {
Expand Down
Loading