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:20:04 UTC

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

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



##########
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:
       Good catch. If I override the method, then the parent class will use stable reorder. Interestingly, I found non-stable sorting runs faster accidentally (I debug the whole day :joy:). So to make the behavior work as expected, I update the code in such way.




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