Don't do progress work on the main thread

I noticed that no-op compile was slower in
https://github.com/sbt/sbt/issues/5508 using 1.4.0-RC2 than 1.4.0-RC1.
It took around 400ms with 1.4.0-RC2 and 200-250ms on RC1. Git bisect
brought me to 41afe9fbdb which I
remembered I'd been slightly concerned about from a performance
perspective but didn't get around to testing. The problem is that we
were blocking the task from running while determing whether or not we
should force a progress report. We can do that work on the background
thread instead so the task can begin running immediately.
This commit is contained in:
Ethan Atkins 2020-09-23 12:09:31 -07:00
parent 4ec6339794
commit d930cb1987
1 changed files with 9 additions and 4 deletions

View File

@ -107,10 +107,15 @@ private[sbt] class TaskProgress(
override def afterReady(task: Task[_]): Unit =
if (!closed.get) {
if (skipReportTasks.contains(getShortName(task))) {
lastTaskCount.set(-1) // force a report for remote clients
report()
} else Util.ignoreResult(active.put(task, schedule(threshold, recurring = false)(doReport())))
try {
Util.ignoreResult(executor.submit((() => {
if (skipReportTasks.contains(getShortName(task))) {
lastTaskCount.set(-1) // force a report for remote clients
report()
} else
Util.ignoreResult(active.put(task, schedule(threshold, recurring = false)(doReport())))
}): Runnable))
} catch { case _: RejectedExecutionException => }
} else {
logger.debug(s"called afterReady for ${taskName(task)} after task progress was closed")
}