chia7712 commented on code in PR #19609:
URL: https://github.com/apache/kafka/pull/19609#discussion_r2077710697


##########
clients/src/main/java/org/apache/kafka/clients/consumer/internals/ConsumerNetworkThread.java:
##########
@@ -154,16 +153,12 @@ void runOnce() {
         lastPollTimeMs = currentTimeMs;
 
         final long pollWaitTimeMs = requestManagers.entries().stream()
-                .filter(Optional::isPresent)
-                .map(Optional::get)
                 .map(rm -> rm.poll(currentTimeMs))
                 .map(networkClientDelegate::addAll)
                 .reduce(MAX_POLL_TIMEOUT_MS, Math::min);

Review Comment:
   run a simple benchmark
   ```java
   @State(Scope.Thread)
   @OutputTimeUnit(TimeUnit.MILLISECONDS)
   public class ReduceBenchmark {
   
       private final List<Long> values = IntStream.range(0, 100 * 
1000).mapToObj(i -> (long) i).toList();
       private final long maxValue = 100;
   
       @Benchmark
       public void testReduce(Blackhole blackhole) {
           blackhole.consume(values.stream().reduce(maxValue, Math::min));
       }
   
       @Benchmark
       public void testMin(Blackhole blackhole) {
           blackhole.consume(values.stream().mapToLong(i -> i)
                           .filter(i -> i <= maxValue)
                           .min()
                           .orElse(maxValue));
       }
   }
   ```
   ```
   Benchmark                    Mode  Cnt  Score   Error   Units
   ReduceBenchmark.testMin     thrpt   25  7.915 ± 0.087  ops/ms
   ReduceBenchmark.testReduce  thrpt   25  3.256 ± 0.017  ops/ms
   ```
   
   It seems the filter could optimize it a bit.



-- 
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: jira-unsubscr...@kafka.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org

Reply via email to