From 7c7c0c2670fba9c3f0f905cbdcfd4245f2f8a3bc Mon Sep 17 00:00:00 2001 From: Alexey Kudravtsev Date: Wed, 4 Feb 2026 18:02:28 +0100 Subject: [PATCH] IJPL-233100 Major degradation in the performance of inspections for Java and Kotlin necromancer should run updateFoldingAsync with quick=true GitOrigin-RevId: 9e0b4ab57a0fc9505fe14ce9d27ece36a53743b7 --- .../folding/impl/CodeFoldingManagerImpl.java | 15 +++++++++++---- .../folding/impl/CodeFoldingNecromancer.kt | 4 ++-- .../codeInsight/folding/impl/FoldingUpdate.java | 11 ++++++----- .../intellij/testFramework/EditorTestUtil.java | 3 ++- 4 files changed, 21 insertions(+), 12 deletions(-) diff --git a/platform/foldings/src/com/intellij/codeInsight/folding/impl/CodeFoldingManagerImpl.java b/platform/foldings/src/com/intellij/codeInsight/folding/impl/CodeFoldingManagerImpl.java index 935280dbd148..482b621aa031 100644 --- a/platform/foldings/src/com/intellij/codeInsight/folding/impl/CodeFoldingManagerImpl.java +++ b/platform/foldings/src/com/intellij/codeInsight/folding/impl/CodeFoldingManagerImpl.java @@ -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 diff --git a/platform/foldings/src/com/intellij/codeInsight/folding/impl/CodeFoldingNecromancer.kt b/platform/foldings/src/com/intellij/codeInsight/folding/impl/CodeFoldingNecromancer.kt index 61c766a80799..fddd5ca19718 100644 --- a/platform/foldings/src/com/intellij/codeInsight/folding/impl/CodeFoldingNecromancer.kt +++ b/platform/foldings/src/com/intellij/codeInsight/folding/impl/CodeFoldingNecromancer.kt @@ -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() + val codeFoldingManager = project.serviceAsync() as CodeFoldingManagerImpl val psiDocumentManager = project.serviceAsync() 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 { diff --git a/platform/foldings/src/com/intellij/codeInsight/folding/impl/FoldingUpdate.java b/platform/foldings/src/com/intellij/codeInsight/folding/impl/FoldingUpdate.java index 39cbc312060a..2dd5b1955c8b 100644 --- a/platform/foldings/src/com/intellij/codeInsight/folding/impl/FoldingUpdate.java +++ b/platform/foldings/src/com/intellij/codeInsight/folding/impl/FoldingUpdate.java @@ -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 elementsToFold = getFoldingsFor(psiFile, false); + List elementsToFold = getFoldingsFor(psiFile, quick); UpdateFoldRegionsOperation operation = new UpdateFoldRegionsOperation(project, editor, psiFile, elementsToFold, applyDefaultStateMode(applyDefaultState), !applyDefaultState, false); diff --git a/platform/testFramework/src/com/intellij/testFramework/EditorTestUtil.java b/platform/testFramework/src/com/intellij/testFramework/EditorTestUtil.java index fb7ccb508a26..bc8064916609 100644 --- a/platform/testFramework/src/com/intellij/testFramework/EditorTestUtil.java +++ b/platform/testFramework/src/com/intellij/testFramework/EditorTestUtil.java @@ -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();