From 9765a5c4ceb875b02d72c90b405e958b96dbd01f Mon Sep 17 00:00:00 2001 From: Yuriy Artamonov Date: Wed, 2 Oct 2024 21:38:18 +0200 Subject: [PATCH] [performance] A lot of memory allocated from InspectionVisitorOptimizer.getTargetPsiClasses for lambdas GitOrigin-RevId: a7f330d3fd1633ee1d17040ba114a0daf4a42eb1 --- .../daemon/impl/InspectionVisitorOptimizer.java | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/platform/analysis-impl/src/com/intellij/codeInsight/daemon/impl/InspectionVisitorOptimizer.java b/platform/analysis-impl/src/com/intellij/codeInsight/daemon/impl/InspectionVisitorOptimizer.java index f8e2b8ad565a..e0c4308ded9a 100644 --- a/platform/analysis-impl/src/com/intellij/codeInsight/daemon/impl/InspectionVisitorOptimizer.java +++ b/platform/analysis-impl/src/com/intellij/codeInsight/daemon/impl/InspectionVisitorOptimizer.java @@ -35,6 +35,7 @@ import java.lang.reflect.Modifier; import java.util.*; import java.util.concurrent.atomic.AtomicReference; import java.util.function.Consumer; +import java.util.function.Function; /** * Infers classes of elements for inspection visitors to skip some of the PSI elements during inspection pass. @@ -80,6 +81,14 @@ public final class InspectionVisitorOptimizer { return acceptingPsiTypes; } + private static final Function, Collection>> TARGET_PSI_CLASSES_INIT = aSuper -> { + List> c = new ArrayList<>(10); + if (!aSuper.isInterface() && !Modifier.isAbstract(aSuper.getModifiers())) { // PSI elements in the tree cannot be abstract + c.add(aSuper); + } + return c; + }; + private static @NotNull Map, Collection>> getTargetPsiClasses(@NotNull List elements) { if (!useOptimizedVisitors) return Collections.emptyMap(); @@ -92,13 +101,7 @@ public final class InspectionVisitorOptimizer { // this check guarantees that items are unique in value collections, so we can use simple lists inside if (uniqueElementClasses.add(elementClass)) { for (Class aSuper : SELF_AND_SUPERS.get(elementClass)) { - Collection> classes = targetPsiClasses.computeIfAbsent(aSuper, aClass -> { - List> c = new ArrayList<>(10); - if (!aSuper.isInterface() && !Modifier.isAbstract(aSuper.getModifiers())) { // PSI elements in the tree cannot be abstract - c.add(aSuper); - } - return c; - }); + Collection> classes = targetPsiClasses.computeIfAbsent(aSuper, TARGET_PSI_CLASSES_INIT); classes.add(elementClass); } }