Skip to content

Commit 1e8baf2

Browse files
committed
perf(devins-lang): move DevInsCompiler.compile() to IO dispatcher
- Update DevInsCompiler.compile() to run on IO dispatcher using withContext - This change improves performance by offloading the compilation task to a separate thread - Ensures that the compilation process does not block the main thread, enhancing responsiveness
1 parent ceba185 commit 1e8baf2

File tree

1 file changed

+4
-2
lines changed
  • exts/devins-lang/src/main/kotlin/cc/unitmesh/devti/language/compiler

1 file changed

+4
-2
lines changed

exts/devins-lang/src/main/kotlin/cc/unitmesh/devti/language/compiler/DevInsCompiler.kt

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@ import com.intellij.openapi.project.guessProjectDir
2424
import com.intellij.openapi.util.NlsSafe
2525
import com.intellij.psi.PsiElement
2626
import com.intellij.psi.util.elementType
27+
import kotlinx.coroutines.Dispatchers
28+
import kotlinx.coroutines.withContext
2729

2830
val CACHED_COMPILE_RESULT = mutableMapOf<String, DevInsCompiledResult>()
2931

@@ -41,7 +43,7 @@ class DevInsCompiler(
4143
/**
4244
* Todo: build AST tree, then compile
4345
*/
44-
suspend fun compile(): DevInsCompiledResult {
46+
suspend fun compile(): DevInsCompiledResult = withContext(Dispatchers.IO) {
4547
result.input = runReadAction { file.text }
4648
val children = runReadAction { file.children }
4749
children.forEach {
@@ -82,7 +84,7 @@ class DevInsCompiler(
8284
result.output = output.toString()
8385

8486
CACHED_COMPILE_RESULT[file.name] = result
85-
return result
87+
return@withContext result
8688
}
8789

8890
suspend fun processUsed(used: DevInUsed) {

0 commit comments

Comments
 (0)