Skip to content

Commit 1ef1b58

Browse files
committed
perf(bulk-model-sync): parallelize export
1 parent 90add15 commit 1ef1b58

File tree

1 file changed

+12
-5
lines changed

1 file changed

+12
-5
lines changed

bulk-model-sync-mps/src/main/kotlin/org/modelix/mps/model/sync/bulk/MPSBulkSynchronizer.kt

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ import org.modelix.model.sync.bulk.ModelImporter
2727
import org.modelix.model.sync.bulk.import
2828
import org.modelix.model.sync.bulk.isModuleIncluded
2929
import java.io.File
30+
import java.util.concurrent.atomic.AtomicInteger
3031

3132
object MPSBulkSynchronizer {
3233

@@ -43,12 +44,18 @@ object MPSBulkSynchronizer {
4344
}
4445
val numIncludedModules = includedModules.count()
4546
val outputPath = System.getProperty("modelix.mps.model.sync.bulk.output.path")
47+
val counter = AtomicInteger()
4648

47-
for ((index, module) in includedModules.withIndex()) {
48-
println("Exporting module ${index + 1} of $numIncludedModules: '${module.moduleName}'")
49-
val exporter = ModelExporter(MPSModuleAsNode(module))
50-
val outputFile = File(outputPath + File.separator + module.moduleName + ".json")
51-
exporter.export(outputFile)
49+
includedModules.parallelStream().forEach { module ->
50+
val pos = counter.incrementAndGet()
51+
52+
repository.modelAccess.runReadAction {
53+
println("Exporting module $pos of $numIncludedModules: '${module.moduleName}'")
54+
val exporter = ModelExporter(MPSModuleAsNode(module))
55+
val outputFile = File(outputPath + File.separator + module.moduleName + ".json")
56+
exporter.export(outputFile)
57+
println("Exported module $pos of $numIncludedModules: '${module.moduleName}'")
58+
}
5259
}
5360
}
5461
}

0 commit comments

Comments
 (0)