Skip to content

Commit 4374d48

Browse files
committed
Eagerly initialize source to target map
The map is used later from notification panel from the UI thread and current workflow leads to UI freeze on source to target map initialization
1 parent 0adb0d1 commit 4374d48

File tree

3 files changed

+43
-2
lines changed

3 files changed

+43
-2
lines changed

base/src/META-INF/blaze-base.xml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<!--
2-
~ Copyright 2016 The Bazel Authors. All rights reserved.
2+
~ Copyright 2025 The Bazel Authors. All rights reserved.
33
~
44
~ Licensed under the Apache License, Version 2.0 (the "License");
55
~ you may not use this file except in compliance with the License.
@@ -625,6 +625,7 @@
625625

626626
<extensions defaultExtensionNs="com.google.idea.blaze">
627627
<SyncListener implementation="com.google.idea.blaze.base.sync.SyncCache$ClearSyncCache"/>
628+
<SyncListener implementation="com.google.idea.blaze.base.sync.SourceToTargetMapInitializer"/>
628629
<SyncListener implementation="com.google.idea.blaze.base.run.BlazeRunConfigurationSyncListener"/>
629630
<SyncListener implementation="com.google.idea.blaze.base.sync.status.BlazeSyncStatusListener" order="first"/>
630631
<SyncListener implementation="com.google.idea.blaze.base.dependencies.ExternalFileProjectManagementHelper$UpdateNotificationsAfterSync"/>
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
/*
2+
* Copyright 2025 The Bazel Authors. All rights reserved.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package com.google.idea.blaze.base.sync;
18+
19+
import com.google.common.collect.ImmutableSet;
20+
import com.google.idea.blaze.base.model.BlazeProjectData;
21+
import com.google.idea.blaze.base.projectview.ProjectViewSet;
22+
import com.google.idea.blaze.base.scope.BlazeContext;
23+
import com.google.idea.blaze.base.settings.BlazeImportSettings;
24+
import com.google.idea.blaze.base.targetmaps.SourceToTargetMap;
25+
import com.intellij.openapi.project.Project;
26+
import java.io.File;
27+
28+
public class SourceToTargetMapInitializer implements SyncListener {
29+
30+
@Override
31+
public void onSyncComplete(Project project, BlazeContext context,
32+
BlazeImportSettings importSettings, ProjectViewSet projectViewSet,
33+
ImmutableSet<Integer> buildIds, BlazeProjectData blazeProjectData, SyncMode syncMode,
34+
SyncResult syncResult) {
35+
// eagerly instantiate source to target map
36+
SourceToTargetMap.getInstance(project).getRulesForSourceFile(new File(""));
37+
}
38+
}

base/src/com/google/idea/blaze/base/targetmaps/AspectSyncSourceToTargetMap.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2016 The Bazel Authors. All rights reserved.
2+
* Copyright 2025 The Bazel Authors. All rights reserved.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -29,6 +29,7 @@
2929
import com.google.idea.blaze.base.sync.data.BlazeProjectDataManager;
3030
import com.google.idea.blaze.base.sync.workspace.ArtifactLocationDecoder;
3131
import com.intellij.openapi.project.Project;
32+
import com.intellij.util.concurrency.annotations.RequiresBackgroundThread;
3233
import java.io.File;
3334
import java.util.Objects;
3435
import javax.annotation.Nullable;
@@ -77,6 +78,7 @@ private synchronized ImmutableMultimap<File, TargetKey> getSourceToTargetMap() {
7778
}
7879

7980
@SuppressWarnings("unused")
81+
@RequiresBackgroundThread
8082
private static ImmutableMultimap<File, TargetKey> computeSourceToTargetMap(
8183
Project project, BlazeProjectData blazeProjectData) {
8284
ArtifactLocationDecoder decoder = blazeProjectData.getArtifactLocationDecoder();

0 commit comments

Comments
 (0)