You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@lucene.apache.org by "romseygeek (via GitHub)" <gi...@apache.org> on 2023/06/09 09:24:30 UTC

[GitHub] [lucene] romseygeek commented on a diff in pull request #12357: Better paging when random reads go backwards

romseygeek commented on code in PR #12357:
URL: https://github.com/apache/lucene/pull/12357#discussion_r1224066078


##########
lucene/core/src/java/org/apache/lucene/store/BufferedIndexInput.java:
##########
@@ -176,11 +179,17 @@ public final byte readByte(long pos) throws IOException {
   public final short readShort(long pos) throws IOException {
     long index = pos - bufferStart;
     if (index < 0 || index >= buffer.limit() - 1) {
-      bufferStart = pos;
+      // if we're moving backwards, then try and fill up the previous page rather than
+      // starting again at the current pos, to avoid successive backwards reads reloading
+      // the same data over and over again
+      bufferStart = index < 0 ? Math.min(pos, Math.max(0, bufferStart - bufferSize)) : pos;
+      if (bufferStart + bufferSize - pos <= 1) {

Review Comment:
   I've rewritten this to extract a `maybeRefillBuffer()` method that should be easier to read.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@lucene.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@lucene.apache.org
For additional commands, e-mail: issues-help@lucene.apache.org