You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@sis.apache.org by de...@apache.org on 2020/12/26 14:31:14 UTC
[sis] 02/02: Avoid the call to `Arrays.binarySearch(…)`. It has been identified by profiling as a performance bottleneck (in the context of `Isolines`).
This is an automated email from the ASF dual-hosted git repository.
desruisseaux pushed a commit to branch geoapi-4.0
in repository https://gitbox.apache.org/repos/asf/sis.git
commit 11c6b74bf448ebc5c2e32fa2afca95f8f274798d
Author: Martin Desruisseaux <ma...@geomatys.com>
AuthorDate: Sat Dec 26 15:28:33 2020 +0100
Avoid the call to `Arrays.binarySearch(…)`. It has been identified by profiling as a performance bottleneck (in the context of `Isolines`).
---
.../internal/processing/image/IsolineTracer.java | 2 +-
.../sis/internal/processing/image/Isolines.java | 23 ++++++----------------
2 files changed, 7 insertions(+), 18 deletions(-)
diff --git a/core/sis-feature/src/main/java/org/apache/sis/internal/processing/image/IsolineTracer.java b/core/sis-feature/src/main/java/org/apache/sis/internal/processing/image/IsolineTracer.java
index 8f8f1c4..e42e362 100644
--- a/core/sis-feature/src/main/java/org/apache/sis/internal/processing/image/IsolineTracer.java
+++ b/core/sis-feature/src/main/java/org/apache/sis/internal/processing/image/IsolineTracer.java
@@ -103,7 +103,7 @@ final class IsolineTracer {
*/
final class Level {
/**
- * The level value. This is a copy of {@link Isolines#levelValues} at the index of this level.
+ * The level value.
*
* @see #interpolate(int, int)
*/
diff --git a/core/sis-feature/src/main/java/org/apache/sis/internal/processing/image/Isolines.java b/core/sis-feature/src/main/java/org/apache/sis/internal/processing/image/Isolines.java
index 5f359e2..e1c6443 100644
--- a/core/sis-feature/src/main/java/org/apache/sis/internal/processing/image/Isolines.java
+++ b/core/sis-feature/src/main/java/org/apache/sis/internal/processing/image/Isolines.java
@@ -53,17 +53,7 @@ import static org.apache.sis.internal.processing.image.IsolineTracer.LOWER_RIGHT
*/
public final class Isolines {
/**
- * Values for which to compute isolines, sorted in ascending order and without NaN values.
- * This array is used for {@linkplain Arrays#binarySearch(double[], double) binary searches}.
- * Each value is associated to an instance in the {@link #levels} array.
- *
- * @see IsolineTracer.Level#value
- */
- private final double[] levelValues;
-
- /**
- * Isoline data for each level.
- * The length of this array is equal to the {@link #levelValues} array length.
+ * Isoline data for each level, sorted in ascending order of {@link IsolineTracer.Level#value}.
*/
private final IsolineTracer.Level[] levels;
@@ -82,10 +72,9 @@ public final class Isolines {
System.arraycopy(values, i, values, i-1, n-- - i);
}
}
- levelValues = ArraysExt.resize(values, n);
levels = new IsolineTracer.Level[n];
for (int i=0; i<n; i++) {
- levels[i] = tracer.new Level(levelValues[i], width);
+ levels[i] = tracer.new Level(values[i], width);
}
}
@@ -112,10 +101,10 @@ public final class Isolines {
* {@value IsolineTracer#LOWER_LEFT} or {@value IsolineTracer#LOWER_RIGHT}.
*/
private void setMaskBit(final DoubleBuffer data, final int bit) {
- int i = Arrays.binarySearch(levelValues, data.get());
- if (i < 0) i = ~i; // Really tild, not minus.
- while (--i >= 0) { // Value is higher than all levels below `i`.
- levels[i].isDataAbove |= bit;
+ final double value = data.get();
+ for (final IsolineTracer.Level level : levels) {
+ if (level.value > value) break; // See above javadoc for NaN handling.
+ level.isDataAbove |= bit;
}
}