aboutsummaryrefslogtreecommitdiff
path: root/core/src/main/kotlin
diff options
context:
space:
mode:
authorAndrzej Ratajczak <andrzej.ratajczak98@gmail.com>2020-09-22 11:08:16 +0200
committerAndrzej Ratajczak <32793002+BarkingBad@users.noreply.github.com>2020-10-02 12:40:50 +0200
commit8de5296b18083361055d11acf6d522c1eef821a4 (patch)
tree5e4f4c42bf801f33c40c4efeb5601e0fc4523e36 /core/src/main/kotlin
parent71b03f6d311c6ebfdf67c593e97a7483a64844f4 (diff)
downloaddokka-8de5296b18083361055d11acf6d522c1eef821a4.tar.gz
dokka-8de5296b18083361055d11acf6d522c1eef821a4.tar.bz2
dokka-8de5296b18083361055d11acf6d522c1eef821a4.zip
Make translators run in parallel.
Diffstat (limited to 'core/src/main/kotlin')
-rw-r--r--core/src/main/kotlin/DokkaGenerator.kt13
-rw-r--r--core/src/main/kotlin/plugability/LazyEvaluated.kt3
-rw-r--r--core/src/main/kotlin/transformers/sources/SourceToDocumentableTranslator.kt4
-rw-r--r--core/src/main/kotlin/utilities/parallelCollectionOperations.kt17
4 files changed, 29 insertions, 8 deletions
diff --git a/core/src/main/kotlin/DokkaGenerator.kt b/core/src/main/kotlin/DokkaGenerator.kt
index 6f42b259..bee85325 100644
--- a/core/src/main/kotlin/DokkaGenerator.kt
+++ b/core/src/main/kotlin/DokkaGenerator.kt
@@ -9,6 +9,8 @@ import org.jetbrains.dokka.plugability.DokkaContext
import org.jetbrains.dokka.plugability.DokkaPlugin
import org.jetbrains.dokka.utilities.DokkaLogger
import org.jetbrains.dokka.utilities.report
+import kotlinx.coroutines.*
+import org.jetbrains.dokka.utilities.parallelMap
/**
@@ -73,9 +75,10 @@ class DokkaGenerator(
fun createDocumentationModels(
context: DokkaContext
- ) = context.configuration.sourceSets
- .flatMap { sourceSet -> translateSources(sourceSet, context) }
- .also { modules -> if (modules.isEmpty()) exitGenerationGracefully("Nothing to document") }
+ ) = runBlocking(Dispatchers.Default) {
+ context.configuration.sourceSets.parallelMap { sourceSet -> translateSources(sourceSet, context) }.flatten()
+ .also { modules -> if (modules.isEmpty()) exitGenerationGracefully("Nothing to document") }
+ }
fun transformDocumentationModelBeforeMerge(
modulesFromPlatforms: List<DModule>,
@@ -133,8 +136,8 @@ class DokkaGenerator(
}
}
- private fun translateSources(sourceSet: DokkaSourceSet, context: DokkaContext) =
- context[CoreExtensions.sourceToDocumentableTranslator].map {
+ private suspend fun translateSources(sourceSet: DokkaSourceSet, context: DokkaContext) =
+ context[CoreExtensions.sourceToDocumentableTranslator].parallelMap {
it.invoke(sourceSet, context)
}
}
diff --git a/core/src/main/kotlin/plugability/LazyEvaluated.kt b/core/src/main/kotlin/plugability/LazyEvaluated.kt
index c0c271f4..17fad525 100644
--- a/core/src/main/kotlin/plugability/LazyEvaluated.kt
+++ b/core/src/main/kotlin/plugability/LazyEvaluated.kt
@@ -2,6 +2,7 @@ package org.jetbrains.dokka.plugability
internal class LazyEvaluated<T : Any> private constructor(private val recipe: ((DokkaContext) -> T)? = null, private var value: T? = null) {
+ @Synchronized
internal fun get(context: DokkaContext): T {
if(value == null) {
value = recipe?.invoke(context)
@@ -13,4 +14,4 @@ internal class LazyEvaluated<T : Any> private constructor(private val recipe: ((
fun <T : Any> fromInstance(value: T) = LazyEvaluated(value = value)
fun <T : Any> fromRecipe(recipe: (DokkaContext) -> T) = LazyEvaluated(recipe = recipe)
}
-} \ No newline at end of file
+}
diff --git a/core/src/main/kotlin/transformers/sources/SourceToDocumentableTranslator.kt b/core/src/main/kotlin/transformers/sources/SourceToDocumentableTranslator.kt
index 6bc8fb14..8ac59a15 100644
--- a/core/src/main/kotlin/transformers/sources/SourceToDocumentableTranslator.kt
+++ b/core/src/main/kotlin/transformers/sources/SourceToDocumentableTranslator.kt
@@ -5,5 +5,5 @@ import org.jetbrains.dokka.model.DModule
import org.jetbrains.dokka.plugability.DokkaContext
interface SourceToDocumentableTranslator {
- fun invoke(sourceSet: DokkaSourceSet, context: DokkaContext): DModule
-} \ No newline at end of file
+ suspend fun invoke(sourceSet: DokkaSourceSet, context: DokkaContext): DModule
+}
diff --git a/core/src/main/kotlin/utilities/parallelCollectionOperations.kt b/core/src/main/kotlin/utilities/parallelCollectionOperations.kt
new file mode 100644
index 00000000..b3191e8b
--- /dev/null
+++ b/core/src/main/kotlin/utilities/parallelCollectionOperations.kt
@@ -0,0 +1,17 @@
+package org.jetbrains.dokka.utilities
+
+import kotlinx.coroutines.async
+import kotlinx.coroutines.awaitAll
+import kotlinx.coroutines.coroutineScope
+
+suspend inline fun <A, B> Iterable<A>.parallelMap(crossinline f: suspend (A) -> B): List<B> = coroutineScope {
+ map { async { f(it) } }.awaitAll()
+}
+
+suspend inline fun <A, B> Iterable<A>.parallelMapNotNull(crossinline f: suspend (A) -> B?): List<B> = coroutineScope {
+ map { async { f(it) } }.awaitAll().filterNotNull()
+}
+
+suspend inline fun <A> Iterable<A>.parallelForEach(crossinline f: suspend (A) -> Unit): Unit = coroutineScope {
+ map { async { f(it) } }.awaitAll()
+}