使用播放SBT自动重载,编译时间极慢!和scala-js

时间:2014-03-19 13:24:46

标签: scala playframework sbt

我遇到SBT问题。我的项目是这个的一个分支:https://github.com/vmunier/play-with-scalajs-example,目前几乎完全相同。我只添加了几行代码和导入的scalatags。

当我使用sbt启动服务器时,我运行该项目并且需要花费很多时间。自动重载功能也是如此。对于代码的任何更改,我每次都要谈论2到3分钟。即使对于SBT,这也太慢了。

SBT版本0.13.0 播放2.1版 Scala版本2.9.1 scalatags版本2.10 scalajs 0.2.4

这是SBT控制台中的输出

    [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

1 个答案:

答案 0 :(得分:2)

因为您正在使用scalatags和scala-js,它们是非常强大的编译器库,所以当您修改需要更改的代码时,编译时间会比平常多得多。您可以采取一些措施来缓解这种情况,升级到最新版本的Play(2.2.2),sbt(0.13.1)和scala(2.10.3),这些版本都在编译时提高了性能。如果您还没有使用增量编辑,我建议这样做(播放〜运行或播放〜测试快速)。还要检查你的内存限制(Xmx和MaxPermGen)以及你使用最新版本的JDK(7或8)。

使用最新版本我能够获得这些时间:

"进行测试"编译应用程序并测试并在173秒内运行所有测试

"播放"在已经编译之后启动Web应用程序需要10秒钟

" sbt run"在已经编译之后启动Web应用程序需要10秒钟

" sbt test"需要10-25秒

"进行测试"需要10-17秒

" sbt compile"干净后需要约20秒

这些时间是在具有SBT_OPTS =" -Xmx2048m"的Macbook Pro Retina上实现的。在.sbtconfig