mirror of https://github.com/sbt/sbt.git
Shave O(500ms) off of sbt startup
It turns out that it can take roughly one second to instantiate a scala.nsc.tools.Global instance for the first time. When sbt is starting up, it also takes nearly 2 seconds to initialize logging. We can speed up the boot time by doing these two things concurrently. On my machine, I saw on average a 500ms decrease in startup time after this change.
This commit is contained in:
parent
529ba8a3f2
commit
418e7e09fd
|
|
@ -44,6 +44,14 @@ final class xMain extends xsbti.AppMain {
|
|||
val instance = clazz.getField("MODULE$").get(null)
|
||||
val runMethod = clazz.getMethod("run", classOf[xsbti.AppConfiguration])
|
||||
try {
|
||||
new Thread("sbt-load-global-instance") {
|
||||
setDaemon(true)
|
||||
override def run(): Unit = {
|
||||
// This preloads the scala.tools.nsc.Global as a performance optimization"
|
||||
loader.loadClass("sbt.internal.parser.SbtParser$").getField("MODULE$").get(null)
|
||||
()
|
||||
}
|
||||
}.start()
|
||||
runMethod.invoke(instance, modifiedConfiguration).asInstanceOf[xsbti.MainResult]
|
||||
} catch {
|
||||
case e: InvocationTargetException =>
|
||||
|
|
|
|||
|
|
@ -108,7 +108,7 @@ private[sbt] object SbtParser {
|
|||
private[sbt] final val globalReporter = new UniqueParserReporter
|
||||
private[sbt] var scalacGlobalInitReporter: Option[ConsoleReporter] = None
|
||||
|
||||
private[sbt] final lazy val defaultGlobalForParser = {
|
||||
private[sbt] final val defaultGlobalForParser = {
|
||||
val options = "-cp" :: s"$defaultClasspath" :: "-Yrangepos" :: Nil
|
||||
val reportError = (msg: String) => System.err.println(msg)
|
||||
val command = new CompilerCommand(options, reportError)
|
||||
|
|
|
|||
Loading…
Reference in New Issue