Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Extremely slow compile time with SBT auto-reload using play! and scala-js

i'm having problems with SBT. My project is a fork of this: https://github.com/vmunier/play-with-scalajs-example and at the moment is pretty much identical. I've only added a few lines of code and imported scalatags.

When i launch the server with sbt, i run the project and it takes a lot of time. The same is true for the auto-reload function. I'm talking about 2 to 3 minutes every time, for any change to the code. This is way too slow even for SBT.

SBT Version 0.13.0 Play Version 2.1 Scala version 2.9.1 scalatags version 2.10 scalajs 0.2.4

This is the output in the SBT console

    [info] Compiling 1 Scala source to /home/chobeat/git/2048-in-scala-js/scalajs/target/scala-2.10/classes...
[info] Preoptimizing /home/chobeat/git/2048-in-scala-js/scalajvm/public/javascripts/scalajs/scalajs-example-preopt.js ...
[warn] Referring to non-existent class scala_scalajs_test_JasmineTest
[warn] Referring to non-existent method example_test_ScalaJSExampleTest$.expect__Lscala_scalajs_js_Any__Lorg_scalajs_jasmine_JasmineExpectation
[warn]   called from example_test_ScalaJSExampleTest$$anonfun$1$$anonfun$apply$mcV$sp$1.apply$mcV$sp__V
[warn]   called from example_test_ScalaJSExampleTest$$anonfun$1$$anonfun$apply$mcV$sp$1.apply__V
[warn]   called from example_test_ScalaJSExampleTest$$anonfun$1$$anonfun$apply$mcV$sp$1.apply__O
[warn]   called from scala_Predef$.require__Z__Lscala_Function0__V
[warn]   called from scala_collection_Iterator$class.scala_collection_Iterator$class__copyToArray__Lscala_collection_Iterator__O__I__I__V
[warn]   called from scala_collection_AbstractIterator.copyToArray__O__I__I__V
[warn]   called from scala_collection_TraversableOnce$class.scala_collection_TraversableOnce$class__copyToArray__Lscala_collection_TraversableOnce__O__I__V
[warn]   called from scala_collection_AbstractTraversable.copyToArray__O__I__V
[warn]   called from scala_collection_TraversableOnce$class.scala_collection_TraversableOnce$class__toArray__Lscala_collection_TraversableOnce__Lscala_reflect_ClassTag__O
[warn]   called from scala_collection_AbstractTraversable.toArray__Lscala_reflect_ClassTag__O
[warn]   called from scala_collection_immutable_StringLike$class.scala_collection_immutable_StringLike$class__format__Lscala_collection_immutable_StringLike__Lscala_collection_Seq__T
[warn]   called from scala_collection_immutable_StringOps.format__Lscala_collection_Seq__T
[warn]   called from scala_collection_immutable_Range.description__p4__T
[warn]   called from scala_collection_immutable_Range.fail__p4__Lscala_Nothing
[warn]   called from scala_collection_immutable_Range.scala$collection$immutable$Range$$validateMaxLength__V
[warn]   called from scala_collection_immutable_Range.validateRangeBoundaries__Lscala_Function1__Z
[warn]   called from scala_collection_immutable_Range.foreach__Lscala_Function1__V
[warn]   called from scala_collection_TraversableOnce$class.scala_collection_TraversableOnce$class__foldLeft__Lscala_collection_TraversableOnce__O__Lscala_Function2__O
[warn]   called from scala_collection_AbstractTraversable.foldLeft__O__Lscala_Function2__O
[warn]   called from scala_collection_generic_TraversableForwarder$class.scala_collection_generic_TraversableForwarder$class__foldLeft__Lscala_collection_generic_TraversableForwarder__O__Lscala_Function2__O
[warn]   called from scala_collection_mutable_ListBuffer.foldLeft__O__Lscala_Function2__O
[warn]   called from scala_collection_immutable_ListSet$ListSetBuilder.result__Lscala_collection_immutable_ListSet
[warn]   called from scala_collection_immutable_ListSet$ListSetBuilder.result__O
[warn]   called from scala_collection_TraversableLike$class.scala_collection_TraversableLike$class__flatMap__Lscala_collection_TraversableLike__Lscala_Function1__Lscala_collection_generic_CanBuildFrom__O
[warn]   called from scala_collection_immutable_Stream.flatMap__Lscala_Function1__Lscala_collection_generic_CanBuildFrom__O
[warn]   called from scala_collection_immutable_Stream$StreamBuilder.result__Lscala_collection_immutable_Stream
[warn]   called from scala_collection_immutable_Stream$StreamBuilder.result__O
[warn]   called from scala_collection_generic_GenericCompanion.empty__Lscala_collection_GenTraversable
[warn]   called from scala_collection_generic_GenericSetTemplate$class.scala_collection_generic_GenericSetTemplate$class__empty__Lscala_collection_generic_GenericSetTemplate__Lscala_collection_GenSet
[warn]   called from scala_collection_AbstractSet.empty__Lscala_collection_GenSet
[warn]   called from scala_collection_immutable_Set$Set2.empty__Lscala_collection_Set
[warn]   called from scala_collection_SetLike$class.scala_collection_SetLike$class__newBuilder__Lscala_collection_SetLike__Lscala_collection_mutable_Builder
[warn]   called from scala_collection_AbstractSet.newBuilder__Lscala_collection_mutable_Builder
[warn]   called from scala_collection_IterableLike$class.scala_collection_IterableLike$class__take__Lscala_collection_IterableLike__I__O
[warn]   called from scala_collection_AbstractIterable.take__I__O
[warn]   called from scala_collection_mutable_ListBuffer.$$plus$plus$eq__Lscala_collection_TraversableOnce__Lscala_collection_mutable_ListBuffer
[warn]   called from scala_collection_mutable_ListBuffer.$$plus$plus$eq__Lscala_collection_TraversableOnce__Lscala_collection_generic_Growable
[warn]   called from scala_collection_TraversableOnce$class.scala_collection_TraversableOnce$class__to__Lscala_collection_TraversableOnce__Lscala_collection_generic_CanBuildFrom__O
[warn]   called from scala_collection_AbstractIterator.to__Lscala_collection_generic_CanBuildFrom__O
[warn]   called from scala_collection_TraversableOnce$class.scala_collection_TraversableOnce$class__toSet__Lscala_collection_TraversableOnce__Lscala_collection_immutable_Set
[warn]   called from scala_collection_AbstractTraversable.toSet__Lscala_collection_immutable_Set
[warn]   called from scala_runtime_ScalaRunTime$.init___
[warn]   called from scala_scalajs_js_JavaScriptException.hashCode__I
[warn]   called from java_lang_Object.toString__T
[warn]   called from scalajs-corejslib.js
[warn] involving instantiated classes:
[warn]   example_test_ScalaJSExampleTest$$anonfun$1$$anonfun$apply$mcV$sp$1
[warn]   scala_Predef$
[warn]   scala_collection_immutable_StreamIterator
[warn]   scala_collection_immutable_HashSet$HashSet1
[warn]   scala_collection_immutable_StringOps
[warn]   scala_collection_immutable_Range
[warn]   scala_collection_mutable_ListBuffer
[warn]     (already seen, not repeating call stack)
[warn]   scala_collection_immutable_ListSet$ListSetBuilder
[warn]     (already seen, not repeating call stack)
[warn]   scala_collection_immutable_Stream$Cons
[warn]     (already seen, not repeating call stack)
[warn]   scala_collection_immutable_Stream$StreamBuilder
[warn]   scala_collection_Traversable$
[warn]     (already seen, not repeating call stack)
[warn]   scala_collection_immutable_Set$Set2
[warn]     (already seen, not repeating call stack)
[warn]   scala_collection_Iterator$$anon$2
[warn]   scala_collection_immutable_Nil$
[warn]     (already seen, not repeating call stack)
[warn]   scala_scalajs_js_JavaScriptException
[warn]   java_lang_Object
[warn] Referring to non-existent method example_test_ScalaJSExampleTest$.describe__T__Lscala_Function0__V
[warn]   called from example_test_ScalaJSExampleTest$.init___
[warn]   exported to JavaScript with @JSExport
[warn] Referring to non-existent method example_test_ScalaJSExampleTest$.it__T__Lscala_Function0__V
[warn]   called from example_test_ScalaJSExampleTest$.init___
[warn]   exported to JavaScript with @JSExport
like image 697
Chobeat Avatar asked Mar 19 '14 13:03

Chobeat


1 Answers

Because you're using scalatags and scala-js which are very compiler intensive libraries you will have much longer compile times than usual when you modify code that requires changes. Some things you can do to mitigate this are upgrade to the latest versions of Play (2.2.2), sbt (0.13.1), and scala (2.10.3) which have all made performance improvements in respect to compile time. If you are not already using the incremental compilations I would suggest doing so (play ~run or play ~test-quick). Also check your memory limits (Xmx and MaxPermGen) and that you're using the latest version of the JDK (either 7 or 8).

Using the latest versions I was able to get these times:

"play test" compiled the app and tests and ran all tests in 173 seconds

"play run" takes 10 seconds to start the web app after its already been compiled

"sbt run" takes 10 seconds to start the web app after its already been compiled

"sbt test" takes 10-25 seconds

"play test" takes 10-17 seconds

"sbt compile" takes ~20 seconds after clean

These times were achieved on a Macbook Pro Retina with SBT_OPTS="-Xmx2048m" in .sbtconfig

like image 152
Jason Pearson Avatar answered Oct 18 '22 04:10

Jason Pearson