Scala 编译较慢的原因

        写过Scala程序的人可能都有一种感觉,编译scala源代码的速度比较慢。是的,Scala编译源代码的速度确实较慢。

Martin Odersky对此作出了解释:http://stackoverflow.com/questions/3606591/why-does-intellij-idea-compile-scala-so-slowly/3612212#3612212

主要有四点:

  • 类型推断是耗时的操作,尤其需要搜索隐式转换(Type inference is costly, in particular if it involves implicit search.)

  • Scalac需要做两次类型检查,第一次是针对scala类型规则,第二次是针对Java类型规则(Scalac has to do type checking twice; once according to Scala's rules and a second time after erasure according to Java's rules.)

  • 从Scala到Java需要大约15次转换(Besides type checking there are about 15 transformation steps to go from Scala to Java, which all take time.)

  • 在源文件大小同等的情况下,Scala编译器通常会生成更多的类,尤其是使用了函数式特性(Scala typically generates many more classes per given file size than Java, in particular if functional idioms are heavily used. Bytecode generation and class writing takes time.)

你可能感兴趣的:(scala,编译)