1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-07-31 21:05:37 +02:00

Bug 509898 - IndexFileSet.containsDeclaration is slow and is causing UI

freezes

Added debug logging of time spent in IndexFileSet.containsDeclaration.

Change-Id: I4523abac4f56c4284ef03da5e82fd39b6dc1d412
This commit is contained in:
Sergey Prigogin 2017-02-05 18:30:58 -08:00
parent 6ddaed7dd7
commit 3bb38bf874
2 changed files with 24 additions and 2 deletions

View file

@ -47,6 +47,7 @@ import org.eclipse.cdt.core.model.ITranslationUnit;
import org.eclipse.cdt.core.parser.ISignificantMacros;
import org.eclipse.cdt.core.parser.util.ArrayUtil;
import org.eclipse.cdt.internal.core.index.IndexBasedFileContentProvider;
import org.eclipse.cdt.internal.core.index.IndexFileSet;
import org.eclipse.cdt.internal.core.parser.scanner.ILocationResolver;
import org.eclipse.cdt.internal.core.parser.scanner.ISkippedIndexedFilesListener;
import org.eclipse.cdt.internal.core.parser.scanner.InternalFileContent;
@ -459,6 +460,14 @@ public abstract class ASTTranslationUnit extends ASTNode implements IASTTranslat
return PROCESS_CONTINUE;
}
});
if (IndexFileSet.sDEBUG_INDEX_FILE_SET && fIndexFileSet != null && fASTFileSet != null) {
long t = ((IndexFileSet) fIndexFileSet).getTimingContainsDeclarationNanos() +
((IndexFileSet) fASTFileSet).getTimingContainsDeclarationNanos();
String forName = fOriginatingTranslationUnit == null ?
"" : " for " + fOriginatingTranslationUnit.getElementName(); //$NON-NLS-1$ //$NON-NLS-2$
System.out.println(String.format("IndexFileSet.containsDeclaration%s took %.2g ms", forName, t / 1.e6)); //$NON-NLS-1$
}
}
@Override

View file

@ -35,6 +35,7 @@ public class IndexFileSet implements IIndexFileSet {
private IIndexFileSet fInverse;
private final HashMap<IIndexFragment, IIndexFragmentFileSet> fSubSets= new HashMap<>();
private final Map<IBinding, Boolean> fDeclarationContainmentCache = new HashMap<>();
private long timingContainsDeclarationNanos;
public IndexFileSet() {
}
@ -69,6 +70,16 @@ public class IndexFileSet implements IIndexFileSet {
if (cachedValue != null)
return cachedValue;
long startTime = sDEBUG_INDEX_FILE_SET ? System.nanoTime() : 0;
boolean contains = computeContainsDeclaration(binding);
fDeclarationContainmentCache.put(binding, contains);
if (sDEBUG_INDEX_FILE_SET) {
timingContainsDeclarationNanos += System.nanoTime() - startTime;
}
return contains;
}
private boolean computeContainsDeclaration(IIndexBinding binding) {
int iterationCount = 0;
for (Map.Entry<IIndexFragment, IIndexFragmentFileSet> entry : fSubSets.entrySet()) {
IIndexFragment fragment = entry.getKey();
@ -83,7 +94,6 @@ public class IndexFileSet implements IIndexFileSet {
while ((nameRecord = nameIterator.next()) != 0) {
long fileRecord = PDOMName.getFileRecord(db, nameRecord);
if (pdomFileSet.containsFile(fileRecord)) {
fDeclarationContainmentCache.put(binding, true);
if (sDEBUG_INDEX_FILE_SET && iterationCount >= 200) {
System.out.println(
String.format("IndexFileSet: %s (%s) found after %d iterations", //$NON-NLS-1$
@ -113,10 +123,13 @@ public class IndexFileSet implements IIndexFileSet {
binding.getClass().getSimpleName(),
iterationCount));
}
fDeclarationContainmentCache.put(binding, false);
return false;
}
public long getTimingContainsDeclarationNanos() {
return timingContainsDeclarationNanos;
}
@Override
public boolean containsNonLocalDeclaration(IBinding binding, IIndexFragment ignore) {
for (Map.Entry<IIndexFragment, IIndexFragmentFileSet> entry : fSubSets.entrySet()) {