You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@pulsar.apache.org by GitBox <gi...@apache.org> on 2022/01/13 14:18:51 UTC
[GitHub] [pulsar] Shawyeok opened a new pull request #13742: [broker] Fix inefficient forEach loop
Shawyeok opened a new pull request #13742:
URL: https://github.com/apache/pulsar/pull/13742
<!--
### Contribution Checklist
- Name the pull request in the form "[Issue XYZ][component] Title of the pull request", where *XYZ* should be replaced by the actual issue number.
Skip *Issue XYZ* if there is no associated github issue for this pull request.
Skip *component* if you are unsure about which is the best component. E.g. `[docs] Fix typo in produce method`.
- Fill out the template below to describe the changes contributed by the pull request. That will give reviewers the context they need to do the review.
- Each pull request should address only one issue, not mix up code from multiple issues.
- Each commit in the pull request has a meaningful commit message
- Once all items of the checklist are addressed, remove the above text and this checklist, leaving only the filled out template below.
**(The sections below can be removed for hotfixes of typos)**
-->
### Motivation
There are some methods implements with inefficient forEach loop, so fix it to get better performance. It is similar with #12953
### Modifications
I reimplements them with basic `for` loop.
### Verifying this change
- [x] Make sure that the change passes the CI checks.
This change added tests and can be verified as follows:
- `org.apache.pulsar.common.util.collections.ConcurrentSortedLongPairSetTest#testIsEmpty`
### Does this pull request potentially affect one of the following parts:
*If `yes` was chosen, please highlight the changes*
- Dependencies (does it add or upgrade a dependency): (no)
- The public API: (no)
- The schema: (no)
- The default values of configurations: (no)
- The wire protocol: (no)
- The rest endpoints: (no)
- The admin cli options: (no)
- Anything that affects deployment: (no)
### Documentation
Check the box below or label this PR directly (if you have committer privilege).
Need to update docs?
- [ ] `doc-required`
(If you need help on updating docs, create a doc issue)
- [x] `no-need-doc`
It is a kind of `bugfix`
- [ ] `doc`
(If this PR contains doc changes)
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@pulsar.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [pulsar] Shawyeok commented on pull request #13742: [broker] Fix inefficient forEach loop
Posted by GitBox <gi...@apache.org>.
Shawyeok commented on pull request #13742:
URL: https://github.com/apache/pulsar/pull/13742#issuecomment-1012806121
/pulsarbot rerun-failure-checks
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@pulsar.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [pulsar] merlimat commented on a change in pull request #13742: [broker] Fix inefficient forEach loop
Posted by GitBox <gi...@apache.org>.
merlimat commented on a change in pull request #13742:
URL: https://github.com/apache/pulsar/pull/13742#discussion_r784116536
##########
File path: pulsar-broker/src/main/java/org/apache/pulsar/broker/service/AbstractTopic.java
##########
@@ -356,14 +355,15 @@ public void enableCnxAutoRead() {
}
protected boolean hasLocalProducers() {
- AtomicBoolean foundLocal = new AtomicBoolean(false);
- producers.values().forEach(producer -> {
+ if (producers.isEmpty()) {
+ return false;
+ }
+ for (Producer producer : producers.values()) {
Review comment:
`producers.values()` is taking a copy of the map so it would be very expensive.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@pulsar.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [pulsar] Shawyeok commented on a change in pull request #13742: [broker] Fix inefficient forEach loop
Posted by GitBox <gi...@apache.org>.
Shawyeok commented on a change in pull request #13742:
URL: https://github.com/apache/pulsar/pull/13742#discussion_r784147855
##########
File path: pulsar-broker/src/main/java/org/apache/pulsar/broker/service/AbstractTopic.java
##########
@@ -356,14 +355,15 @@ public void enableCnxAutoRead() {
}
protected boolean hasLocalProducers() {
- AtomicBoolean foundLocal = new AtomicBoolean(false);
- producers.values().forEach(producer -> {
+ if (producers.isEmpty()) {
+ return false;
+ }
+ for (Producer producer : producers.values()) {
Review comment:
It's create a reusable ValuesView instance under ConcurrentHashMap#values, not a copy I think.
##########
File path: pulsar-broker/src/main/java/org/apache/pulsar/broker/service/AbstractTopic.java
##########
@@ -356,14 +355,15 @@ public void enableCnxAutoRead() {
}
protected boolean hasLocalProducers() {
- AtomicBoolean foundLocal = new AtomicBoolean(false);
- producers.values().forEach(producer -> {
+ if (producers.isEmpty()) {
+ return false;
+ }
+ for (Producer producer : producers.values()) {
Review comment:
It's create a reusable `ValuesView` instance under `ConcurrentHashMap#values`, not a copy I think.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@pulsar.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [pulsar] gaoran10 merged pull request #13742: [broker] Fix inefficient forEach loop
Posted by GitBox <gi...@apache.org>.
gaoran10 merged pull request #13742:
URL: https://github.com/apache/pulsar/pull/13742
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@pulsar.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [pulsar] Shawyeok commented on pull request #13742: [broker] Fix inefficient forEach loop
Posted by GitBox <gi...@apache.org>.
Shawyeok commented on pull request #13742:
URL: https://github.com/apache/pulsar/pull/13742#issuecomment-1012680345
/pulsarbot rerun-failure-checks
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@pulsar.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [pulsar] Shawyeok commented on pull request #13742: [broker] Fix inefficient forEach loop
Posted by GitBox <gi...@apache.org>.
Shawyeok commented on pull request #13742:
URL: https://github.com/apache/pulsar/pull/13742#issuecomment-1013694741
/pulsarbot rerun-failure-checks
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@pulsar.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [pulsar] Shawyeok commented on a change in pull request #13742: [broker] Fix inefficient forEach loop
Posted by GitBox <gi...@apache.org>.
Shawyeok commented on a change in pull request #13742:
URL: https://github.com/apache/pulsar/pull/13742#discussion_r784147855
##########
File path: pulsar-broker/src/main/java/org/apache/pulsar/broker/service/AbstractTopic.java
##########
@@ -356,14 +355,15 @@ public void enableCnxAutoRead() {
}
protected boolean hasLocalProducers() {
- AtomicBoolean foundLocal = new AtomicBoolean(false);
- producers.values().forEach(producer -> {
+ if (producers.isEmpty()) {
+ return false;
+ }
+ for (Producer producer : producers.values()) {
Review comment:
It's create a reusable instance of `ValuesView` under ConcurrentHashMap#values, not a copy I think.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@pulsar.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [pulsar] codelipenghui commented on pull request #13742: [broker] Fix inefficient forEach loop
Posted by GitBox <gi...@apache.org>.
codelipenghui commented on pull request #13742:
URL: https://github.com/apache/pulsar/pull/13742#issuecomment-1012725788
/pulsarbot rerun-failure-checks
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@pulsar.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [pulsar] Shawyeok commented on pull request #13742: [broker] Fix inefficient forEach loop
Posted by GitBox <gi...@apache.org>.
Shawyeok commented on pull request #13742:
URL: https://github.com/apache/pulsar/pull/13742#issuecomment-1012180003
It is similar with https://github.com/apache/pulsar/pull/12953, please take a look. @BewareMyPower @codelipenghui
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@pulsar.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [pulsar] merlimat commented on a change in pull request #13742: [broker] Fix inefficient forEach loop
Posted by GitBox <gi...@apache.org>.
merlimat commented on a change in pull request #13742:
URL: https://github.com/apache/pulsar/pull/13742#discussion_r784189595
##########
File path: pulsar-broker/src/main/java/org/apache/pulsar/broker/service/AbstractTopic.java
##########
@@ -356,14 +355,15 @@ public void enableCnxAutoRead() {
}
protected boolean hasLocalProducers() {
- AtomicBoolean foundLocal = new AtomicBoolean(false);
- producers.values().forEach(producer -> {
+ if (producers.isEmpty()) {
+ return false;
+ }
+ for (Producer producer : producers.values()) {
Review comment:
Oh, you're right, we using the regular `ConcurrentHashMap` here instead of the other custom map.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@pulsar.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org