Java compile speed vs Scala compile speed

前端 未结 8 1490
陌清茗
陌清茗 2020-11-28 16:07

I\'ve been programming in Scala for a while and I like it but one thing I\'m annoyed by is the time it takes to compile programs. It\'s seems like a small thing but with Ja

8条回答
  •  野趣味
    野趣味 (楼主)
    2020-11-28 17:03

    You should be aware that Scala compilation takes at least an order of magnitude longer than Java to compile. The reasons for this are as follows:

    1. Naming conventions (a file XY.scala file need not contain a class called XY and may contain multiple top-level classes). The compiler may therefore have to search more source files to find a given class/trait/object identifier.
    2. Implicits - heavy use of implicits means the compiler needs to search any in-scope implicit conversion for a given method and rank them to find the "right" one. (i.e. the compiler has a massively-increased search domain when locating a method.)
    3. The type system - the scala type system is way more complicated than Java's and hence takes more CPU time.
    4. Type inference - type inference is computationally expensive and a job that javac does not need to do at all
    5. scalac includes an 8-bit simulator of a fully armed and operational battle station, viewable using the magic key combination CTRL-ALT-F12 during the GenICode compilation phase.

提交回复
热议问题