IJPL-233100 Major degradation in the performance of inspections for Java and Kotlin

necromancer should run updateFoldingAsync with quick=true

GitOrigin-RevId: 9e0b4ab57a0fc9505fe14ce9d27ece36a53743b7
This commit is contained in:
Alexey Kudravtsev
2026-02-05 13:42:57 +00:00
committed by intellij-monorepo-bot
parent ddb1066c50
commit 7c7c0c2670
4 changed files with 21 additions and 12 deletions
@@ -264,7 +264,7 @@ public final class CodeFoldingManagerImpl extends CodeFoldingManager implements
return;
}
PsiDocumentManager.getInstance(myProject).commitDocument(editor.getDocument());
Runnable runnable = updateFoldRegions(editor, false);
Runnable runnable = updateFoldRegions(editor, false, false);
if (runnable != null) {
runnable.run();
}
@@ -274,12 +274,19 @@ public final class CodeFoldingManagerImpl extends CodeFoldingManager implements
@RequiresBackgroundThread
@RequiresReadLock
public @Nullable Runnable updateFoldRegionsAsync(@NotNull Editor editor, boolean firstTime) {
return updateFoldRegionsAsync(editor, firstTime, false);
}
@ApiStatus.Internal
@RequiresBackgroundThread
@RequiresReadLock
public @Nullable Runnable updateFoldRegionsAsync(@NotNull Editor editor, boolean firstTime, boolean quick) {
ThreadingAssertions.assertBackgroundThread();
ThreadingAssertions.assertReadAccess();
if (!editor.getSettings().isAutoCodeFoldingEnabled()) {
return null;
}
Runnable runnable = updateFoldRegions(editor, firstTime);
Runnable runnable = updateFoldRegions(editor, firstTime, quick);
return () -> {
if (runnable != null) {
runnable.run();
@@ -290,9 +297,9 @@ public final class CodeFoldingManagerImpl extends CodeFoldingManager implements
};
}
private @Nullable Runnable updateFoldRegions(@NotNull Editor editor, boolean firstTime) {
private @Nullable Runnable updateFoldRegions(@NotNull Editor editor, boolean firstTime, boolean quick) {
PsiFile psiFile = getPsiFileForFolding(myProject, editor.getDocument());
return psiFile == null ? null : FoldingUpdate.updateFoldRegions(editor, psiFile, firstTime);
return psiFile == null ? null : FoldingUpdate.updateFoldRegions(editor, psiFile, firstTime, quick);
}
@Override
@@ -89,7 +89,7 @@ private class CodeFoldingNecromancer(
override suspend fun spawnNoZombie(recipe: SpawnRecipe) {
val project = recipe.project
val document = recipe.document
val codeFoldingManager = project.serviceAsync<CodeFoldingManager>()
val codeFoldingManager = project.serviceAsync<CodeFoldingManager>() as CodeFoldingManagerImpl
val psiDocumentManager = project.serviceAsync<PsiDocumentManager>()
val editor = recipe.editorSupplier()
var modStamp:Long = 0
@@ -98,7 +98,7 @@ private class CodeFoldingNecromancer(
modStamp = document.modificationStamp
catchingExceptions {
blockingContextToIndicator {
codeFoldingManager.updateFoldRegionsAsync(editor, true)
codeFoldingManager.updateFoldRegionsAsync(editor, true, true)
}
}
} else {
@@ -68,7 +68,7 @@ public final class FoldingUpdate {
}
@RequiresReadLock
static @Nullable Runnable updateFoldRegions(@NotNull Editor editor, @NotNull PsiFile psiFile, boolean firstTime) {
static @Nullable Runnable updateFoldRegions(@NotNull Editor editor, @NotNull PsiFile psiFile, boolean firstTime, boolean quick) {
ApplicationManager.getApplication().assertReadAccessAllowed();
Project project = psiFile.getProject();
@@ -88,13 +88,13 @@ public final class FoldingUpdate {
}
}
if (firstTime) {
return getUpdateResult(psiFile, document, project, editor, true).getFirst();
return getUpdateResult(psiFile, document, project, editor, true, quick).getFirst();
}
return CachedValuesManager.getManager(project).getCachedValue(
editor, CODE_FOLDING_KEY, () -> {
PsiFile psiFile1 = CodeFoldingManagerImpl.getPsiFileForFolding(project, document);
Pair<@NotNull Runnable, @NotNull Object @NotNull []> result = getUpdateResult(psiFile1, document, project, editor, false);
Pair<@NotNull Runnable, @NotNull Object @NotNull []> result = getUpdateResult(psiFile1, document, project, editor, false, quick);
Runnable runnable = result.getFirst();
Object[] dependencies = result.getSecond();
return CachedValueProvider.Result.create(runnable, dependencies);
@@ -105,9 +105,10 @@ public final class FoldingUpdate {
@NotNull Document document,
@NotNull Project project,
@NotNull Editor editor,
boolean applyDefaultState) {
boolean applyDefaultState,
boolean quick) {
PsiUtilCore.ensureValid(psiFile);
List<RegionInfo> elementsToFold = getFoldingsFor(psiFile, false);
List<RegionInfo> elementsToFold = getFoldingsFor(psiFile, quick);
UpdateFoldRegionsOperation operation = new UpdateFoldRegionsOperation(project, editor, psiFile, elementsToFold,
applyDefaultStateMode(applyDefaultState),
!applyDefaultState, false);
@@ -4,6 +4,7 @@ package com.intellij.testFramework;
import com.intellij.codeInsight.daemon.impl.HighlightInfo;
import com.intellij.codeInsight.daemon.impl.IdentifierHighlighterPassFactory;
import com.intellij.codeInsight.folding.CodeFoldingManager;
import com.intellij.codeInsight.folding.impl.CodeFoldingManagerImpl;
import com.intellij.ide.DataManager;
import com.intellij.lang.Language;
import com.intellij.lang.folding.FoldingBuilder;
@@ -933,7 +934,7 @@ public final class EditorTestUtil {
if (psiFile == null || !supportsDumbModeFolding(psiFile)) {
return null;
}
return CodeFoldingManager.getInstance(project).updateFoldRegionsAsync(editor, true);
return ((CodeFoldingManagerImpl)CodeFoldingManager.getInstance(project)).updateFoldRegionsAsync(editor, true, true);
}).submit(AppExecutorUtil.getAppExecutorService()));
if (foldingState != null) {
foldingState.run();