You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@kafka.apache.org by gw...@apache.org on 2020/04/15 15:31:57 UTC
[kafka] branch trunk updated: MINOR: avoid autoboxing in
FetchRequest.PartitionData.equals
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 <lu...@gmail.com>
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.

![image](https://user-images.githubusercontent.com/252189/79079019-46686300-7cc1-11ea-9bc9-44fd17bae888.png)
Author: Lucas Bradstreet <lu...@gmail.com>
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,