This is an automated email from the ASF dual-hosted git repository.
zuston pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/incubator-uniffle.git
The following commit(s) were added to refs/heads/master by this push:
new d82e10d9 [#729] improvement: use `foreach` when iterate over
Roaring64NavigableMap for better performance (#730)
d82e10d9 is described below
commit d82e10d9bf1457bb74a4ac349a117f44fcbeb31a
Author: Junfan Zhang <[email protected]>
AuthorDate: Fri Mar 17 15:31:23 2023 +0800
[#729] improvement: use `foreach` when iterate over Roaring64NavigableMap
for better performance (#730)
### What changes were proposed in this pull request?
use foreach when iterate over Roaring64NavigableMap for better performance
### Why are the changes needed?
From the doc of https://github.com/RoaringBitmap/RoaringBitmap/issues/44,
it will reduce GC footprint and be faster when using the `foreach`
### Does this PR introduce _any_ user-facing change?
No.
### How was this patch tested?
Don't need.
---
.../apache/uniffle/common/segment/LocalOrderSegmentSplitter.java | 6 +-----
.../main/java/org/apache/uniffle/server/ShuffleTaskManager.java | 9 +++------
2 files changed, 4 insertions(+), 11 deletions(-)
diff --git
a/common/src/main/java/org/apache/uniffle/common/segment/LocalOrderSegmentSplitter.java
b/common/src/main/java/org/apache/uniffle/common/segment/LocalOrderSegmentSplitter.java
index d3f912f7..a8bcd0ce 100644
---
a/common/src/main/java/org/apache/uniffle/common/segment/LocalOrderSegmentSplitter.java
+++
b/common/src/main/java/org/apache/uniffle/common/segment/LocalOrderSegmentSplitter.java
@@ -23,7 +23,6 @@ import java.util.ArrayList;
import java.util.List;
import com.google.common.collect.Lists;
-import org.roaringbitmap.longlong.LongIterator;
import org.roaringbitmap.longlong.Roaring64NavigableMap;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -156,10 +155,7 @@ public class LocalOrderSegmentSplitter implements
SegmentSplitter {
private List<Long> getExpectedTaskIds(Roaring64NavigableMap expectTaskIds) {
List<Long> taskIds = new ArrayList<>();
- LongIterator iterator = expectTaskIds.getLongIterator();
- while (iterator.hasNext()) {
- taskIds.add(iterator.next());
- }
+ expectTaskIds.forEach(value -> taskIds.add(value));
return taskIds;
}
}
diff --git
a/server/src/main/java/org/apache/uniffle/server/ShuffleTaskManager.java
b/server/src/main/java/org/apache/uniffle/server/ShuffleTaskManager.java
index e723d22c..4095cedf 100644
--- a/server/src/main/java/org/apache/uniffle/server/ShuffleTaskManager.java
+++ b/server/src/main/java/org/apache/uniffle/server/ShuffleTaskManager.java
@@ -39,7 +39,6 @@ import com.google.common.collect.Queues;
import com.google.common.collect.Range;
import com.google.common.collect.Sets;
import org.apache.commons.collections.CollectionUtils;
-import org.roaringbitmap.longlong.LongIterator;
import org.roaringbitmap.longlong.Roaring64NavigableMap;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -441,15 +440,13 @@ public class ShuffleTaskManager {
// filter the specific partition blockId in the bitmap to the resultBitmap
protected Roaring64NavigableMap getBlockIdsByPartitionId(Set<Integer>
requestPartitions,
Roaring64NavigableMap bitmap, Roaring64NavigableMap resultBitmap) {
- LongIterator iter = bitmap.getLongIterator();
- long mask = (1L << Constants.PARTITION_ID_MAX_LENGTH) - 1;
- while (iter.hasNext()) {
- long blockId = iter.next();
+ final long mask = (1L << Constants.PARTITION_ID_MAX_LENGTH) - 1;
+ bitmap.forEach(blockId -> {
int partitionId = Math.toIntExact((blockId >>
Constants.TASK_ATTEMPT_ID_MAX_LENGTH) & mask);
if (requestPartitions.contains(partitionId)) {
resultBitmap.addLong(blockId);
}
- }
+ });
return resultBitmap;
}