[LL FIR] optimize FirCacheValue, do not create ConcurrentHashMap to store a single value
^KTIJ-24640 ^KTIJ-24641
This commit is contained in:
committed by
Space Team
parent
57da858810
commit
4c3672de0a
+4
@@ -8,6 +8,7 @@ package org.jetbrains.kotlin.analysis.low.level.api.fir.fir.caches
|
||||
import org.jetbrains.kotlin.fir.caches.FirCache
|
||||
import org.jetbrains.kotlin.fir.caches.FirCachesFactory
|
||||
import java.util.concurrent.ConcurrentHashMap
|
||||
import org.jetbrains.kotlin.fir.caches.FirLazyValue
|
||||
|
||||
object FirThreadSafeCachesFactory : FirCachesFactory() {
|
||||
override fun <KEY : Any, VALUE, CONTEXT> createCache(createValue: (KEY, CONTEXT) -> VALUE): FirCache<KEY, VALUE, CONTEXT> =
|
||||
@@ -29,4 +30,7 @@ object FirThreadSafeCachesFactory : FirCachesFactory() {
|
||||
postCompute: (KEY, VALUE, DATA) -> Unit
|
||||
): FirCache<KEY, VALUE, CONTEXT> =
|
||||
FirThreadSafeCacheWithPostCompute(createValue, postCompute)
|
||||
|
||||
override fun <V> createLazyValue(createValue: () -> V): FirLazyValue<V> =
|
||||
FirThreadSafeValue(createValue)
|
||||
}
|
||||
+13
@@ -0,0 +1,13 @@
|
||||
/*
|
||||
* Copyright 2010-2021 JetBrains s.r.o. and Kotlin Programming Language contributors.
|
||||
* Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
|
||||
*/
|
||||
|
||||
package org.jetbrains.kotlin.analysis.low.level.api.fir.fir.caches
|
||||
|
||||
import org.jetbrains.kotlin.fir.caches.FirLazyValue
|
||||
|
||||
internal class FirThreadSafeValue<V>(createValue: () -> V) : FirLazyValue<V>() {
|
||||
private val lazyValue by lazy(LazyThreadSafetyMode.SYNCHRONIZED, createValue)
|
||||
override fun getValue(): V = lazyValue
|
||||
}
|
||||
+1
-1
@@ -25,7 +25,7 @@ internal class LLFirIdeRegisteredPluginAnnotations(
|
||||
override val annotations: Set<AnnotationFqn>
|
||||
get() = allAnnotationsCache.getValue()
|
||||
|
||||
private val allAnnotationsCache: FirLazyValue<Set<AnnotationFqn>, Nothing?> = session.firCachesFactory.createLazyValue {
|
||||
private val allAnnotationsCache: FirLazyValue<Set<AnnotationFqn>> = session.firCachesFactory.createLazyValue {
|
||||
// at this point, both metaAnnotations and annotationsFromPlugins should be collected
|
||||
val result = metaAnnotations.flatMapTo(mutableSetOf()) { getAnnotationsWithMetaAnnotation(it) }
|
||||
|
||||
|
||||
Reference in New Issue
Block a user