Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Reduce freeze in ProjectUpdater #7153

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
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)
}
}
}
}
}
Loading