You are viewing a plain text version of this content. The canonical link for it is here.
Posted to jira@kafka.apache.org by "ASF GitHub Bot (Jira)" <ji...@apache.org> on 2019/10/06 23:19:00 UTC

[jira] [Commented] (KAFKA-8991) Enable scalac optimizer

    [ https://issues.apache.org/jira/browse/KAFKA-8991?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16945483#comment-16945483 ] 

ASF GitHub Bot commented on KAFKA-8991:
---------------------------------------

ijuma commented on pull request #7452: KAFKA-8991: Enable scalac optimizer
URL: https://github.com/apache/kafka/pull/7452
 
 
   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.
   
   I verified that the lambda allocation in the code below went away after this change
   with Scala 2.12 and 2.13.
   
   ```scala
   private def consumeAbortedTxnsUpTo(offset: Long): Unit = {
     while (abortedTransactions.headOption.exists(_.firstOffset <= offset)) {
       val abortedTxn = abortedTransactions.dequeue()
       ongoingAbortedTxns.getOrElseUpdate(abortedTxn.producerId, new AbortedTransactionMetadata(abortedTxn))
     }
   }
   ```
   
   The relevant part of the bytecode when compiled with Scala 2.13 looks like:
   
   ```text
   private void consumeAbortedTxnsUpTo(long);
       Code:
          0: aload_0
          1: invokespecial #54                 // Method abortedTransactions:()Lscala/collection/mutable/PriorityQueue;
          4: invokevirtual #175                // Method scala/collection/mutable/PriorityQueue.headOption:()Lscala/Option;
          7: dup
          8: ifnonnull     13
         11: aconst_null
         12: athrow
         13: astore        4
         15: aload         4
         17: invokevirtual #145                // Method scala/Option.isEmpty:()Z
         20: ifne          48
         23: aload         4
         25: invokevirtual #148                // Method scala/Option.get:()Ljava/lang/Object;
         28: checkcast     #177                // class kafka/log/AbortedTxn
   ```
   
   ### Committer Checklist (excluded from commit message)
   - [ ] Verify design and implementation 
   - [ ] Verify test coverage and CI build status
   - [ ] Verify documentation (including upgrade notes)
   
 
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


> Enable scalac optimizer
> -----------------------
>
>                 Key: KAFKA-8991
>                 URL: https://issues.apache.org/jira/browse/KAFKA-8991
>             Project: Kafka
>          Issue Type: Improvement
>            Reporter: Ismael Juma
>            Assignee: Ismael Juma
>            Priority: Major
>             Fix For: 2.5.0
>
>
> The scalac optimizer is able to eliminate a number of allocations due to usage of lambdas as described in:
> https://www.lightbend.com/blog/scala-inliner-optimizer



--
This message was sent by Atlassian Jira
(v8.3.4#803005)