-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Inline code leads to a lot of Unit load + discard bytecode #6800
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
Those where supposed to be handled by the local optimizer which was removed in #4799 |
@jsuereth could you give a self contained snippet of code that reproduces the issue? |
@nicolasstucki I'll be a bit, but I can. |
It is possible that the new backend already optimizes those. Maybe we should wait until we upgrade the backend and see if it is still a problem. |
Hello, has the backend been upgraded? It seems that some class SpuriousUnits {
inline def inlined(f: => Unit): Unit = f
def use: Unit = inlined { println("") }
} The getstatic scala/Predef$.MODULE$:scala.Predef$
ldc "" (java.lang.String)
invokevirtual scala/Predef$.println(Ljava/lang/Object;)V
getstatic scala/runtime/BoxedUnit.UNIT:scala.runtime.BoxedUnit
pop Inline conditionals and matches are also affected: inline def printIfZero(x: Int): Unit = inline x match {
case 0 => println("zero")
case _ => ()
}
def useMatch: Unit = printIfZero(0) // contains getstatic BoxedUnit.UNIT at the end Interestingly, if we do def noop: Unit = inlined { () }
def useMatch2: Unit = printIfZero(2) // case _ => () then |
No, the backend has not been upgraded. This is something that will need some time. |
I've been using a lot of inline lately and I'm seeing the following bytecode in a lot of places:
This stems from doing Tuple-pair-wise-peel-off(tm), basically:
I had thought the empty
()
would get removed from the AST/generated code, but it seems to show up in bytecode. Additionally, when doing nested Product types with the same technique, I see BoxedUnit accessed and discarded at every nested-product boundary.The text was updated successfully, but these errors were encountered: