scalafix icon indicating copy to clipboard operation
scalafix copied to clipboard

[sbt 2.x] Cached/incremental invocations across builds & machines

Open bjaglin opened this issue 7 months ago • 0 comments
trafficstars

Context

sbt-scalafix has had opt-in support for cached/incremental invocations within a build for sbt 0.13.x and sbt 1.x since v0.9.15-3. This feature was instrumental to introduce scalafixOnCompile in v0.9.19.

Improvements were made in v0.9.20, as well as some tweaks along the way. Caching has been enabled by default since v0.9.28.

sbt-scalafix is now available for sbt 2.x since v0.14.2, preserving the same features as with sbt 1.x. Interestingly, the sbt 2.x shell now make the cache usage explicit:

sbt:sbt-scalafix-root> all Compile/compile Test/compile
...
[success] elapsed time: 5 s, cache 8%, 2 disk cache hits, 22 onsite tasks

sbt:sbt-scalafix-root> scalafixAll
[info] Running scalafix on 18 Scala sources
[info] Running scalafix on 19 Scala sources
[info] Running scalafix on 7 Scala sources
[info] Running scalafix on 7 Scala sources
[success] elapsed time: 1 s, cache 59%, 16 disk cache hits, 11 onsite tasks

sbt:sbt-scalafix-root> scalafixAll
[success] elapsed time: 0 s, cache 100%, 27 disk cache hits

Feature request

One of the key feature of sbt 2.x is to provide a set of declarative APIs for tasks to be "transparently" cached indifferently across builds and/or across machines. A PR merged in v0.9.26 enabled a similar behavior on sbt 1.x, but only for power users with large builds, willing to invest time to extend the adhoc, imperative cache features of sbt 1.x.

To significantly reduce CPU footprint on developers machines, sbt-scalafix should be made remote-cache friendly on sbt 2.x, by porting the existing local cache logic to the generic, declarative one. The extensive upstream documentation about doing that fortestQuick should greatly help.

Current

sbt:sbt-scalafix-root> scalafixAll
[success] elapsed time: 0 s, cache 100%, 27 disk cache hits

sbt:sbt-scalafix-root> clean
[success] elapsed time: 0 s

sbt:sbt-scalafix-root> scalafixAll
[info] Running scalafix on 18 Scala sources
[info] Running scalafix on 7 Scala sources
[info] Running scalafix on 19 Scala sources
[info] Running scalafix on 7 Scala sources
[success] elapsed time: 2 s, cache 100%, 27 disk cache hits

Expected

sbt:sbt-scalafix-root> scalafixAll
[success] elapsed time: 0 s, cache 100%, 27 disk cache hits

sbt:sbt-scalafix-root> clean
[success] elapsed time: 0 s

sbt:sbt-scalafix-root> scalafixAll
[success] elapsed time: 0 s, cache 100%, 27 disk cache hits

bjaglin avatar Mar 28 '25 13:03 bjaglin