IDEA-325274 Search Everywhere: long delay before first results on All tab

GitOrigin-RevId: 846b9dca853812f65cbc2aa5788eb5e584a40bc8
This commit is contained in:
Mikhail Sokolov
2023-10-12 18:04:03 +00:00
committed by intellij-monorepo-bot
parent e4d6a1b5fb
commit 8bb4d145d6
9 changed files with 43 additions and 12 deletions
@@ -0,0 +1,18 @@
// Copyright 2000-2023 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license.
package com.intellij.ide.actions.searcheverywhere;
/**
* This is marker interface for an Essential Contributor. During the search process, it is guaranteed
* that results are not displayed until all contributions marked as Essential have returned items
* (or have completed processing with no results).
*/
public interface EssentialContributor {
default boolean isEssential() {
return true;
}
static boolean checkEssential(SearchEverywhereContributor<?> contributor) {
return (contributor instanceof EssentialContributor ic) && ic.isEssential();
}
}
@@ -1,6 +1,14 @@
// Copyright 2000-2022 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license.
package com.intellij.ide.actions.searcheverywhere;
/**
* This marker interface represents contributors that may process items slowly. The search process can start
* displaying initial results without waiting for input from such contributors.
*
* Currently, this interface is not in use. By default, all contributors are
* assumed slow unless they are explicitly marked as an {@link EssentialContributor}.
* Nevertheless, this interface may be repurposed and applied for enhanced checks in the future.
*/
public interface PossibleSlowContributor {
default boolean isSlow() {
@@ -41,7 +41,7 @@ import static com.intellij.ide.actions.searcheverywhere.footer.ExtendedInfoImplK
/**
* @author Konstantin Bulenkov
*/
public class ClassSearchEverywhereContributor extends AbstractGotoSEContributor {
public class ClassSearchEverywhereContributor extends AbstractGotoSEContributor implements EssentialContributor {
private static final Pattern ourPatternToDetectMembers = Pattern.compile("(.+)(#)(.*)");
private final PersistentSearchEverywhereContributorFilter<LanguageRef> filter;
@@ -41,7 +41,7 @@ import static com.intellij.ide.actions.searcheverywhere.footer.ExtendedInfoImplK
* @author Konstantin Bulenkov
* @author Mikhail Sokolov
*/
public class FileSearchEverywhereContributor extends AbstractGotoSEContributor {
public class FileSearchEverywhereContributor extends AbstractGotoSEContributor implements EssentialContributor {
private static final Logger LOG = Logger.getInstance(FileSearchEverywhereContributor.class);
private final GotoFileModel myModelForRenderer;
private final PersistentSearchEverywhereContributorFilter<FileTypeRef> myFilter;
@@ -33,7 +33,7 @@ import java.util.List;
import java.util.function.Function;
public final class PSIPresentationBgRendererWrapper implements WeightedSearchEverywhereContributor<Object>, ScopeSupporting,
AutoCompletionContributor, PossibleSlowContributor,
AutoCompletionContributor, PossibleSlowContributor, EssentialContributor,
SearchEverywhereExtendedInfoProvider {
private final AbstractGotoSEContributor myDelegate;
@@ -51,6 +51,11 @@ public final class PSIPresentationBgRendererWrapper implements WeightedSearchEve
return PossibleSlowContributor.checkSlow(myDelegate);
}
@Override
public boolean isEssential() {
return EssentialContributor.checkEssential(myDelegate);
}
public static WeightedSearchEverywhereContributor<Object> wrapIfNecessary(AbstractGotoSEContributor delegate) {
if (Registry.is("psi.element.list.cell.renderer.background")) {
return new PSIPresentationBgRendererWrapper(delegate);
@@ -57,7 +57,7 @@ class SlowContributorDetector: SearchListener {
private fun logContributorFinished(contributor: SearchEverywhereContributor<*>) {
if (finishedContributors.containsKey(contributor.searchProviderId)) return
if (PossibleSlowContributor.checkSlow(contributor)) return //don't worry about contributors already marked as slow
if (!EssentialContributor.checkEssential(contributor)) return //don't worry about contributors which are not essential
finishedContributors[contributor.searchProviderId] = System.currentTimeMillis() - startTimestamp!!
}
@@ -81,7 +81,7 @@ class SlowContributorDetector: SearchListener {
private fun reportSlowContributor(id: String, delay: Long) {
LOG.warn("Contributor [$id] is too slow (took $delay ms to finish). Slow contributors should implement PossibleSlowContributor interface")
LOG.warn("Contributor [$id] is too slow (took $delay ms to finish). But it is marked as EssentialContributor and can slow down the search process")
}
private fun calculatePercentileEdge(delays: Collection<Long>): Long {
@@ -150,7 +150,7 @@ public final class WaitForContributorsListenerWrapper implements SearchListener,
cancelAllFlushTasks();
buffer.clearBuffer();
Map<? extends SearchEverywhereContributor<?>, Boolean> map = contributors.stream()
.filter(c -> !PossibleSlowContributor.checkSlow(c))
.filter(EssentialContributor::checkEssential)
.collect(Collectors.toMap(Function.identity(), c -> false));
contributorsMap.clear();
contributorsMap.putAll(map);
@@ -6,8 +6,8 @@ import com.intellij.util.Processor
import javax.swing.JPanel
import javax.swing.ListCellRenderer
fun createDumbContributor(id: String, showTab: Boolean = false, slow: Boolean = false): SearchEverywhereContributor<Unit> =
object : SearchEverywhereContributor<Unit>, PossibleSlowContributor {
fun createDumbContributor(id: String, showTab: Boolean = false, essential: Boolean = false): SearchEverywhereContributor<Unit> =
object : SearchEverywhereContributor<Unit>, EssentialContributor {
override fun getSearchProviderId(): String = id
override fun getGroupName(): String = id
override fun getSortWeight(): Int = 0
@@ -18,7 +18,7 @@ fun createDumbContributor(id: String, showTab: Boolean = false, slow: Boolean =
override fun processSelectedItem(selected: Unit, modifiers: Int, searchText: String): Boolean = false
override fun fetchElements(pattern: String, progressIndicator: ProgressIndicator, consumer: Processor<in Unit>) {}
override fun isSlow(): Boolean = slow
override fun isEssential(): Boolean = essential
override fun toString(): String = id
}
@@ -20,9 +20,9 @@ class SearchBufferedListenersTest : BasePlatformTestCase() {
private var myMockery: Mockery? = null
private val contributor1 = createDumbContributor("Test1")
private val contributor2 = createDumbContributor("Test2")
private val contributor3 = createDumbContributor("Test3(slow)", slow = true)
private val contributor1 = createDumbContributor("Test1", essential = true)
private val contributor2 = createDumbContributor("Test2", essential = true)
private val contributor3 = createDumbContributor("Test3(slow)")
private val c1_e1 = SearchEverywhereFoundElementInfoTest("c1_e1", contributor1)
private val c1_e2 = SearchEverywhereFoundElementInfoTest("c1_e2", contributor1)