From abb43ce593acacbfb68126fc892a18eda1148ad3 Mon Sep 17 00:00:00 2001 From: Martin Odersky Date: Fri, 4 Feb 2011 15:52:19 +0000 Subject: Presentation compiler yields now to be nicer to... Presentation compiler yields now to be nicer to UI thread. --- src/compiler/scala/tools/nsc/interactive/Global.scala | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/src/compiler/scala/tools/nsc/interactive/Global.scala b/src/compiler/scala/tools/nsc/interactive/Global.scala index e4befdc1dd..033776e7eb 100644 --- a/src/compiler/scala/tools/nsc/interactive/Global.scala +++ b/src/compiler/scala/tools/nsc/interactive/Global.scala @@ -208,12 +208,24 @@ self => var moreWorkAtNode: Int = -1 var nodesSeen = 0 + /** The number of pollForWorks after which the presentation compiler yields. + * Yielding improves responsiveness on systems with few cores because it + * gives the UI thread a chance to get new tasks and interrupt the presentation + * compiler with them. + */ + final val yieldPeriod = 8 + /** Called from runner thread and signalDone: * Poll for interrupts and execute them immediately. * Then, poll for exceptions and execute them. * Then, poll for work reload/typedTreeAt/doFirst commands during background checking. + * @param pos The position of the tree if polling while typechecking, NoPosition otherwise + * */ def pollForWork(pos: Position) { + if (pos == NoPosition || nodesSeen % yieldPeriod == 0) + Thread.`yield`() + def nodeWithWork(): Option[WorkEvent] = if (scheduler.moreWork || pendingResponse.isCancelled) Some(new WorkEvent(nodesSeen, System.currentTimeMillis)) else None -- cgit v1.2.3