shared-indexes: rework chunks loading using API of IndexableFilesProvider instead of OrderEntry.

Shared indexes infrastructure used to be called too often, on every iteration by indexable files. We must search for and load shared indexes only when real indexing happens.

GitOrigin-RevId: 957194b2242067ffdb4f6bbe2eca32f9d97c89cc
This commit is contained in:
Sergey Patrikeev
2020-03-22 17:32:29 +00:00
committed by intellij-monorepo-bot
parent 7026d377c2
commit f04bcd8b66
3 changed files with 11 additions and 17 deletions
@@ -5,7 +5,6 @@ import com.intellij.ide.lightEdit.LightEdit;
import com.intellij.openapi.application.ReadAction;
import com.intellij.openapi.module.Module;
import com.intellij.openapi.module.ModuleManager;
import com.intellij.openapi.progress.EmptyProgressIndicator;
import com.intellij.openapi.progress.ProgressIndicator;
import com.intellij.openapi.progress.ProgressManager;
import com.intellij.openapi.project.Project;
@@ -332,8 +331,7 @@ public abstract class FileBasedIndexEx extends FileBasedIndex {
@Override
public void iterateIndexableFiles(@NotNull ContentIterator processor, @NotNull Project project, @Nullable ProgressIndicator indicator) {
final ProgressIndicator finalIndicator = indicator == null ? new EmptyProgressIndicator() : indicator;
List<IndexableFilesProvider> providers = getOrderedIndexableFilesProviders(project, finalIndicator);
List<IndexableFilesProvider> providers = getOrderedIndexableFilesProviders(project);
ConcurrentBitSet visitedFileSet = new ConcurrentBitSet();
for (IndexableFilesProvider provider : providers) {
if (!provider.iterateFiles(project, processor, visitedFileSet)) {
@@ -346,8 +344,7 @@ public abstract class FileBasedIndexEx extends FileBasedIndex {
* Returns providers of files to be indexed. Indexing is performed in the order corresponding to the resulting list.
*/
@NotNull
public List<IndexableFilesProvider> getOrderedIndexableFilesProviders(@NotNull Project project,
@NotNull ProgressIndicator indicator) {
public List<IndexableFilesProvider> getOrderedIndexableFilesProviders(@NotNull Project project) {
if (LightEdit.owns(project)) {
return Collections.emptyList();
}
@@ -358,7 +355,6 @@ public abstract class FileBasedIndexEx extends FileBasedIndex {
Set<Library> seenLibraries = new HashSet<>();
Set<Sdk> seenSdks = new HashSet<>();
Set<OrderEntry> allEntries = new THashSet<>();
List<IndexableFilesProvider> providers = new ArrayList<>();
Module[] modules = ModuleManager.getInstance(project).getSortedModules();
@@ -367,7 +363,6 @@ public abstract class FileBasedIndexEx extends FileBasedIndex {
OrderEntry[] orderEntries = ModuleRootManager.getInstance(module).getOrderEntries();
for (OrderEntry orderEntry : orderEntries) {
allEntries.add(orderEntry);
if (orderEntry instanceof LibraryOrderEntry) {
Library library = ((LibraryOrderEntry)orderEntry).getLibrary();
if (library != null && seenLibraries.add(library)) {
@@ -393,8 +388,6 @@ public abstract class FileBasedIndexEx extends FileBasedIndex {
}
}
FileBasedIndexInfrastructureExtension.EP_NAME.extensions().forEach(ex -> ex.processProjectEntries(project, allEntries, indicator));
return providers;
});
}
@@ -4,27 +4,26 @@ package com.intellij.util.indexing;
import com.intellij.openapi.extensions.ExtensionPointName;
import com.intellij.openapi.progress.ProgressIndicator;
import com.intellij.openapi.project.Project;
import com.intellij.openapi.roots.OrderEntry;
import com.intellij.openapi.vfs.VirtualFile;
import com.intellij.psi.stubs.StubIndexKey;
import com.intellij.util.indexing.roots.IndexableFilesProvider;
import org.jetbrains.annotations.ApiStatus;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import java.util.Set;
import java.util.List;
@ApiStatus.Internal
public interface FileBasedIndexInfrastructureExtension {
ExtensionPointName<FileBasedIndexInfrastructureExtension> EP_NAME = ExtensionPointName.create("com.intellij.fileBasedIndexInfrastructureExtension");
/**
* This notification is send from an IDE to let the extension point implementation
* update it's internal state in order to supply indexes for the given {@param entries}.
*
* Called every time when project structure is updated.
* This notification is sent from the IDE to let the extension point implementation
* update it's internal state in order to supply indexes for the given {@param providers}.
* Called every time the project structure is updated.
*/
void processProjectEntries(@NotNull Project project,
@NotNull Set<OrderEntry> entries,
@NotNull List<IndexableFilesProvider> providers,
@NotNull ProgressIndicator indicator);
@@ -87,7 +87,9 @@ public final class UnindexedFilesUpdater extends DumbModeTask {
snapshot = PerformanceWatcher.takeSnapshot();
List<IndexableFilesProvider> orderedProviders = myIndex.getOrderedIndexableFilesProviders(myProject, indicator);
List<IndexableFilesProvider> orderedProviders = myIndex.getOrderedIndexableFilesProviders(myProject);
FileBasedIndexInfrastructureExtension.EP_NAME.extensions().forEach(ex -> ex.processProjectEntries(myProject, orderedProviders, indicator));
Map<IndexableFilesProvider, List<VirtualFile>> providerToFiles = collectIndexableFilesConcurrently(myProject, indicator, orderedProviders);
if (trackResponsiveness) snapshot.logResponsivenessSinceCreation("Indexable file iteration");