From 0fe0bcddc5621dd34d27179cac49ae9dc21f434a Mon Sep 17 00:00:00 2001 From: Ismael Juma Date: Sun, 6 Oct 2019 16:08:14 -0700 Subject: [PATCH 1/4] KAFKA-8991: Enable scalac optimizer --- build.gradle | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/build.gradle b/build.gradle index 65e6a69dbca5f..f9de5d1f17619 100644 --- a/build.gradle +++ b/build.gradle @@ -419,6 +419,22 @@ subprojects { "-Xlint:constant", "-Xlint:unused" ] + + // Inline more aggressively when compiling the `core` jar since it's not meant to be used as a library. + // More specifically, inline classes from the Scala library so that we can inline methods like `Option.exists` + // and avoid lambda allocations. This is only safe if the Scala library version is the same at compile time + // and runtime. We cannot guarantee this for libraries like kafka streams, so only inline classes from the + // Kafka project in that case. + List inlineFrom + if (project.name.equals('core')) + inlineFrom = ["-opt-inline-from:scala.**", "-opt-inline-from:kafka.**", "-opt-inline-from:org.apache.kafka.**"] + else + inlineFrom = ["-opt-inline-from:org.apache.kafka.**"] + + // Somewhat confusingly, `-opt:l:inline` enables all optimizations. `inlineFrom` configures what can be inlined. + // See https://www.lightbend.com/blog/scala-inliner-optimizer for more information about the optimizer. + scalaCompileOptions.additionalParameters += ["-opt:l:inline"] + scalaCompileOptions.additionalParameters += inlineFrom } // these options are valid for Scala versions < 2.13 only From b09430cc3bf331565049c70b8167ed0884b83ff6 Mon Sep 17 00:00:00 2001 From: Ismael Juma Date: Sun, 6 Oct 2019 17:51:18 -0700 Subject: [PATCH 2/4] Avoid boxing by using `java.lang.Long.compare` --- core/src/main/scala/kafka/log/AbstractIndex.scala | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/core/src/main/scala/kafka/log/AbstractIndex.scala b/core/src/main/scala/kafka/log/AbstractIndex.scala index 242d0745302bc..7dca8120c3d5b 100644 --- a/core/src/main/scala/kafka/log/AbstractIndex.scala +++ b/core/src/main/scala/kafka/log/AbstractIndex.scala @@ -405,8 +405,8 @@ abstract class AbstractIndex[K, V](@volatile var file: File, val baseOffset: Lon private def compareIndexEntry(indexEntry: IndexEntry, target: Long, searchEntity: IndexSearchEntity): Int = { searchEntity match { - case IndexSearchType.KEY => indexEntry.indexKey.compareTo(target) - case IndexSearchType.VALUE => indexEntry.indexValue.compareTo(target) + case IndexSearchType.KEY => java.lang.Long.compare(indexEntry.indexKey, target) + case IndexSearchType.VALUE => java.lang.Long.compare(indexEntry.indexValue, target) } } From 2e05b1a1a8f706430d47416e1bd0c62dd4151299 Mon Sep 17 00:00:00 2001 From: Ismael Juma Date: Sun, 6 Oct 2019 18:48:04 -0700 Subject: [PATCH 3/4] spotBugs exclusions --- gradle/spotbugs-exclude.xml | 24 ++++++++++++++++++++---- 1 file changed, 20 insertions(+), 4 deletions(-) diff --git a/gradle/spotbugs-exclude.xml b/gradle/spotbugs-exclude.xml index 07ca2b450e753..f4fdd78fc79c0 100644 --- a/gradle/spotbugs-exclude.xml +++ b/gradle/spotbugs-exclude.xml @@ -104,10 +104,8 @@ For a detailed description of spotbugs bug categories, see https://spotbugs.read - - - - + + @@ -118,6 +116,24 @@ For a detailed description of spotbugs bug categories, see https://spotbugs.read + + + + + + + + + + + + + + + + + + From 80bb3ab0fec5200463de98ecdc483643694616b5 Mon Sep 17 00:00:00 2001 From: Ismael Juma Date: Mon, 7 Oct 2019 06:39:23 -0700 Subject: [PATCH 4/4] Add exclusions for Scala 2.12 --- gradle/spotbugs-exclude.xml | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) diff --git a/gradle/spotbugs-exclude.xml b/gradle/spotbugs-exclude.xml index f4fdd78fc79c0..70ea5b0682a65 100644 --- a/gradle/spotbugs-exclude.xml +++ b/gradle/spotbugs-exclude.xml @@ -134,6 +134,41 @@ For a detailed description of spotbugs bug categories, see https://spotbugs.read + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +