Skip to content

Commit

Permalink
Skip computing working set when possible
Browse files Browse the repository at this point in the history
Computing the working set involves running few git commands, including git diff, it can be skipped if the "Expand Sync to Working Set" option is disabled.

The working set will be computed on each `collectProjectState` call, given that this method is triggered three times per sync operation, disabling unnecessary working set computations can reduce the sync times by roughly three times the duration typically taken by git diff operations.
  • Loading branch information
idanakav committed Aug 8, 2023
1 parent 0b1c58e commit b99aa06
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ public void requestProjectSync(BlazeSyncParams syncParams) {
try {
projectState =
ProjectStateSyncTask.collectProjectState(
project, context);
project, context, syncParams);
} catch (SyncCanceledException | SyncFailedException e) {
ApplicationManager.getApplication()
.invokeLater(
Expand Down
14 changes: 10 additions & 4 deletions base/src/com/google/idea/blaze/base/sync/ProjectStateSyncTask.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@

import com.google.common.collect.Iterables;
import com.google.common.collect.Lists;
import com.google.common.util.concurrent.Futures;
import com.google.common.util.concurrent.ListenableFuture;
import com.google.common.util.concurrent.ListeningExecutorService;
import com.google.idea.blaze.base.async.FutureUtil;
Expand Down Expand Up @@ -61,10 +62,10 @@
/** Collects information about the project state (VCS, blaze info, .blazeproject contents, etc.). */
final class ProjectStateSyncTask {

static SyncProjectState collectProjectState(Project project, BlazeContext context)
static SyncProjectState collectProjectState(Project project, BlazeContext context, BlazeSyncParams syncParams)
throws SyncCanceledException, SyncFailedException {
ProjectStateSyncTask task = new ProjectStateSyncTask(project);
return task.getProjectState(context);
return task.getProjectState(context, syncParams);
}

private final Project project;
Expand All @@ -77,7 +78,7 @@ private ProjectStateSyncTask(Project project) {
this.workspaceRoot = WorkspaceRoot.fromImportSettings(importSettings);
}

private SyncProjectState getProjectState(BlazeContext context)
private SyncProjectState getProjectState(BlazeContext context, BlazeSyncParams params)
throws SyncFailedException, SyncCanceledException {
if (!FileOperationProvider.getInstance().exists(workspaceRoot.directory())) {
String message = String.format("Workspace '%s' doesn't exist.", workspaceRoot.directory());
Expand Down Expand Up @@ -124,7 +125,12 @@ private SyncProjectState getProjectState(BlazeContext context)
importSettings.getBuildSystem(),
syncFlags);

ListenableFuture<WorkingSet> workingSetFuture = vcsHandler.getWorkingSet(context, executor);
ListenableFuture<WorkingSet> workingSetFuture;
if(params.addWorkingSet() || params.syncMode() == SyncMode.FULL) {
workingSetFuture = vcsHandler.getWorkingSet(context, executor);
} else {
workingSetFuture = Futures.immediateFuture(null);
}

BlazeInfo blazeInfo =
FutureUtil.waitForFuture(context, blazeInfoFuture)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -361,7 +361,7 @@ private void doFilterProjectTargets(
context,
childContext -> {
SyncProjectState projectState =
ProjectStateSyncTask.collectProjectState(project, context);
ProjectStateSyncTask.collectProjectState(project, context, params);
if (projectState == null) {
return;
}
Expand Down Expand Up @@ -436,7 +436,7 @@ void runSync(BlazeSyncParams params, boolean singleThreaded, BlazeContext contex
SyncStats.builder());
return;
}
SyncProjectState projectState = ProjectStateSyncTask.collectProjectState(project, context);
SyncProjectState projectState = ProjectStateSyncTask.collectProjectState(project, context, params);
BlazeSyncBuildResult buildResult =
BuildPhaseSyncTask.runBuildPhase(
project, params, projectState, buildId, context, buildSystem);
Expand Down

0 comments on commit b99aa06

Please sign in to comment.