Skip to content

Dotty generates suboptimal bytecode, even for simple code snippets #3271

Closed
@gan74

Description

@gan74

For

  var x = 0
  while(x <= 5) {
    println(x)
    x += 1
  }

Dotty generates bytecode like this: (even with -optimise)

iconst_0
istore_2
goto 20
iload_2
iconst_5
if_icmpgt 19
getstatic scala/Predef$/MODULE$ Lscala/Predef$;
iload_2
invokestatic scala/runtime/BoxesRunTime/boxToInteger(I)Ljava/lang/Integer;
invokevirtual scala/Predef$/println(Ljava/lang/Object;)V
iconst_1
iload_2
iadd
istore_2
goto 4
nop
nop
athrow
goto 21
goto 4
return

while scalac 2.12.3 generates:

iconst_0
istore_2
iload_2
iconst_5
if_icmpgt 15
getstatic scala/Predef$/MODULE$ Lscala/Predef$;
iload_2
invokestatic scala/runtime/BoxesRunTime/boxToInteger(I)Ljava/lang/Integer;
invokevirtual scala/Predef$/println(Ljava/lang/Object;)V
iload_2
iconst_1
iadd
istore_2
goto 3
return

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