mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
[java] IDEA-370304 "Go to Declaration and Usages" seems to leak memory in both IntelliJ 2024.2 and 2024.3 (a lot of memory used by java PSI)
- simplify api GitOrigin-RevId: 104f02bbec697ff4ed6bc5ae02b17b01114d104e
This commit is contained in:
committed by
intellij-monorepo-bot
parent
80e44c7bad
commit
304ae1ace9
@@ -20,6 +20,7 @@
|
||||
package com.intellij.psi.impl;
|
||||
|
||||
import com.intellij.openapi.project.Project;
|
||||
import com.intellij.openapi.util.ThrowableComputable;
|
||||
import com.intellij.psi.JavaPsiFacade;
|
||||
import com.intellij.psi.PsiClass;
|
||||
import com.intellij.psi.search.GlobalSearchScope;
|
||||
@@ -27,8 +28,6 @@ import org.jetbrains.annotations.ApiStatus;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.TestOnly;
|
||||
|
||||
import java.util.concurrent.Callable;
|
||||
|
||||
public abstract class JavaPsiFacadeEx extends JavaPsiFacade {
|
||||
@TestOnly
|
||||
public static JavaPsiFacadeEx getInstanceEx(@NotNull Project project) {
|
||||
@@ -42,16 +41,16 @@ public abstract class JavaPsiFacadeEx extends JavaPsiFacade {
|
||||
* This method uses thread local variables to keep it state.
|
||||
*
|
||||
* @param <T> the type of the result returned by the callable
|
||||
* @param callable the callable to be executed within the temporary scope
|
||||
* @param computation the callable to be executed within the temporary scope
|
||||
* @return the result produced by the callable
|
||||
*/
|
||||
@ApiStatus.Internal
|
||||
public abstract <T> T withTemporaryScopeCaches(Callable<T> callable);
|
||||
public abstract <T, E extends Throwable> T withTemporaryScopeCaches(@NotNull ThrowableComputable<T, E> computation) throws E;
|
||||
|
||||
/**
|
||||
* @return true if temporary scope caches are enabled, otherwise false
|
||||
*
|
||||
* @see #withTemporaryScopeCaches(Callable)
|
||||
* @see #withTemporaryScopeCaches(ThrowableComputable)
|
||||
*/
|
||||
@ApiStatus.Internal
|
||||
public abstract boolean temporaryScopeCachesEnabled();
|
||||
|
||||
@@ -37,7 +37,6 @@ import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.util.*;
|
||||
import java.util.concurrent.Callable;
|
||||
import java.util.concurrent.ConcurrentMap;
|
||||
import java.util.function.Predicate;
|
||||
|
||||
@@ -68,8 +67,6 @@ public final class JavaPsiFacadeImpl extends JavaPsiFacadeEx {
|
||||
(coroutineScope == null ? bus.simpleConnect() : bus.connect(coroutineScope)).subscribe(PsiModificationTracker.TOPIC, () -> {
|
||||
myClassCache.clear();
|
||||
myPackageCache.clear();
|
||||
myCachedTemporaryScopes.get().clear();
|
||||
myCachedTemporaryScopes.remove();
|
||||
});
|
||||
|
||||
DummyHolderFactory.setFactory(new JavaDummyHolderFactory());
|
||||
@@ -87,7 +84,7 @@ public final class JavaPsiFacadeImpl extends JavaPsiFacadeEx {
|
||||
public PsiClass findClass(final @NotNull String qualifiedName, @NotNull GlobalSearchScope scope) {
|
||||
ProgressIndicatorProvider.checkCanceled(); // We hope this method is being called often enough to cancel daemon processes smoothly
|
||||
|
||||
if (myTemporaryScopeCacheEnabled.get()) {
|
||||
if (myTemporaryScopeCacheEnabled.get() && myClassCache.get(scope) == null) {
|
||||
myCachedTemporaryScopes.get().add(scope);
|
||||
}
|
||||
Map<String, Optional<PsiClass>> map = myClassCache.computeIfAbsent(scope, scope1 -> CollectionFactory.createConcurrentWeakValueMap());
|
||||
@@ -515,20 +512,16 @@ public final class JavaPsiFacadeImpl extends JavaPsiFacadeEx {
|
||||
|
||||
@ApiStatus.Internal
|
||||
@Override
|
||||
public <T> T withTemporaryScopeCaches(Callable<T> callable) {
|
||||
public <T, E extends Throwable> T withTemporaryScopeCaches(@NotNull ThrowableComputable<T, E> computation) throws E {
|
||||
Boolean previousValue = myTemporaryScopeCacheEnabled.get();
|
||||
myTemporaryScopeCacheEnabled.set(Boolean.TRUE);
|
||||
try {
|
||||
return callable.call();
|
||||
}
|
||||
catch (Exception e) {
|
||||
throw new RuntimeException(e);
|
||||
return computation.compute();
|
||||
}
|
||||
finally {
|
||||
for (GlobalSearchScope scope : myCachedTemporaryScopes.get()) {
|
||||
myClassCache.remove(scope);
|
||||
}
|
||||
myCachedTemporaryScopes.get().clear();
|
||||
myCachedTemporaryScopes.remove();
|
||||
myTemporaryScopeCacheEnabled.set(previousValue);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user