Skip to content

Commit 19d3ce0

Browse files
authored
Merge pull request #4897 from gzm0/parallel-linker
Parallelize the Analyzer
2 parents f5dd469 + 9a0143c commit 19d3ce0

File tree

5 files changed

+483
-349
lines changed

5 files changed

+483
-349
lines changed
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
/*
2+
* Scala.js (https://www.scala-js.org/)
3+
*
4+
* Copyright EPFL.
5+
*
6+
* Licensed under Apache License 2.0
7+
* (https://www.apache.org/licenses/LICENSE-2.0).
8+
*
9+
* See the NOTICE file distributed with this work for
10+
* additional information regarding copyright ownership.
11+
*/
12+
13+
package org.scalajs.linker.analyzer
14+
15+
import scala.collection.mutable
16+
import scala.concurrent.ExecutionContext
17+
18+
private[analyzer] object Platform {
19+
def emptyThreadSafeMap[K, V]: mutable.Map[K, V] = mutable.Map.empty
20+
21+
def adjustExecutionContextForParallelism(ec: ExecutionContext,
22+
parallel: Boolean): ExecutionContext = {
23+
ec // we're never parallel on JS
24+
}
25+
}
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
/*
2+
* Scala.js (https://www.scala-js.org/)
3+
*
4+
* Copyright EPFL.
5+
*
6+
* Licensed under Apache License 2.0
7+
* (https://www.apache.org/licenses/LICENSE-2.0).
8+
*
9+
* See the NOTICE file distributed with this work for
10+
* additional information regarding copyright ownership.
11+
*/
12+
13+
package org.scalajs.linker.analyzer
14+
15+
import scala.collection.mutable
16+
import scala.collection.concurrent.TrieMap
17+
import scala.concurrent.ExecutionContext
18+
19+
import java.util.concurrent.Executors
20+
21+
private[analyzer] object Platform {
22+
def emptyThreadSafeMap[K, V]: mutable.Map[K, V] = TrieMap.empty
23+
24+
def adjustExecutionContextForParallelism(ec: ExecutionContext,
25+
parallel: Boolean): ExecutionContext = {
26+
/* Parallel is the default. Parallelism is disabled (likely for debugging),
27+
* we create our own single thread executor. This is for sure not the most
28+
* efficient, but it is simpler than, say, attempting to build single thread
29+
* execution on top of an arbitrary execution context.
30+
* Further, if parallel is false, we do not expect that speed is the primary
31+
* aim of the execution.
32+
*/
33+
if (parallel) ec
34+
else ExecutionContext.fromExecutorService(Executors.newSingleThreadExecutor())
35+
}
36+
}

linker/shared/src/main/scala/org/scalajs/linker/analyzer/Analysis.scala

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ object Analysis {
7878

7979
def linkedFrom: scala.collection.Seq[From]
8080
def instantiatedFrom: scala.collection.Seq[From]
81-
def dispatchCalledFrom: scala.collection.Map[MethodName, scala.collection.Seq[From]]
81+
def dispatchCalledFrom(methodName: MethodName): Option[scala.collection.Seq[From]]
8282
def methodInfos(
8383
namespace: MemberNamespace): scala.collection.Map[MethodName, MethodInfo]
8484

@@ -309,7 +309,7 @@ object Analysis {
309309
}
310310

311311
def followDispatch(fromDispatch: FromDispatch): Option[From] =
312-
fromDispatch.classInfo.dispatchCalledFrom.get(fromDispatch.methodName).flatMap(_.lastOption)
312+
fromDispatch.classInfo.dispatchCalledFrom(fromDispatch.methodName).flatMap(_.lastOption)
313313

314314
optFrom match {
315315
case None =>

0 commit comments

Comments
 (0)