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 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) } } diff --git a/gradle/spotbugs-exclude.xml b/gradle/spotbugs-exclude.xml index 07ca2b450e753..70ea5b0682a65 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,59 @@ For a detailed description of spotbugs bug categories, see https://spotbugs.read + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +