mikemccand commented on code in PR #12653: URL: https://github.com/apache/lucene/pull/12653#discussion_r1364204027
########## lucene/core/src/java/org/apache/lucene/codecs/MultiLevelSkipListWriter.java: ########## @@ -63,24 +63,23 @@ public abstract class MultiLevelSkipListWriter { /** for every skip level a different buffer is used */ private ByteBuffersDataOutput[] skipBuffer; + /** Length of the window at which the skips are placed on skip level 1 */ + private final long windowLength; + /** Creates a {@code MultiLevelSkipListWriter}. */ protected MultiLevelSkipListWriter( int skipInterval, int skipMultiplier, int maxSkipLevels, int df) { this.skipInterval = skipInterval; this.skipMultiplier = skipMultiplier; - int numberOfSkipLevels; + int numberOfSkipLevels = 1; // calculate the maximum number of skip levels for this document frequency - if (df <= skipInterval) { - numberOfSkipLevels = 1; - } else { - numberOfSkipLevels = 1 + MathUtil.log(df / skipInterval, skipMultiplier); - } - - // make sure it does not exceed maxSkipLevels - if (numberOfSkipLevels > maxSkipLevels) { - numberOfSkipLevels = maxSkipLevels; + if (df > skipInterval) { + // also make sure it does not exceed maxSkipLevels + numberOfSkipLevels = + Math.min(1 + MathUtil.log(df / skipInterval, skipMultiplier), maxSkipLevels); } Review Comment: Could we move the `numberOfSkiLevels = 1` onto an `else` clause here? ########## lucene/core/src/java/org/apache/lucene/codecs/MultiLevelSkipListWriter.java: ########## @@ -130,12 +129,14 @@ public void bufferSkip(int df) throws IOException { assert df % skipInterval == 0; int numLevels = 1; - df /= skipInterval; - - // determine max level - while ((df % skipMultiplier) == 0 && numLevels < numberOfSkipLevels) { + if (df % windowLength == 0) { Review Comment: So this optimizes for the common case when `numLevels` will be `1`, right? It does a single modulo check to catch that case, and only if `numLevels` will be > 1 does it fall into the `while` loop case. Maybe add some comments explaining this? Perhaps even the beautiful ascii art you put in the opening description? -- 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-unsubscr...@lucene.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org --------------------------------------------------------------------- To unsubscribe, e-mail: issues-unsubscr...@lucene.apache.org For additional commands, e-mail: issues-h...@lucene.apache.org