majialoong commented on PR #20205:
URL: https://github.com/apache/kafka/pull/20205#issuecomment-3104130169
In the original method, there is no need to count the epochs without
messages(epochsWithNoMessages) first and then remove them. We can directly
calculate and get the results.
Use JMH test :
```
@BenchmarkMode(Mode.AverageTime)
@OutputTimeUnit(TimeUnit.NANOSECONDS)
@State(Scope.Thread)
public class LeaderEpochMapBenchmark {
@Param({"1000", "10000", "100000"})
private int mapSize;
NavigableMap<Integer, Long> testMap;
@Setup
public void setup() {
testMap = new TreeMap<>();
for (int i = 0; i < mapSize; i++) {
/**
* 0,0
* 1,0
* 2,1
* 3,1
* ...
*/
testMap.put(i, (long) (i / 2));
}
}
@Benchmark
public NavigableMap<Integer, Long> testOriginal() {
// before optimize (make method public)
return RemoteLogManager.buildFilteredLeaderEpochMap(testMap);
}
@Benchmark
public NavigableMap<Integer, Long> testOptimized() {
// after optimize (make method public)
return RemoteLogManager.buildFilteredLeaderEpochMap2(testMap);
}
}
```
Command :
``` ./jmh-benchmarks/jmh.sh LeaderEpochMapBenchmark ```
Result :
<img width="1528" height="370" alt="image"
src="https://github.com/user-attachments/assets/9f912a40-2c88-47fc-8eea-e8f063d7c320"
/>
--
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: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]