performance: ignore whitespace during spell checking, fix test to perform actual inspections instead of skipping them altogether

This commit is contained in:
Alexey Kudravtsev
2016-05-17 14:20:36 +03:00
parent 34a7dafc46
commit f8a95baf80
3 changed files with 55 additions and 10 deletions
@@ -52,6 +52,9 @@ public class SpellcheckingStrategy {
@NotNull
public Tokenizer getTokenizer(PsiElement element) {
if (element instanceof PsiWhiteSpace) {
return EMPTY_TOKENIZER;
}
if (element instanceof PsiLanguageInjectionHost && InjectedLanguageUtil.hasInjections((PsiLanguageInjectionHost)element)) {
return EMPTY_TOKENIZER;
}
@@ -25,7 +25,7 @@ public abstract class SpellcheckerInspectionTestCase extends LightPlatformCodeIn
return true;
}
public static String getSpellcheckerTestDataPath() {
static String getSpellcheckerTestDataPath() {
return "/spellchecker/testData/";
}
@@ -34,7 +34,7 @@ public abstract class SpellcheckerInspectionTestCase extends LightPlatformCodeIn
myFixture.testHighlighting(false, false, true, file);
}
public static LocalInspectionTool[] getInspectionTools() {
static LocalInspectionTool[] getInspectionTools() {
return new LocalInspectionTool[]{new SpellCheckingInspection()};
}
}
@@ -15,10 +15,19 @@
*/
package com.intellij.spellchecker.inspection;
import com.intellij.codeHighlighting.Pass;
import com.intellij.codeHighlighting.TextEditorHighlightingPass;
import com.intellij.codeInsight.daemon.DaemonCodeAnalyzer;
import com.intellij.codeInsight.daemon.impl.HighlightInfo;
import com.intellij.codeInsight.daemon.impl.TextEditorHighlightingPassRegistrarEx;
import com.intellij.openapi.util.text.StringUtil;
import com.intellij.openapi.vfs.VirtualFile;
import com.intellij.testFramework.PlatformTestUtil;
import com.intellij.util.ThrowableRunnable;
import com.intellij.testFramework.fixtures.impl.CodeInsightTestFixtureImpl;
import com.intellij.util.ArrayUtil;
import org.jetbrains.annotations.NotNull;
import java.util.List;
/**
* @author peter
@@ -46,14 +55,47 @@ public class SpellcheckerPerformanceTest extends SpellcheckerInspectionTestCase
myFixture.enableInspections(getInspectionTools());
start = System.currentTimeMillis();
assertSize(typoCount, myFixture.doHighlighting());
assertSize(typoCount, runLocalInspections());
System.out.println("warm-up took " + (System.currentTimeMillis() - start) + " ms");
PlatformTestUtil.startPerformanceTest("many typos highlighting", 1000, new ThrowableRunnable() {
@Override
public void run() {
assertSize(typoCount, myFixture.doHighlighting());
}
}).cpuBound().useLegacyScaling().assertTiming();
PlatformTestUtil.startPerformanceTest("many typos highlighting", 10000, () -> {
DaemonCodeAnalyzer.getInstance(getProject()).restart();
assertSize(typoCount, runLocalInspections());
}).cpuBound().assertTiming();
}
public void testManyWhitespaces() {
final int count = 100000;
String text = StringUtil.repeat("//\n \t \t \n \n", count);
long start = System.currentTimeMillis();
VirtualFile file = myFixture.addFileToProject("foo.java", text).getVirtualFile();
System.out.println("creation took " + (System.currentTimeMillis() - start) + " ms");
start = System.currentTimeMillis();
myFixture.configureFromExistingVirtualFile(file);
System.out.println("configure took " + (System.currentTimeMillis() - start) + " ms");
start = System.currentTimeMillis();
List<HighlightInfo> infos = runLocalInspections();
assertEmpty(infos);
System.out.println("warm-up took " + (System.currentTimeMillis() - start) + " ms");
PlatformTestUtil.startPerformanceTest("many whitespaces highlighting", 4000, () -> {
DaemonCodeAnalyzer.getInstance(getProject()).restart();
assertEmpty(runLocalInspections());
}).cpuBound().assertTiming();
}
@NotNull
private List<HighlightInfo> runLocalInspections() {
myFixture.enableInspections(getInspectionTools());
TextEditorHighlightingPassRegistrarEx passRegistrar = TextEditorHighlightingPassRegistrarEx.getInstanceEx(getProject());
List<TextEditorHighlightingPass> passes = passRegistrar.instantiatePasses(myFixture.getFile(), myFixture.getEditor(), new int[0]);
int[] toIgnore = passes.stream().mapToInt(TextEditorHighlightingPass::getId).toArray();
int i = ArrayUtil.find(toIgnore, Pass.LOCAL_INSPECTIONS);
toIgnore[i] = 0; // ignore everything except Pass.LOCAL_INSPECTIONS
return CodeInsightTestFixtureImpl.instantiateAndRun(myFixture.getFile(), myFixture.getEditor(), toIgnore, false);
}
}