|
|
@@ -33,7 +33,7 @@ public class BaseSpliteratorParalell {
|
|
|
}
|
|
|
|
|
|
ForkJoinPool executor = ForkJoinPool.commonPool();
|
|
|
- int splits = MathUtils.log2ceil(executor.getParallelism());
|
|
|
+ int splits = estimateSplits(executor, that);
|
|
|
List<Callable<Void>> tasks = new ArrayList<>();
|
|
|
try {
|
|
|
forEachSplit(splits, tasks, that, 0, consumer);
|
|
|
@@ -73,7 +73,7 @@ public class BaseSpliteratorParalell {
|
|
|
}
|
|
|
|
|
|
ForkJoinPool executor = ForkJoinPool.commonPool();
|
|
|
- int splits = MathUtils.log2ceil(executor.getParallelism());
|
|
|
+ int splits = estimateSplits(executor, that);
|
|
|
List<Callable<Void>> tasks = new ArrayList<>();
|
|
|
BaseState.Terminator terminator = BaseState.newTerminator(true);
|
|
|
try {
|
|
|
@@ -119,7 +119,7 @@ public class BaseSpliteratorParalell {
|
|
|
}
|
|
|
|
|
|
ForkJoinPool executor = ForkJoinPool.commonPool();
|
|
|
- int splits = MathUtils.log2ceil(executor.getParallelism());
|
|
|
+ int splits = estimateSplits(executor, that);
|
|
|
List<Callable<Integer>> tasks = new ArrayList<>();
|
|
|
try {
|
|
|
sizeSplit(splits, tasks, that);
|
|
|
@@ -149,4 +149,28 @@ public class BaseSpliteratorParalell {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+ private static int estimateSplits(ForkJoinPool executor, Spliterator<?> that) {
|
|
|
+ // we can't split spliterators into groups with specified size
|
|
|
+ // which mean we can't distribute elements evenly
|
|
|
+ // we can do 2 things:
|
|
|
+ // - split into number of tasks lower than executor
|
|
|
+ // - split into number of tasks SIGNIFICANTLY bigger than executor
|
|
|
+
|
|
|
+ // this estimation assumes that 3 additional splits will make groups
|
|
|
+ // 8 times smaller, which will eliminate disproportion between groups
|
|
|
+ //
|
|
|
+ // effectively, it will introduce 1/8 overhead at most, which means ~12%
|
|
|
+
|
|
|
+ int splits = MathUtils.log2floor(executor.getParallelism());
|
|
|
+
|
|
|
+ long n = that.getExactSizeIfKnown();
|
|
|
+ for(int i = 0; i<3; i++, splits++) {
|
|
|
+ if(n / (1L << splits) <= 3) {
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return splits;
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
}
|