Skip to content

Inline code leads to a lot of Unit load + discard bytecode #6800

Closed
@jsuereth

Description

@jsuereth

I've been using a lot of inline lately and I'm seeing the following bytecode in a lot of places:

N: getstatic     #54  // Field scala/runtime/BoxedUnit.UNIT:Lscala/runtime/BoxedUnit;
N+1: pop

This stems from doing Tuple-pair-wise-peel-off(tm), basically:

inline def doNextThing[Elems](idx: Int, p: Product): Unit =
   inline erasedValue match {
       case _: (a *: b) =>  doThing[a](p.productElement(idx).asInstanceOf)
       case _: Unit => () // Base case
   }

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.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions