Skip to content

Inefficient bytecode generated compared to Scala 2.13 #12161

Closed
@japgolly

Description

@japgolly

In my UnivEq library I have ==*/!=* ops which are macros that expand to normal ==/!=.

Comparing the bytecode generated for:

def testBoolean(a: Boolean): Boolean =
  (a !=* a) || (a ==* a)

we get this for Scala 2.13 (note: no -opt flags used):

  public boolean testBoolean(boolean);
    Code:
       0: iload_1
       1: iload_1
       2: if_icmpeq     9
       5: iconst_1
       6: goto          10
       9: iconst_0
      10: ifne          26
      13: iload_1
      14: iload_1
      15: if_icmpne     22
      18: iconst_1
      19: goto          23
      22: iconst_0
      23: ifeq          30
      26: iconst_1
      27: goto          31
      30: iconst_0
      31: ireturn

and this for Scala 3

  public boolean testBoolean(boolean);
    Code:
       0: iload_1
       1: istore_2
       2: iload_1
       3: istore_3
       4: iload_2
       5: iload_3
       6: if_icmpeq     13
       9: iconst_1
      10: goto          14
      13: iconst_0
      14: ifne          38
      17: iload_1
      18: istore        4
      20: iload_1
      21: istore        5
      23: iload         4
      25: iload         5
      27: if_icmpne     34
      30: iconst_1
      31: goto          35
      34: iconst_0
      35: ifeq          42
      38: iconst_1
      39: goto          43
      42: iconst_0
      43: ireturn

The Scala 3 bytecode seems inefficient compared to that of Scala 2.13. Ideally they'd be the same for something this simple, no?

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions