mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-08-04 23:05:47 +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:
parent
6ddaed7dd7
commit
3bb38bf874
2 changed files with 24 additions and 2 deletions
|
@ -47,6 +47,7 @@ import org.eclipse.cdt.core.model.ITranslationUnit;
|
||||||
import org.eclipse.cdt.core.parser.ISignificantMacros;
|
import org.eclipse.cdt.core.parser.ISignificantMacros;
|
||||||
import org.eclipse.cdt.core.parser.util.ArrayUtil;
|
import org.eclipse.cdt.core.parser.util.ArrayUtil;
|
||||||
import org.eclipse.cdt.internal.core.index.IndexBasedFileContentProvider;
|
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.ILocationResolver;
|
||||||
import org.eclipse.cdt.internal.core.parser.scanner.ISkippedIndexedFilesListener;
|
import org.eclipse.cdt.internal.core.parser.scanner.ISkippedIndexedFilesListener;
|
||||||
import org.eclipse.cdt.internal.core.parser.scanner.InternalFileContent;
|
import org.eclipse.cdt.internal.core.parser.scanner.InternalFileContent;
|
||||||
|
@ -459,6 +460,14 @@ public abstract class ASTTranslationUnit extends ASTNode implements IASTTranslat
|
||||||
return PROCESS_CONTINUE;
|
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
|
@Override
|
||||||
|
|
|
@ -35,6 +35,7 @@ public class IndexFileSet implements IIndexFileSet {
|
||||||
private IIndexFileSet fInverse;
|
private IIndexFileSet fInverse;
|
||||||
private final HashMap<IIndexFragment, IIndexFragmentFileSet> fSubSets= new HashMap<>();
|
private final HashMap<IIndexFragment, IIndexFragmentFileSet> fSubSets= new HashMap<>();
|
||||||
private final Map<IBinding, Boolean> fDeclarationContainmentCache = new HashMap<>();
|
private final Map<IBinding, Boolean> fDeclarationContainmentCache = new HashMap<>();
|
||||||
|
private long timingContainsDeclarationNanos;
|
||||||
|
|
||||||
public IndexFileSet() {
|
public IndexFileSet() {
|
||||||
}
|
}
|
||||||
|
@ -69,6 +70,16 @@ public class IndexFileSet implements IIndexFileSet {
|
||||||
if (cachedValue != null)
|
if (cachedValue != null)
|
||||||
return cachedValue;
|
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;
|
int iterationCount = 0;
|
||||||
for (Map.Entry<IIndexFragment, IIndexFragmentFileSet> entry : fSubSets.entrySet()) {
|
for (Map.Entry<IIndexFragment, IIndexFragmentFileSet> entry : fSubSets.entrySet()) {
|
||||||
IIndexFragment fragment = entry.getKey();
|
IIndexFragment fragment = entry.getKey();
|
||||||
|
@ -83,7 +94,6 @@ public class IndexFileSet implements IIndexFileSet {
|
||||||
while ((nameRecord = nameIterator.next()) != 0) {
|
while ((nameRecord = nameIterator.next()) != 0) {
|
||||||
long fileRecord = PDOMName.getFileRecord(db, nameRecord);
|
long fileRecord = PDOMName.getFileRecord(db, nameRecord);
|
||||||
if (pdomFileSet.containsFile(fileRecord)) {
|
if (pdomFileSet.containsFile(fileRecord)) {
|
||||||
fDeclarationContainmentCache.put(binding, true);
|
|
||||||
if (sDEBUG_INDEX_FILE_SET && iterationCount >= 200) {
|
if (sDEBUG_INDEX_FILE_SET && iterationCount >= 200) {
|
||||||
System.out.println(
|
System.out.println(
|
||||||
String.format("IndexFileSet: %s (%s) found after %d iterations", //$NON-NLS-1$
|
String.format("IndexFileSet: %s (%s) found after %d iterations", //$NON-NLS-1$
|
||||||
|
@ -113,10 +123,13 @@ public class IndexFileSet implements IIndexFileSet {
|
||||||
binding.getClass().getSimpleName(),
|
binding.getClass().getSimpleName(),
|
||||||
iterationCount));
|
iterationCount));
|
||||||
}
|
}
|
||||||
fDeclarationContainmentCache.put(binding, false);
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public long getTimingContainsDeclarationNanos() {
|
||||||
|
return timingContainsDeclarationNanos;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean containsNonLocalDeclaration(IBinding binding, IIndexFragment ignore) {
|
public boolean containsNonLocalDeclaration(IBinding binding, IIndexFragment ignore) {
|
||||||
for (Map.Entry<IIndexFragment, IIndexFragmentFileSet> entry : fSubSets.entrySet()) {
|
for (Map.Entry<IIndexFragment, IIndexFragmentFileSet> entry : fSubSets.entrySet()) {
|
||||||
|
|
Loading…
Add table
Reference in a new issue