Skip to content

Commit 48424b0

Browse files
authored
Work on Column performance (#13074)
Following the hit from adding progress logging attempting to improve it. - Only do a progress message every 50,000 rows (still probably too frequent). - Tuned `ProgressHandler` to count down to avoid any division in step check. - Separated the specialized iterators from standard java iterators on `Storage`, making it clearer to see when using them. - Removed the `zip` method from primitive iterators as when testing found for loop accessing boxed values was significantly quicker. - Tuned map and build to have two cleaner and simpler methods - one preserving nulls and one passing nulls. Boxed was slower than primitive in testing here. **Running Perf test on develop and this to compare results.**
1 parent 59eb1f2 commit 48424b0

20 files changed

+359
-479
lines changed

std-bits/table/src/main/java/org/enso/table/data/column/operation/StorageIterators.java

Lines changed: 235 additions & 156 deletions
Large diffs are not rendered by default.

std-bits/table/src/main/java/org/enso/table/data/column/storage/BoolStorage.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -323,7 +323,7 @@ public Storage<Boolean> slice(List<SliceRange> ranges) {
323323
}
324324

325325
@Override
326-
public ColumnBooleanStorageIterator iterator() {
326+
public ColumnBooleanStorageIterator iteratorWithIndex() {
327327
return new BoolStorageIterator(this);
328328
}
329329

std-bits/table/src/main/java/org/enso/table/data/column/storage/ColumnBooleanStorage.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,5 +5,5 @@ public interface ColumnBooleanStorage extends ColumnStorage<Boolean> {
55
boolean getItemAsBoolean(long index) throws ValueIsNothingException;
66

77
@Override
8-
ColumnBooleanStorageIterator iterator();
8+
ColumnBooleanStorageIterator iteratorWithIndex();
99
}

std-bits/table/src/main/java/org/enso/table/data/column/storage/ColumnBooleanStorageIterator.java

Lines changed: 0 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -3,28 +3,4 @@
33
public interface ColumnBooleanStorageIterator extends ColumnStorageIterator<Boolean> {
44
/** Gets the current item as a boolean. Note if the item isNothing value is undefined. */
55
boolean getItemAsBoolean();
6-
7-
@FunctionalInterface
8-
interface BooleanBooleanZipper {
9-
void accept(long idx, boolean value1, boolean isNothing1, boolean value2, boolean isNothing2);
10-
}
11-
12-
/** Zips this iterator with another iterator. */
13-
default void zip(
14-
ColumnBooleanStorage otherStorage, ColumnBooleanStorageIterator.BooleanBooleanZipper zipper) {
15-
var other = otherStorage.iterator();
16-
17-
boolean hasValue1 = moveNext();
18-
boolean hasValue2 = other.moveNext();
19-
long idx = 0;
20-
while (hasValue1 || hasValue2) {
21-
boolean isNothing1 = !hasValue1 || isNothing();
22-
boolean value1 = isNothing1 && getItemAsBoolean();
23-
boolean isNothing2 = !hasValue2 || other.isNothing();
24-
boolean value2 = isNothing2 && other.getItemAsBoolean();
25-
zipper.accept(idx++, value1, isNothing1, value2, isNothing2);
26-
hasValue1 = hasValue1 && moveNext();
27-
hasValue2 = hasValue2 && other.moveNext();
28-
}
29-
}
306
}

std-bits/table/src/main/java/org/enso/table/data/column/storage/ColumnDoubleStorage.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ public interface ColumnDoubleStorage extends ColumnStorage<Double> {
77
double getItemAsDouble(long index) throws ValueIsNothingException;
88

99
@Override
10-
ColumnDoubleStorageIterator iterator();
10+
ColumnDoubleStorageIterator iteratorWithIndex();
1111

1212
@Override
1313
FloatType getType();

std-bits/table/src/main/java/org/enso/table/data/column/storage/ColumnDoubleStorageIterator.java

Lines changed: 0 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -3,50 +3,4 @@
33
public interface ColumnDoubleStorageIterator extends ColumnStorageIterator<Double> {
44
/** Gets the current item as a double. Note if the item isNothing value is undefined. */
55
double getItemAsDouble();
6-
7-
@FunctionalInterface
8-
interface DoubleDoubleZipper {
9-
void accept(long idx, double value1, boolean isNothing1, double value2, boolean isNothing2);
10-
}
11-
12-
@FunctionalInterface
13-
interface DoubleLongZipper {
14-
void accept(long idx, double value1, boolean isNothing1, long value2, boolean isNothing2);
15-
}
16-
17-
/** Zips this iterator with another iterator. */
18-
default void zip(ColumnDoubleStorage otherStorage, DoubleDoubleZipper zipper) {
19-
var other = otherStorage.iterator();
20-
21-
boolean hasValue1 = moveNext();
22-
boolean hasValue2 = other.moveNext();
23-
long idx = 0;
24-
while (hasValue1 || hasValue2) {
25-
boolean isNothing1 = !hasValue1 || isNothing();
26-
double value1 = isNothing1 ? Double.NaN : getItemAsDouble();
27-
boolean isNothing2 = !hasValue2 || other.isNothing();
28-
double value2 = isNothing2 ? Double.NaN : other.getItemAsDouble();
29-
zipper.accept(idx++, value1, isNothing1, value2, isNothing2);
30-
hasValue1 = hasValue1 && moveNext();
31-
hasValue2 = hasValue2 && other.moveNext();
32-
}
33-
}
34-
35-
/** Zips this iterator with another iterator. */
36-
default void zip(ColumnLongStorage otherStorage, DoubleLongZipper zipper) {
37-
var other = otherStorage.iterator();
38-
39-
boolean hasValue1 = moveNext();
40-
boolean hasValue2 = other.moveNext();
41-
long idx = 0;
42-
while (hasValue1 || hasValue2) {
43-
boolean isNothing1 = !hasValue1 || isNothing();
44-
double value1 = isNothing1 ? Double.NaN : getItemAsDouble();
45-
boolean isNothing2 = !hasValue2 || other.isNothing();
46-
long value2 = isNothing2 ? 0 : other.getItemAsLong();
47-
zipper.accept(idx++, value1, isNothing1, value2, isNothing2);
48-
hasValue1 = hasValue1 && moveNext();
49-
hasValue2 = hasValue2 && other.moveNext();
50-
}
51-
}
526
}

std-bits/table/src/main/java/org/enso/table/data/column/storage/ColumnLongStorage.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ public interface ColumnLongStorage extends ColumnStorage<Long> {
77
long getItemAsLong(long index) throws ValueIsNothingException;
88

99
@Override
10-
ColumnLongStorageIterator iterator();
10+
ColumnLongStorageIterator iteratorWithIndex();
1111

1212
@Override
1313
IntegerType getType();

std-bits/table/src/main/java/org/enso/table/data/column/storage/ColumnLongStorageIterator.java

Lines changed: 0 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -3,50 +3,4 @@
33
public interface ColumnLongStorageIterator extends ColumnStorageIterator<Long> {
44
/** Gets the current item as a long. Note if the item isNothing value is undefined. */
55
long getItemAsLong();
6-
7-
@FunctionalInterface
8-
interface LongLongZipper {
9-
void accept(long idx, long value1, boolean isNothing1, long value2, boolean isNothing2);
10-
}
11-
12-
@FunctionalInterface
13-
interface LongDoubleZipper {
14-
void accept(long idx, long value1, boolean isNothing1, double value2, boolean isNothing2);
15-
}
16-
17-
/** Zips this iterator with a Double storage. */
18-
default void zip(ColumnDoubleStorage otherStorage, LongDoubleZipper zipper) {
19-
var other = otherStorage.iterator();
20-
21-
boolean hasValue1 = moveNext();
22-
boolean hasValue2 = other.moveNext();
23-
long idx = 0;
24-
while (hasValue1 || hasValue2) {
25-
boolean isNothing1 = !hasValue1 || isNothing();
26-
long value1 = isNothing1 ? 0 : getItemAsLong();
27-
boolean isNothing2 = !hasValue2 || other.isNothing();
28-
double value2 = isNothing2 ? 0 : other.getItemAsDouble();
29-
zipper.accept(idx++, value1, isNothing1, value2, isNothing2);
30-
hasValue1 = hasValue1 && moveNext();
31-
hasValue2 = hasValue2 && other.moveNext();
32-
}
33-
}
34-
35-
/** Zips this iterator with another Long storage. */
36-
default void zip(ColumnLongStorage otherStorage, LongLongZipper zipper) {
37-
var other = otherStorage.iterator();
38-
39-
boolean hasValue1 = moveNext();
40-
boolean hasValue2 = other.moveNext();
41-
long idx = 0;
42-
while (hasValue1 || hasValue2) {
43-
boolean isNothing1 = !hasValue1 || isNothing();
44-
long value1 = isNothing1 ? 0 : getItemAsLong();
45-
boolean isNothing2 = !hasValue2 || other.isNothing();
46-
long value2 = isNothing2 ? 0 : other.getItemAsLong();
47-
zipper.accept(idx++, value1, isNothing1, value2, isNothing2);
48-
hasValue1 = hasValue1 && moveNext();
49-
hasValue2 = hasValue2 && other.moveNext();
50-
}
51-
}
526
}

std-bits/table/src/main/java/org/enso/table/data/column/storage/ColumnStorage.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,6 @@ public interface ColumnStorage<T> extends Iterable<T> {
2121
/* Gets the value at a given index. */
2222
T getItemBoxed(long index);
2323

24-
@Override
25-
ColumnStorageIterator<T> iterator();
24+
/* Gets an iterator with index tracking. */
25+
ColumnStorageIterator<T> iteratorWithIndex();
2626
}

std-bits/table/src/main/java/org/enso/table/data/column/storage/ColumnStorageFacade.java

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package org.enso.table.data.column.storage;
22

3+
import java.util.Iterator;
34
import java.util.function.Function;
45
import org.enso.table.data.column.storage.type.StorageType;
56

@@ -35,7 +36,29 @@ public T getItemBoxed(long index) {
3536
}
3637

3738
@Override
38-
public ColumnStorageIterator<T> iterator() {
39+
public Iterator<T> iterator() {
40+
return new Iterator<T>() {
41+
private final Iterator<S> parentIterator = parent.iterator();
42+
43+
@Override
44+
public boolean hasNext() {
45+
return parentIterator.hasNext();
46+
}
47+
48+
@Override
49+
public T next() {
50+
S item = parentIterator.next();
51+
if (item == null) {
52+
return null;
53+
} else {
54+
return converter.apply(item);
55+
}
56+
}
57+
};
58+
}
59+
60+
@Override
61+
public ColumnStorageIterator<T> iteratorWithIndex() {
3962
return new Storage.StorageIterator<>(this);
4063
}
4164
}

0 commit comments

Comments
 (0)