platform: do not keep CheckedDisposable-s in disposed object weak-key map. It should allow to fix Disposer-s performance problems on client side (when Disposer.register/dispose triggered very often) IDEA-314139

GitOrigin-RevId: 9d0ca9cc3e1a7ff92971e97cb6ce73cfa225c26b
This commit is contained in:
Dmitry Batkovich
2023-03-09 13:10:58 +00:00
committed by intellij-monorepo-bot
parent f35952b792
commit baed10e426
2 changed files with 15 additions and 2 deletions
@@ -26,6 +26,7 @@ import com.intellij.openapi.progress.util.ProgressIndicatorUtils;
import com.intellij.openapi.project.Project;
import com.intellij.openapi.project.ex.ProjectEx;
import com.intellij.openapi.project.impl.ProjectImpl;
import com.intellij.openapi.util.CheckedDisposable;
import com.intellij.openapi.util.Disposer;
import com.intellij.openapi.util.Ref;
import com.intellij.openapi.vfs.VirtualFile;
@@ -272,10 +273,16 @@ public final class NonBlockingReadActionImpl<T> implements NonBlockingReadAction
cancel();
break;
}
//noinspection Convert2Lambda,Anonymous2MethodRef
Disposable child = new Disposable() { // not a lambda to create a separate object for each parent
Disposable child = new CheckedDisposable() {
private volatile boolean disposed;
@Override
public boolean isDisposed() {
return disposed;
}
@Override
public void dispose() {
disposed = true;
cancel();
}
};
@@ -79,6 +79,9 @@ final class ObjectTree {
}
}
boolean isDisposed(@NotNull Disposable object) {
if (object instanceof CheckedDisposable) {
return ((CheckedDisposable)object).isDisposed();
}
synchronized (getTreeLock()) {
return myDisposedObjects.get(object) != null;
}
@@ -231,6 +234,9 @@ final class ObjectTree {
// return old value
Throwable rememberDisposedTrace(@NotNull Disposable object, @Nullable Throwable trace) {
if (object instanceof CheckedDisposable) {
return null;
}
return myDisposedObjects.put(object, ObjectUtils.notNull(trace, UNKNOWN_TRACE));
}