Scala slow builds: development approaches to avoid

后端 未结 2 884
忘了有多久
忘了有多久 2021-02-07 12:50

First of all, incremental builds via SBT are pretty awesome, generally in the < 1sec range. However, sometimes you have to do a full clean/compile, or, in the case of increme

2条回答
  •  借酒劲吻你
    2021-02-07 13:11

    Have a look at how incremental recompilation works in SBT.

    It's roughly this:

    1. Find all classes whose publicly visible API have changed
    2. Invalidate all of its dependents, its dependents' dependents, and so on.

    For the purposes of SBT, a "dependent" is both a user of the class and a class defined in the same file.

    Owen's example for foo.scala could even be this, and you'd see the issue:

    object foo {
      def z: Int = 8
    }
    
    object foo2 {
      class A { ... }
    }
    

    Good practices:

    • Separate files for separate classes
    • Fine-grained interfaces
    • Use the same level of abstraction in companion objects as in their companion classes; if the companion object reaches up through layers of abstraction, pull it into a separate class and file.

提交回复
热议问题