ResolveElementCache: Use softly (not weakly) retained values
Fixes performance problems with long running searches analyzing function bodies several times
This commit is contained in:
@@ -22,10 +22,10 @@ import org.jetbrains.kotlin.resolve.BindingTrace;
|
||||
|
||||
public interface LazyResolveStorageManager extends StorageManager {
|
||||
@NotNull
|
||||
<K, V> MemoizedFunctionToNotNull<K, V> createWeaklyRetainedMemoizedFunction(@NotNull Function1<K, V> compute);
|
||||
<K, V> MemoizedFunctionToNotNull<K, V> createSoftlyRetainedMemoizedFunction(@NotNull Function1<K, V> compute);
|
||||
|
||||
@NotNull
|
||||
<K, V> MemoizedFunctionToNullable<K, V> createWeaklyRetainedMemoizedFunctionWithNullableValues(@NotNull Function1<K, V> compute);
|
||||
<K, V> MemoizedFunctionToNullable<K, V> createSoftlyRetainedMemoizedFunctionWithNullableValues(@NotNull Function1<K, V> compute);
|
||||
|
||||
@NotNull
|
||||
BindingTrace createSafeTrace(@NotNull BindingTrace originalTrace);
|
||||
|
||||
+5
-5
@@ -16,7 +16,6 @@
|
||||
|
||||
package org.jetbrains.kotlin.storage
|
||||
|
||||
import com.intellij.util.containers.ConcurrentWeakValueHashMap
|
||||
import org.jetbrains.annotations.TestOnly
|
||||
import org.jetbrains.kotlin.diagnostics.Diagnostic
|
||||
import org.jetbrains.kotlin.resolve.BindingContext
|
||||
@@ -24,13 +23,14 @@ import org.jetbrains.kotlin.resolve.BindingTrace
|
||||
import org.jetbrains.kotlin.util.slicedMap.ReadOnlySlice
|
||||
import org.jetbrains.kotlin.util.slicedMap.WritableSlice
|
||||
import org.jetbrains.kotlin.resolve.diagnostics.Diagnostics
|
||||
import com.intellij.util.containers.ConcurrentSoftValueHashMap
|
||||
|
||||
public class LockBasedLazyResolveStorageManager(private val storageManager: StorageManager): StorageManager by storageManager, LazyResolveStorageManager {
|
||||
override fun <K, V> createWeaklyRetainedMemoizedFunction(compute: Function1<K, V>) =
|
||||
storageManager.createMemoizedFunction<K, V>(compute, ConcurrentWeakValueHashMap<K, Any>())
|
||||
override fun <K, V> createSoftlyRetainedMemoizedFunction(compute: Function1<K, V>) =
|
||||
storageManager.createMemoizedFunction<K, V>(compute, ConcurrentSoftValueHashMap<K, Any>())
|
||||
|
||||
override fun <K, V> createWeaklyRetainedMemoizedFunctionWithNullableValues(compute: Function1<K, V>) =
|
||||
storageManager.createMemoizedFunctionWithNullableValues<K, V>(compute, ConcurrentWeakValueHashMap<K, Any>())
|
||||
override fun <K, V> createSoftlyRetainedMemoizedFunctionWithNullableValues(compute: Function1<K, V>) =
|
||||
storageManager.createMemoizedFunctionWithNullableValues<K, V>(compute, ConcurrentSoftValueHashMap<K, Any>())
|
||||
|
||||
// It seems safe to have a separate lock for traces:
|
||||
// no other locks will be acquired inside the trace operations
|
||||
|
||||
@@ -55,7 +55,7 @@ public class ResolveElementCache extends ElementResolver {
|
||||
ResolveSession resolveSession = ResolveElementCache.this.resolveSession;
|
||||
LazyResolveStorageManager manager = resolveSession.getStorageManager();
|
||||
MemoizedFunctionToNotNull<JetElement, BindingContext> elementsCacheFunction =
|
||||
manager.createWeaklyRetainedMemoizedFunction(new Function1<JetElement, BindingContext>() {
|
||||
manager.createSoftlyRetainedMemoizedFunction(new Function1<JetElement, BindingContext>() {
|
||||
@Override
|
||||
public BindingContext invoke(JetElement jetElement) {
|
||||
return elementAdditionalResolve(jetElement, jetElement, BodyResolveMode.FULL);
|
||||
|
||||
Reference in New Issue
Block a user