Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[#493] improvement: replace putIfAbsent with computeIfAbsent to avoid performance loss in some critical paths #876

Merged
merged 3 commits into from
May 13, 2023

Conversation

cchung100m
Copy link
Collaborator

Hi @zuston

I have updated some critical paths with the replacement, however, there might be some missing pieces, any suggestions would be appreciated.

What changes were proposed in this pull request?

Replace putIfAbsent with computeIfAbsent in some critical paths

Why are the changes needed?

Fix: #493

Does this PR introduce any user-facing change?

No.

How was this patch tested?

current UT

@jerqi jerqi requested a review from zuston May 11, 2023 15:37
@jerqi jerqi changed the title [#493][Improvement] Replace putIfAbsent with computeIfAbsent in some critical paths [#493] refactor: Replace putIfAbsent with computeIfAbsent in some critical paths May 12, 2023
@@ -241,7 +241,7 @@ protected ShuffleBlockInfo createShuffleBlock(int partitionId, WriterBuffer wb)

// it's run in single thread, and is not thread safe
private int getNextSeqNo(int partitionId) {
partitionToSeqNo.putIfAbsent(partitionId, 0);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is unnecessary.

@@ -544,7 +544,7 @@ public void reportShuffleResult(
groupedPartitions.get(ssi).add(partitionIdx);
}
if (CollectionUtils.isNotEmpty(partitionToBlockIds.get(partitionIdx))) {
partitionReportTracker.putIfAbsent(partitionIdx, 0);
partitionReportTracker.computeIfAbsent(partitionIdx, key -> 0);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ditto

@@ -630,7 +630,7 @@ public Roaring64NavigableMap getShuffleResultForMultiPart(String clientType,
ShuffleServerInfo shuffleServerInfo = entry.getKey();
Set<Integer> requestPartitions = Sets.newHashSet();
for (Integer partitionId : entry.getValue()) {
partitionReadSuccess.putIfAbsent(partitionId, 0);
partitionReadSuccess.computeIfAbsent(partitionId, key -> 0);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ditto

@@ -312,7 +312,7 @@ public static Map<Integer, Roaring64NavigableMap> generatePartitionToBitmap(
Roaring64NavigableMap shuffleBitmap, int startPartition, int endPartition) {
Map<Integer, Roaring64NavigableMap> result = Maps.newHashMap();
for (int partitionId = startPartition; partitionId < endPartition; partitionId++) {
result.putIfAbsent(partitionId, Roaring64NavigableMap.bitmapOf());
result.computeIfAbsent(partitionId, key -> Roaring64NavigableMap.bitmapOf());
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice! 👍

@zuston
Copy link
Member

zuston commented May 12, 2023

Overall LGTM @cchung100m Left minor comments and please fix the CI failure. Thanks~

@cchung100m cchung100m requested a review from zuston May 12, 2023 16:13
@codecov-commenter
Copy link

codecov-commenter commented May 12, 2023

Codecov Report

Merging #876 (b90399d) into master (9c26c1b) will increase coverage by 2.13%.
The diff coverage is 100.00%.

@@             Coverage Diff              @@
##             master     #876      +/-   ##
============================================
+ Coverage     56.58%   58.71%   +2.13%     
- Complexity     2176     2183       +7     
============================================
  Files           327      307      -20     
  Lines         15981    13623    -2358     
  Branches       1263     1258       -5     
============================================
- Hits           9043     7999    -1044     
+ Misses         6430     5186    -1244     
+ Partials        508      438      -70     
Impacted Files Coverage Δ
...g/apache/hadoop/mapred/SortWriteBufferManager.java 79.67% <100.00%> (-0.11%) ⬇️
.../java/org/apache/uniffle/common/util/RssUtils.java 56.83% <100.00%> (ø)
...apache/uniffle/coordinator/ApplicationManager.java 83.79% <100.00%> (+0.09%) ⬆️
...ache/uniffle/coordinator/SimpleClusterManager.java 75.31% <100.00%> (ø)
...assignment/PartitionBalanceAssignmentStrategy.java 94.91% <100.00%> (+0.08%) ⬆️
...org/apache/uniffle/server/ShuffleFlushManager.java 80.20% <100.00%> (-0.10%) ⬇️
.../org/apache/uniffle/server/ShuffleTaskManager.java 77.23% <100.00%> (+0.28%) ⬆️
...he/uniffle/server/buffer/ShuffleBufferManager.java 84.22% <100.00%> (ø)

... and 23 files with indirect coverage changes

📣 We’re building smart automated test selection to slash your CI/CD build times. Learn more

Copy link
Member

@zuston zuston left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM. Thanks for your contribution @cchung100m 🎉

@zuston zuston changed the title [#493] refactor: Replace putIfAbsent with computeIfAbsent in some critical paths [#493] improvement: replace putIfAbsent with computeIfAbsent to avoid performance loss in some critical paths May 13, 2023
@zuston zuston merged commit 748b735 into apache:master May 13, 2023
25 checks passed
@zuston
Copy link
Member

zuston commented May 13, 2023

Do you want join our WeChat group? If you are willing to do more contribution or have any good idea, feel free to propose.

IMG_9188

@cchung100m cchung100m deleted the refactor_493_putIfAbsent branch May 13, 2023 08:08
@cchung100m
Copy link
Collaborator Author

Hi @zuston

Thanks for the invitation, I have joined the group.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Improvement] Replace putIfAbsent with computeIfAbsent in some critical paths
3 participants