KAFKA-8991: Enable scalac optimizer#7452
Conversation
05148ca to
b7f4afc
Compare
62b450c to
80bb3ab
Compare
|
I ran the JMH ReplicaFetcher benchmark from #7443 with this change: On the small partition count runs it looks like it's ~2% improvement, with other costs dominating as the partition count increases. |
guozhangwang
left a comment
There was a problem hiding this comment.
Thanks for tackling this @ijuma !
| 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) |
There was a problem hiding this comment.
Curious why are these piggy-backs added here?
There was a problem hiding this comment.
It was causing a spotBugs failure after the inlining.
|
One job passed, 2 failed with seemingly flaky tests. |
|
retest this please |
|
2 jobs passed, Scala 2.11 failed with a single failing test but Scala 2.11 is not affected by this PR. @guozhangwang @omkreddy Does the PR look good to you? |
|
LGTM! |
| // Kafka project in that case. | ||
| List<String> inlineFrom | ||
| if (project.name.equals('core')) | ||
| inlineFrom = ["-opt-inline-from:scala.**", "-opt-inline-from:kafka.**", "-opt-inline-from:org.apache.kafka.**"] |
There was a problem hiding this comment.
@ijuma I apologize if this the wrong place to ask a question about this PR. What would be the best place to start a discussion on removing "-opt-inline-from:scala.**" or reducing the scope of the glob to only include relevant methods like Option.exists? I'm not so familiar with the Kafka development process.
At Twitter, we are currently unable to upgrade to 2.5.x because kafka_2.12:2.5.1 inlines anonymous classes from the 2.12.11 library that no longer exist in the 2.12.12 library, resulting in crashes like this
java.lang.NoClassDefFoundError: scala/math/Ordering$$anon$7
We can work around this issue by publishing a custom build of Kafka but that's not a sustainable solution.
These inlining settings are causing issues for a lot of users based on my search online. Even members of the Scala compiler team who worked on the inliner have suggested that the inliner settings in the Kafka build are based on false assumptions akka/alpakka-kafka#1212 (comment) cc/ @lrytz
There was a problem hiding this comment.
Let's continue the discussion in #9548. Note the comment from @lrytz is regarding the claim that the core module should not be used as a library. This is the recommendation from the Kafka project though, so we can discuss in #9548 why users are depending on this module as a library (i.e. his expertise in the scala compiler/inliner is not relevant to this particular comment).
The scalac optimizer is able to inline methods to avoid lambda allocations, eliminating
the runtime cost of higher order functions in many cases. The compilation parameters
we are using here were introduced in 2.12.x, so we don't enable them for Scala 2.11.
Also, we enable a more aggressive inlining policy for the
coreproject since it'snot meant to be used as a library.
See https://www.lightbend.com/blog/scala-inliner-optimizer for more information about
the optimizer.
I verified that the lambda allocation in the code below (from LogCleaner.scala) went away
after this change with Scala 2.12 and 2.13.
The relevant part of the bytecode when compiled with Scala 2.13 looks like:
The increased inlining causes some spurious spotBugs warnings, I added a few suppressions
and fixed one warning by avoiding unnecessary boxing.
Committer Checklist (excluded from commit message)