optimization: do not allocate primitive Long wrappers unnecessarily (part of KTIJ-27475 Investigate Kotlin plugin excessive memory usage)

GitOrigin-RevId: 34c2eb0d117de642da4adaeda61985287448c8de
This commit is contained in:
Alexey Kudravtsev
2023-10-20 15:18:55 +02:00
committed by intellij-monorepo-bot
parent d109fc8433
commit 84d0c3fe17

View File

@@ -29,6 +29,7 @@ import com.intellij.util.ExceptionUtil
import com.intellij.util.ObjectUtils
import com.intellij.util.concurrency.AppExecutorUtil
import com.intellij.util.containers.CollectionFactory
import com.intellij.util.containers.ConcurrentLongObjectHashMap
import io.opentelemetry.api.metrics.Meter
import org.jetbrains.annotations.NonNls
import org.jetbrains.annotations.TestOnly
@@ -73,7 +74,7 @@ internal open class EntityStorageSnapshotImpl(
// I suppose that we can use some kind of array of arrays to get a quicker access (just two accesses by-index)
// However, it's not implemented currently because I'm not sure about threading.
private val entitiesCache = ConcurrentHashMap<EntityId, WorkspaceEntity>()
private val entitiesCache = ConcurrentLongObjectHashMap<WorkspaceEntity>()
override fun <T> cached(query: StorageQuery<T>): T {
return snapshotCache.cached(query)
@@ -94,7 +95,7 @@ internal open class EntityStorageSnapshotImpl(
return found as T
}
val newData = newInstance()
entitiesCache[entityId] = newData
entitiesCache.put(entityId, newData)
return newData
}