Skip to content

Commit

Permalink
fix: Reduce freeze in ProjectUpdater (bazelbuild#7153)
Browse files Browse the repository at this point in the history
* fix: Reduce freeze in ProjectUpdater

closes bazelbuild#7149

* Allow to switch back to the old behavior (just in case)
  • Loading branch information
Tomasz Pasternak authored Dec 11, 2024
1 parent f5f8f24 commit bdb2b48
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 4 deletions.
3 changes: 3 additions & 0 deletions base/src/META-INF/blaze-base.xml
Original file line number Diff line number Diff line change
Expand Up @@ -424,6 +424,9 @@
<registryKey defaultValue="true"
description="Enable basic syntax highliting in Query Sync's 'Analysis Disabled' mode"
key="bazel.qsync.enable.basic.highlighting.in.non.analysis.mode"/>
<registryKey defaultValue="true"
description="Use coroutine-based ProjectUpdater implementation. It it is supposed to reduce the freeze that happens during sync"
key="bazel.qsync.enable.coroutine.project.updater"/>
<editorNotificationProvider implementation="com.google.idea.blaze.base.wizard2.BazelNotificationProvider"/>
</extensions>

Expand Down
8 changes: 4 additions & 4 deletions base/src/com/google/idea/blaze/base/qsync/ProjectUpdater.java
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@
import com.google.idea.blaze.qsync.project.ProjectPath;
import com.google.idea.blaze.qsync.project.ProjectProto;
import com.google.idea.blaze.qsync.project.ProjectProto.LibrarySource;
import com.google.idea.common.util.Transactions;
import com.intellij.openapi.externalSystem.service.project.IdeModifiableModelsProvider;
import com.intellij.openapi.externalSystem.service.project.ProjectDataManager;
import com.intellij.openapi.module.Module;
Expand Down Expand Up @@ -116,7 +115,7 @@ public void onNewProjectSnapshot(Context<?> context, QuerySyncProjectSnapshot gr

private void updateProjectModel(ProjectProto.Project spec, Context<?> context) {
File imlDirectory = new File(BlazeDataStorage.getProjectDataDir(importSettings), "modules");
Transactions.submitWriteActionTransactionAndWait(
ProjectUpdaterThreadingUtils.Companion.readWriteAction(
() -> {
IdeModifiableModelsProvider models =
ProjectDataManager.getInstance().createModifiableModelsProvider(project);
Expand Down Expand Up @@ -217,9 +216,10 @@ private void updateProjectModel(ProjectProto.Project spec, Context<?> context) {
.build(),
workspaceLanguageSettings);
}
models.commit();

}
});
return models;
}, models -> models.commit());
}

private Library getOrCreateLibrary(
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
package com.google.idea.blaze.base.qsync

import com.google.idea.common.util.Transactions
import com.intellij.openapi.application.readAndWriteAction
import com.intellij.openapi.diagnostic.Logger
import com.intellij.openapi.util.registry.Registry
import kotlinx.coroutines.runBlocking
import java.util.concurrent.Callable
import java.util.function.Consumer

class ProjectUpdaterThreadingUtils {
companion object {
val logger = Logger.getInstance(ProjectUpdaterThreadingUtils::class.java)
fun <T> readWriteAction(readPart: Callable<T>, commit: Consumer<T>) {
if (Registry.`is`("bazel.qsync.enable.coroutine.project.updater")) {
runBlocking {
readAndWriteAction {
logger.info("Starting read operation")
val ret = readPart.call()
writeAction {
commit.accept(ret)
}
}
}
} else {
Transactions.submitWriteActionTransactionAndWait {
val ret = readPart.call()
commit.accept(ret)
}
}
}
}
}

0 comments on commit bdb2b48

Please sign in to comment.