From 27f77f2eba93a787545b338c9545fe5eea530a5e Mon Sep 17 00:00:00 2001 From: OneWay Date: Sun, 22 Nov 2026 18:15:49 +0800 Subject: [PATCH] perf(pipeline): remove fixed reindex delay and main-thread file snapshot The reindex pipeline slept for a fixed second after waiting for indexing to finish, even though the wait already blocks until the index is ready, and it listed the dictionary directory on the main thread. Drop the redundant sleep and take the directory snapshot on the IO dispatcher so the pipeline no longer stalls the UI thread. --- .../common/progress/DictionaryPipelineCoordinator.kt | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/app/src/main/java/com/example/research/common/progress/DictionaryPipelineCoordinator.kt b/app/src/main/java/com/example/research/common/progress/DictionaryPipelineCoordinator.kt index 8325335..2713e66 100644 --- a/app/src/main/java/com/example/research/common/progress/DictionaryPipelineCoordinator.kt +++ b/app/src/main/java/com/example/research/common/progress/DictionaryPipelineCoordinator.kt @@ -8,11 +8,9 @@ import kotlinx.coroutines.CoroutineDispatcher import kotlinx.coroutines.CoroutineScope import kotlinx.coroutines.Dispatchers import kotlinx.coroutines.Job -import kotlinx.coroutines.delay import kotlinx.coroutines.launch import kotlinx.coroutines.withContext import java.io.File -import kotlin.time.Duration.Companion.seconds class DictionaryPipelineCoordinator( private val scope: CoroutineScope, @@ -62,7 +60,9 @@ class DictionaryPipelineCoordinator( pipelineJob?.cancel() pipelineJob = scope.launch(launchDispatcher) { val dir = File(dictionaryPath()) - val filesBeforeReindex = dir.listFiles()?.map { it.name }?.toSet() ?: emptySet() + val filesBeforeReindex = withContext(ioDispatcher) { + dir.listFiles()?.map { it.name }?.toSet() ?: emptySet() + } try { triggerReindexing(isImport) if (isImport) { @@ -95,7 +95,6 @@ class DictionaryPipelineCoordinator( private suspend fun triggerReindexing(isImport: Boolean) = withContext(ioDispatcher) { steps.waitForIndexingCompletion() - delay(1.seconds) val path = dictionaryPath() if (isImport) {