rorygraves / scalac_perf

The Scala programming language
http://www.scala-lang.org/
16 stars 3 forks source link

Erasing to object #51

Open mkeskells opened 6 years ago

mkeskells commented 6 years ago

many of the collection method have a return type without bound, e.g. Repr

This means that the bytecode emitted is littered with class cast to the expected type

Not sure what the overhead is. We should measure and see what options there are to improve this

mkeskells commented 6 years ago

e.g.

class demo {

  val in = List(1,2)

  def process1 = in.map (_+1).distinct.head
}

generates


  // access flags 0x1
  public process1()I
...
    GETSTATIC scala/collection/immutable/List$.MODULE$ : Lscala/collection/immutable/List$;
    INVOKEVIRTUAL scala/collection/immutable/List$.canBuildFrom ()Lscala/collection/generic/CanBuildFrom;
    INVOKEVIRTUAL scala/collection/immutable/List.map (Lscala/Function1;Lscala/collection/generic/CanBuildFrom;)Ljava/lang/Object;
    CHECKCAST scala/collection/SeqLike
    INVOKEINTERFACE scala/collection/SeqLike.distinct ()Ljava/lang/Object;
    CHECKCAST scala/collection/IterableLike
    INVOKEINTERFACE scala/collection/IterableLike.head ()Ljava/lang/Object;
    INVOKESTATIC scala/runtime/BoxesRunTime.unboxToInt (Ljava/lang/Object;)I
    IRETURN