Skip to content

Commit

Permalink
Reduce freeze times on updating search results on resource changes
Browse files Browse the repository at this point in the history
If the search view shows ~100000 matches, deleting resources that are
shown in the search view freezes Eclipse for many minutes. With this
change the freeze is only about 30 seconds.

See #2279
  • Loading branch information
iloveeclipse committed Sep 17, 2024
1 parent a43889d commit 675c75d
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 7 deletions.
2 changes: 1 addition & 1 deletion bundles/org.eclipse.search/META-INF/MANIFEST.MF
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ Manifest-Version: 1.0
Bundle-ManifestVersion: 2
Bundle-Name: %pluginName
Bundle-SymbolicName: org.eclipse.search; singleton:=true
Bundle-Version: 3.16.300.qualifier
Bundle-Version: 3.17.0.qualifier
Bundle-Activator: org.eclipse.search.internal.ui.SearchPlugin
Bundle-ActivationPolicy: lazy
Bundle-Vendor: %providerName
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import java.util.HashSet;
import java.util.Iterator;
import java.util.List;
import java.util.Map.Entry;
import java.util.Set;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.ConcurrentMap;
Expand Down Expand Up @@ -308,6 +309,19 @@ public int getMatchCount() {
return count;
}

/**
* @return {@code true} if the result is not empty
* @since 3.17
*/
public boolean hasMatches() {
for (Entry<Object, Set<Match>> entry : fElementsToMatches.entrySet()) {
if (!entry.getValue().isEmpty()) {
return true;
}
}
return false;
}

/**
* Returns the number of matches reported against a given element. This is
* equivalent to calling <code>getMatches(element).length</code>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,11 @@

import org.eclipse.core.resources.IProject;
import org.eclipse.core.resources.IResource;

import org.eclipse.jface.viewers.AbstractTreeViewer;
import org.eclipse.jface.viewers.ITreeContentProvider;
import org.eclipse.jface.viewers.Viewer;

import org.eclipse.search.ui.text.AbstractTextSearchResult;
import org.eclipse.search.ui.text.Match;
import org.eclipse.search.ui.text.MatchFilter;
Expand Down Expand Up @@ -177,17 +179,27 @@ private boolean hasMatches(Object element) {
if (element instanceof LineElement) {
LineElement lineElement= (LineElement) element;
IResource resource = lineElement.getParent();
if (getMatchCount(resource) > 0) {
if (hasMatches(resource)) {
return lineElement.hasMatches(fResult);
}
}
return fPage.getDisplayedMatchCount(element) > 0;
}

private boolean hasMatches(IResource element) {
if (hasActiveMatchFilters()) {
return fPage.getDisplayedMatchCount(element) > 0;
} else {
return fResult.hasMatches();
}
}

private int getMatchCount(Object element) {
return fResult.getActiveMatchFilters() != null && fResult.getActiveMatchFilters().length > 0
? fPage.getDisplayedMatchCount(element)
: fResult.getMatchCount();
if (hasActiveMatchFilters()) {
return fPage.getDisplayedMatchCount(element);
} else {
return fResult.getMatchCount();
}
}

private void removeFromSiblings(Object element, Object parent) {
Expand All @@ -207,7 +219,11 @@ public Object[] getChildren(Object parentElement) {

@Override
public boolean hasChildren(Object element) {
return getChildren(element).length > 0;
Set<Object> children = fChildrenMap.get(element);
if (children == null) {
return false;
}
return !children.isEmpty();
}

static <T> Stream<T> toStream(Enumeration<T> e) {
Expand Down Expand Up @@ -243,7 +259,7 @@ public synchronized void elementsChanged(Object[] updatedElements) {
Set<LineElement> lineMatches = Collections.emptySet();
// if we have active match filters, we should only use non-filtered FileMatch
// objects to collect LineElements to update
if (fResult.getActiveMatchFilters() != null && fResult.getActiveMatchFilters().length > 0) {
if (hasActiveMatchFilters()) {
lineMatches = Arrays.stream(updatedElements).filter(LineElement.class::isInstance)
// only for distinct files:
.map(u -> ((LineElement) u).getParent()).distinct()
Expand Down Expand Up @@ -292,6 +308,11 @@ public synchronized void elementsChanged(Object[] updatedElements) {
}
}

private boolean hasActiveMatchFilters() {
MatchFilter[] activeMatchFilters = fResult.getActiveMatchFilters();
return activeMatchFilters != null && activeMatchFilters.length > 0;
}

@Override
public void clear() {
initialize(fResult);
Expand Down

0 comments on commit 675c75d

Please sign in to comment.