Optimize TaskProgress.containsSkipTasks

I was surprised to find this method in a flamegraph* so I optimized it.
TaskProgress was actually on the hotpath of task evaluation so every
single task was slower to be enqueued with the CompletionService. After
this change, containsSkipTasks dropped out of the flamegraph.

*The flamegraph was for a compile loop where sbt constantly modified a
single source file and re-compiled it. The containsSkipTasks method
appeared in over 2% of the method calls.
This commit is contained in:
Ethan Atkins 2020-05-04 17:46:26 -07:00
parent 77cc7285ae
commit 0a06bfe2d5
1 changed files with 12 additions and 2 deletions

View File

@ -128,6 +128,16 @@ private[sbt] final class TaskProgress(log: ManagedLogger)
}
}
private[this] def containsSkipTasks(tasks: Vector[Task[_]]): Boolean =
tasks.map(taskName).exists(n => skipReportTasks.exists(m => m == n || n.endsWith("/ " + m)))
private[this] def containsSkipTasks(tasks: Vector[Task[_]]): Boolean = {
tasks.map(taskName).exists { n =>
val shortName = n.lastIndexOf('/') match {
case -1 => n
case i =>
var j = i + 1
while (n(j) == ' ') j += 1
n.substring(j)
}
skipReportTasks.contains(shortName)
}
}
}