23

Does SBT make use of fsc?

For test purposes I am compiling a 500-line program on a fairly slow Ubuntu machine (Atom N270). Three successive compile times were 77s, 66s, and 66s.

I then compiled the file with fsc from the command line. Now my times were 80s, 25s, 18s. Better! That implies to me sbt is not using fsc. Am I right? If so, why doesn't it use it?

I may try getting sbt to explicitly use fsc to compile, though I am not sure I will figure out the config. Has anyone done this?

Crosbie
  • 1,805
  • 2
  • 16
  • 22

4 Answers4

21

This discussion made me realize I have been using sbt the wrong way.

Instead of (from the command line):

$ sbt compile
$ sbt test

..one should keep sbt running and treat it as the command prompt.

$ sbt
> compile
  ...
> test

It has the command history and even ability to dive back into OS command line. I wrote this 'answer' for others like me (coming from a Makefile mindset) that might not realize we're taking the pill all wrong. :)

(It's still slow, though.)

akauppi
  • 17,018
  • 15
  • 95
  • 120
  • How do you interrupt an sbt command (e.g. I have a web server that I need to interrupt when I change the code in the test/dev cycle)? This will be useful to add to akauppi's answer – Ram Rajamony Apr 05 '15 at 17:00
  • Hi @RamRajamony - do you know sbt-revolver, it sounds like what you are looking for. In essence, it keeps sbt on the background and recompiles whenever the source changes, automatically. Look for this kind of workflow, rather than interrupting sbt. – akauppi Apr 06 '15 at 18:55
12

SBT cannot benefit from the Fast Scala Compiler when you run it interactively (with or without using its continuous build mode) because the Scala compiler classes are loaded and get "warmed up" and JIT-ed, which is the entirety of fsc's advantage.

Erik Kaplun
  • 37,128
  • 15
  • 99
  • 111
Randall Schulz
  • 26,420
  • 4
  • 61
  • 81
  • But the fsc can run in the background even after SBT exited. – tstenner Oct 12 '10 at 11:03
  • 1
    The compile times reported clearly show that running compile again does not get much faster (the OP does not restart sbt between compiles). Fsc keeps the Java&Scala library classes loaded, while sbt will reload them each time. fsc's speedup is explained in Programming in Scala, and a comparison with sbt is made in passing here: http://code.google.com/p/simple-build-tool/wiki/ChangeDetectionAndTesting – Blaisorblade Aug 09 '11 at 00:36
2

At least for SBT 0.7.x the authors explain that it is not as fast as fsc, which caches the compiler instance (including the loaded libraries), rather than just the JITted compiler classes:

http://code.google.com/p/simple-build-tool/wiki/ChangeDetectionAndTesting

My experience also confirms that fsc is faster for full compiles, but does not automatically select what to recompile.

For SBT 0.10, I can find no docs whatsoever on this issue.

Blaisorblade
  • 6,438
  • 1
  • 43
  • 76
  • Update: finally with SBT 0.12.2 (or possibly earlier) SBT can keep the compiler itself resident. – Blaisorblade Jan 21 '13 at 22:35
  • is that something that's enabled by default or needs to be manually enabled? – Erik Kaplun Mar 19 '14 at 16:46
  • I think enabled by default, but I should check. – Blaisorblade Mar 19 '14 at 16:52
  • The only docs I found mention this as experimental, but that's only discussed for 0.12. https://groups.google.com/forum/#!searchin/simple-build-tool/resident$20compiler/simple-build-tool/aTd5hzUJXts/sTtqFxXiDZUJ http://www.scala-sbt.org/0.12.4/docs/Community/ChangeSummary_0.12.0.html#experimental-or-in-progress The code is still around in http://www.scala-sbt.org/0.13.1/sxr/sbt/compiler/AnalyzingCompiler.scala.html#sbt.compiler;AnalyzingCompiler.newCachedCompiler(50fb8bd74a).resident, so either support was completed or silently removed (which I wouldn't expect). – Blaisorblade Mar 19 '14 at 23:31
0

You don't need to do it anymore. Sbt has its own way now:

M.Rez
  • 1,802
  • 2
  • 21
  • 30
  • I would definitely welcome a joint compile backend for my IntelliJ IDE and command line (I work in both). However, this still looks to be in the concept level to me, or can I actually try it out, with current sbt (0.13.8) somehow? – akauppi Apr 06 '15 at 19:00
  • Can I actually use client/server on sbt 0.13.13? – akauppi Mar 29 '17 at 10:18
  • Status in March 2016: [sbt server reboot](http://eed3si9n.com/sbt-server-reboot) (blog) – akauppi Mar 29 '17 at 10:23