This is an automated email from the ASF dual-hosted git repository.
gwenshap pushed a commit to branch trunk
in repository https://gitbox.apache.org/repos/asf/kafka.git
The following commit(s) were added to refs/heads/trunk by this push:
new 7da1302 MINOR: avoid autoboxing in FetchRequest.PartitionData.equals
7da1302 is described below
commit 7da13024b4b42c7fe1e82792a5d85c77d4e93037
Author: Lucas Bradstreet <[email protected]>
AuthorDate: Wed Apr 15 08:31:09 2020 -0700
MINOR: avoid autoboxing in FetchRequest.PartitionData.equals
FetchRequest.PartitionData.equals unnecessarily uses Object.equals
generating a lot of allocations due to boxing, even though primitives are being
compared. This is shown in the allocation profile below. Note that the CPU
overhead is negligble.


Author: Lucas Bradstreet <[email protected]>
Reviewers: Chia-Ping Tsai, Gwen Shapira
Closes #8473 from lbradstreet/avoid-boxing-partition-data-equals
---
.../main/java/org/apache/kafka/common/requests/FetchRequest.java | 8 ++++----
core/src/test/scala/unit/kafka/server/FetchRequestTest.scala | 6 ++++++
2 files changed, 10 insertions(+), 4 deletions(-)
diff --git
a/clients/src/main/java/org/apache/kafka/common/requests/FetchRequest.java
b/clients/src/main/java/org/apache/kafka/common/requests/FetchRequest.java
index f99409e..502e32b 100644
--- a/clients/src/main/java/org/apache/kafka/common/requests/FetchRequest.java
+++ b/clients/src/main/java/org/apache/kafka/common/requests/FetchRequest.java
@@ -266,10 +266,10 @@ public class FetchRequest extends AbstractRequest {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
PartitionData that = (PartitionData) o;
- return Objects.equals(fetchOffset, that.fetchOffset) &&
- Objects.equals(logStartOffset, that.logStartOffset) &&
- Objects.equals(maxBytes, that.maxBytes) &&
- Objects.equals(currentLeaderEpoch, that.currentLeaderEpoch);
+ return fetchOffset == that.fetchOffset &&
+ logStartOffset == that.logStartOffset &&
+ maxBytes == that.maxBytes &&
+ currentLeaderEpoch.equals(that.currentLeaderEpoch);
}
}
diff --git a/core/src/test/scala/unit/kafka/server/FetchRequestTest.scala
b/core/src/test/scala/unit/kafka/server/FetchRequestTest.scala
index 048794b..f0c4329 100644
--- a/core/src/test/scala/unit/kafka/server/FetchRequestTest.scala
+++ b/core/src/test/scala/unit/kafka/server/FetchRequestTest.scala
@@ -533,6 +533,12 @@ class FetchRequestTest extends BaseRequestTest {
}
@Test
+ def testPartitionDataEquals(): Unit = {
+ assertEquals(new FetchRequest.PartitionData(300, 0L, 300,
Optional.of(300)),
+ new FetchRequest.PartitionData(300, 0L, 300, Optional.of(300)));
+ }
+
+ @Test
def testZStdCompressedRecords(): Unit = {
// Producer compressed topic
val topicConfig = Map(LogConfig.CompressionTypeProp ->
ProducerCompressionCodec.name,