You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@lucene.apache.org by jp...@apache.org on 2024/01/11 14:38:35 UTC

(lucene) 02/02: Avoid reset BlockDocsEnum#freqBuffer when indexHasFreq is false (#12997)

This is an automated email from the ASF dual-hosted git repository.

jpountz pushed a commit to branch branch_9x
in repository https://gitbox.apache.org/repos/asf/lucene.git

commit b516b32ba3d3c9d7d759e7bba93f02b9c56b0e8e
Author: Zhang Chao <80...@qq.com>
AuthorDate: Thu Jan 11 22:37:52 2024 +0800

    Avoid reset BlockDocsEnum#freqBuffer when indexHasFreq is false (#12997)
---
 lucene/CHANGES.txt                                                  | 2 ++
 .../org/apache/lucene/codecs/lucene99/Lucene99PostingsReader.java   | 6 +++---
 2 files changed, 5 insertions(+), 3 deletions(-)

diff --git a/lucene/CHANGES.txt b/lucene/CHANGES.txt
index 7b80d3afdbb..48c4978c9f9 100644
--- a/lucene/CHANGES.txt
+++ b/lucene/CHANGES.txt
@@ -43,6 +43,8 @@ Optimizations
 
 * GITHUB#12841: Move group-varint encoding/decoding logic to DataOutput/DataInput.  (Adrien Grand, Zhang Chao, Uwe Schindler)
 
+* GITHUB#:12997 Avoid reset BlockDocsEnum#freqBuffer when indexHasFreq is false. (Zhang Chao, Adrien Grand)
+
 Bug Fixes
 ---------------------
 * GITHUB#12866: Prevent extra similarity computation for single-level HNSW graphs. (Kaival Parikh)
diff --git a/lucene/core/src/java/org/apache/lucene/codecs/lucene99/Lucene99PostingsReader.java b/lucene/core/src/java/org/apache/lucene/codecs/lucene99/Lucene99PostingsReader.java
index 80d24917477..362fb34539e 100644
--- a/lucene/core/src/java/org/apache/lucene/codecs/lucene99/Lucene99PostingsReader.java
+++ b/lucene/core/src/java/org/apache/lucene/codecs/lucene99/Lucene99PostingsReader.java
@@ -400,9 +400,9 @@ public final class Lucene99PostingsReader extends PostingsReaderBase {
       this.needsFreq = PostingsEnum.featureRequested(flags, PostingsEnum.FREQS);
       this.isFreqsRead = true;
       if (indexHasFreq == false || needsFreq == false) {
-        for (int i = 0; i < ForUtil.BLOCK_SIZE; ++i) {
-          freqBuffer[i] = 1;
-        }
+        // Filling this buffer may not be cheap when doing primary key lookups, so we make sure to
+        // not fill more than `docFreq` entries.
+        Arrays.fill(freqBuffer, 0, Math.min(ForUtil.BLOCK_SIZE, docFreq), 1);
       }
       accum = 0;
       blockUpto = 0;