From f04bcd8b6615e2991bd3c82caf4352675c58b571 Mon Sep 17 00:00:00 2001 From: Sergey Patrikeev Date: Sun, 22 Mar 2020 18:50:24 +0300 Subject: [PATCH] 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 --- .../intellij/util/indexing/FileBasedIndexEx.java | 11 ++--------- .../FileBasedIndexInfrastructureExtension.java | 13 ++++++------- .../util/indexing/UnindexedFilesUpdater.java | 4 +++- 3 files changed, 11 insertions(+), 17 deletions(-) diff --git a/platform/lang-impl/src/com/intellij/util/indexing/FileBasedIndexEx.java b/platform/lang-impl/src/com/intellij/util/indexing/FileBasedIndexEx.java index 02f23f751873..ff9d5b16edf1 100644 --- a/platform/lang-impl/src/com/intellij/util/indexing/FileBasedIndexEx.java +++ b/platform/lang-impl/src/com/intellij/util/indexing/FileBasedIndexEx.java @@ -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 providers = getOrderedIndexableFilesProviders(project, finalIndicator); + List 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 getOrderedIndexableFilesProviders(@NotNull Project project, - @NotNull ProgressIndicator indicator) { + public List getOrderedIndexableFilesProviders(@NotNull Project project) { if (LightEdit.owns(project)) { return Collections.emptyList(); } @@ -358,7 +355,6 @@ public abstract class FileBasedIndexEx extends FileBasedIndex { Set seenLibraries = new HashSet<>(); Set seenSdks = new HashSet<>(); - Set allEntries = new THashSet<>(); List 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; }); } diff --git a/platform/lang-impl/src/com/intellij/util/indexing/FileBasedIndexInfrastructureExtension.java b/platform/lang-impl/src/com/intellij/util/indexing/FileBasedIndexInfrastructureExtension.java index 1530a8835102..f94d9a7812c9 100644 --- a/platform/lang-impl/src/com/intellij/util/indexing/FileBasedIndexInfrastructureExtension.java +++ b/platform/lang-impl/src/com/intellij/util/indexing/FileBasedIndexInfrastructureExtension.java @@ -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 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 entries, + @NotNull List providers, @NotNull ProgressIndicator indicator); diff --git a/platform/lang-impl/src/com/intellij/util/indexing/UnindexedFilesUpdater.java b/platform/lang-impl/src/com/intellij/util/indexing/UnindexedFilesUpdater.java index cd734b19c6f3..e1091018b289 100644 --- a/platform/lang-impl/src/com/intellij/util/indexing/UnindexedFilesUpdater.java +++ b/platform/lang-impl/src/com/intellij/util/indexing/UnindexedFilesUpdater.java @@ -87,7 +87,9 @@ public final class UnindexedFilesUpdater extends DumbModeTask { snapshot = PerformanceWatcher.takeSnapshot(); - List orderedProviders = myIndex.getOrderedIndexableFilesProviders(myProject, indicator); + List orderedProviders = myIndex.getOrderedIndexableFilesProviders(myProject); + FileBasedIndexInfrastructureExtension.EP_NAME.extensions().forEach(ex -> ex.processProjectEntries(myProject, orderedProviders, indicator)); + Map> providerToFiles = collectIndexableFilesConcurrently(myProject, indicator, orderedProviders); if (trackResponsiveness) snapshot.logResponsivenessSinceCreation("Indexable file iteration");