You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@lucene.apache.org by GitBox <gi...@apache.org> on 2021/04/21 10:04:45 UTC

[GitHub] [lucene] jpountz commented on a change in pull request #91: LUCENE-9932: Performance improvement for BKD index building

jpountz commented on a change in pull request #91:
URL: https://github.com/apache/lucene/pull/91#discussion_r617367359



##########
File path: lucene/core/src/java/org/apache/lucene/util/StableMSBRadixSorter.java
##########
@@ -0,0 +1,91 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.lucene.util;
+
+/**
+ * Stable radix sorter for variable-length strings. It has to check data beforehand to see if stable
+ * sort can be enabled or not. If not applicable, it works the same way as its parent class {@link
+ * MSBRadixSorter}.
+ *
+ * @lucene.internal
+ */
+public abstract class StableMSBRadixSorter extends MSBRadixSorter {
+
+  protected boolean useStableSort;
+
+  public StableMSBRadixSorter(int maxLength) {
+    super(maxLength);
+  }
+
+  /** Check if stable sort can be enabled or not. */
+  protected boolean isEnableStableSort(int from, int to) {
+    return false;
+  }
+
+  /**
+   * If stable sort is applicable, do some closure logic, which might update some of the internal
+   * variable.
+   */
+  protected void doClosureIfStableSortEnabled() {}
+
+  /** Assign the from-th value to to-th position in another array which used temporarily. */
+  protected void assign(int from, int to) {
+    throw new UnsupportedOperationException("not implement");
+  }
+
+  /** Finalize assign operation, to switch array. */
+  protected void finalizeAssign(int from, int to) {
+    throw new UnsupportedOperationException("not implement");
+  }
+
+  @Override
+  public void sort(int from, int to) {
+    checkRange(from, to);
+    useStableSort = isEnableStableSort(from, to);
+    if (useStableSort) {
+      doClosureIfStableSortEnabled();
+    }
+    sort(from, to, 0, 0);
+  }
+
+  @Override
+  protected void reorder(int from, int to, int[] startOffsets, int[] endOffsets, int k) {
+    if (useStableSort) {
+      stableReorder(from, to, startOffsets, endOffsets, k);
+    } else {
+      super.reorder(from, to, startOffsets, endOffsets, k);
+    }

Review comment:
       Always use stable reordering for simplicity?

##########
File path: lucene/core/src/java/org/apache/lucene/util/bkd/MutablePointsReaderUtils.java
##########
@@ -39,13 +41,23 @@
   public static void sort(
       BKDConfig config, int maxDoc, MutablePointValues reader, int from, int to) {
     final int bitsPerDocId = PackedInts.bitsRequired(maxDoc - 1);

Review comment:
       I wonder if we could check whether doc IDs are sorted right above this line, and then adapt the number of compared bytes? Then we should be able to get rid of `isEnableStableSort` and `doClosureIfStableSortEnabled`?
   
   ```suggestion
       // In the common case that index sorting is not enabled, doc IDs come in order, which enables us to check fewer bytes for sorting
       boolean sortedDocIDs = true;
       for (int i = from + 1; i < to; i++) {
         if (reader.getDocID(i - 1) > reader.getDocID(i)) {
           sortedDocIDs = false;
           break;
         }
       }
       final int bitsPerDocId = sorted ? 0 : PackedInts.bitsRequired(maxDoc - 1);
   ```

##########
File path: lucene/core/src/java/org/apache/lucene/codecs/MutablePointValues.java
##########
@@ -41,4 +41,14 @@ protected MutablePointValues() {}
 
   /** Swap the i-th and j-th values. */
   public abstract void swap(int i, int j);
+
+  /** Assign the from-th value to to-th position in another array which used temporarily. */
+  public void assign(int from, int to) {
+    throw new UnsupportedOperationException();
+  }
+
+  /** Finalize assign operation, to switch array. */
+  public void finalizeAssign(int from, int to) {
+    throw new UnsupportedOperationException();
+  }

Review comment:
       Can you make these abstract?

##########
File path: lucene/core/src/java/org/apache/lucene/util/StableMSBRadixSorter.java
##########
@@ -0,0 +1,91 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.lucene.util;
+
+/**
+ * Stable radix sorter for variable-length strings. It has to check data beforehand to see if stable
+ * sort can be enabled or not. If not applicable, it works the same way as its parent class {@link
+ * MSBRadixSorter}.
+ *
+ * @lucene.internal
+ */
+public abstract class StableMSBRadixSorter extends MSBRadixSorter {
+
+  protected boolean useStableSort;
+
+  public StableMSBRadixSorter(int maxLength) {
+    super(maxLength);
+  }
+
+  /** Check if stable sort can be enabled or not. */
+  protected boolean isEnableStableSort(int from, int to) {
+    return false;
+  }
+
+  /**
+   * If stable sort is applicable, do some closure logic, which might update some of the internal
+   * variable.
+   */
+  protected void doClosureIfStableSortEnabled() {}
+
+  /** Assign the from-th value to to-th position in another array which used temporarily. */
+  protected void assign(int from, int to) {
+    throw new UnsupportedOperationException("not implement");
+  }
+
+  /** Finalize assign operation, to switch array. */
+  protected void finalizeAssign(int from, int to) {
+    throw new UnsupportedOperationException("not implement");
+  }

Review comment:
       Can you make the two above methods abstract, since it would always be a bug to not override them?




-- 
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.

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