Use interner in LookupTracker implementations to reduce memory consuming
This commit is contained in:
Generated
+2
-1
@@ -2,8 +2,9 @@
|
||||
<dictionary name="bashor">
|
||||
<words>
|
||||
<w>ctor</w>
|
||||
<w>interner</w>
|
||||
<w>lookups</w>
|
||||
<w>unescape</w>
|
||||
</words>
|
||||
</dictionary>
|
||||
</component>
|
||||
</component>
|
||||
@@ -17,6 +17,7 @@
|
||||
package org.jetbrains.kotlin.incremental
|
||||
|
||||
import com.intellij.util.containers.MultiMap
|
||||
import com.intellij.util.containers.StringInterner
|
||||
import org.jetbrains.annotations.TestOnly
|
||||
import org.jetbrains.kotlin.incremental.components.LookupTracker
|
||||
import org.jetbrains.kotlin.incremental.components.Position
|
||||
@@ -62,8 +63,7 @@ open class LookupStorage(private val targetDataDir: File) : BasicMapsOwner() {
|
||||
}
|
||||
}
|
||||
|
||||
fun addAll(lookups: Set<Map.Entry<LookupSymbol, Collection<String>>>) {
|
||||
val allPaths = lookups.flatMapTo(HashSet<String>()) { it.value }
|
||||
fun addAll(lookups: Set<Map.Entry<LookupSymbol, Collection<String>>>, allPaths: Set<String>) {
|
||||
val pathToId = allPaths.keysToMap { addFileIfNeeded(File(it)) }
|
||||
|
||||
for ((lookupSymbol, paths) in lookups) {
|
||||
@@ -183,13 +183,19 @@ open class LookupStorage(private val targetDataDir: File) : BasicMapsOwner() {
|
||||
|
||||
class LookupTrackerImpl(private val delegate: LookupTracker) : LookupTracker {
|
||||
val lookups = MultiMap<LookupSymbol, String>()
|
||||
val pathInterner = StringInterner()
|
||||
private val interner = StringInterner()
|
||||
|
||||
override val requiresPosition: Boolean
|
||||
get() = delegate.requiresPosition
|
||||
|
||||
override fun record(filePath: String, position: Position, scopeFqName: String, scopeKind: ScopeKind, name: String) {
|
||||
lookups.putValue(LookupSymbol(name, scopeFqName), filePath)
|
||||
delegate.record(filePath, position, scopeFqName, scopeKind, name)
|
||||
val internedScopeFqName = interner.intern(scopeFqName)
|
||||
val internedName = interner.intern(name)
|
||||
val internedFilePath = pathInterner.intern(filePath)
|
||||
|
||||
lookups.putValue(LookupSymbol(internedName, internedScopeFqName), internedFilePath)
|
||||
delegate.record(internedFilePath, position, internedScopeFqName, scopeKind, internedName)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -16,26 +16,32 @@
|
||||
|
||||
package org.jetbrains.kotlin.daemon
|
||||
|
||||
import com.intellij.util.containers.StringInterner
|
||||
import org.jetbrains.kotlin.daemon.common.CompilerCallbackServicesFacade
|
||||
import org.jetbrains.kotlin.daemon.common.DummyProfiler
|
||||
import org.jetbrains.kotlin.daemon.common.Profiler
|
||||
import org.jetbrains.kotlin.incremental.components.LookupInfo
|
||||
import org.jetbrains.kotlin.incremental.components.LookupTracker
|
||||
import org.jetbrains.kotlin.incremental.components.Position
|
||||
import org.jetbrains.kotlin.incremental.components.ScopeKind
|
||||
import org.jetbrains.kotlin.daemon.common.CompilerCallbackServicesFacade
|
||||
import org.jetbrains.kotlin.daemon.common.DummyProfiler
|
||||
import org.jetbrains.kotlin.daemon.common.Profiler
|
||||
|
||||
|
||||
class RemoteLookupTrackerClient(val facade: CompilerCallbackServicesFacade, val eventManger: EventManger, val profiler: Profiler = DummyProfiler()) : LookupTracker {
|
||||
private val isDoNothing = profiler.withMeasure(this) { facade.lookupTracker_isDoNothing() }
|
||||
|
||||
private val lookups = hashSetOf<LookupInfo>()
|
||||
private val interner = StringInterner()
|
||||
|
||||
override val requiresPosition: Boolean = profiler.withMeasure(this) { facade.lookupTracker_requiresPosition() }
|
||||
|
||||
override fun record(filePath: String, position: Position, scopeFqName: String, scopeKind: ScopeKind, name: String) {
|
||||
if (isDoNothing) return
|
||||
|
||||
lookups.add(LookupInfo(filePath, position, scopeFqName, scopeKind, name))
|
||||
val internedFilePath = interner.intern(filePath)
|
||||
val internedScopeFqName = interner.intern(scopeFqName)
|
||||
val internedName = interner.intern(name)
|
||||
|
||||
lookups.add(LookupInfo(internedFilePath, position, internedScopeFqName, scopeKind, internedName))
|
||||
}
|
||||
|
||||
init {
|
||||
|
||||
@@ -542,7 +542,7 @@ class KotlinBuilder : ModuleLevelBuilder(BuilderCategory.SOURCE_PROCESSOR) {
|
||||
val removedFiles = chunk.targets.flatMap { KotlinSourceFileCollector.getRemovedKotlinFiles(dirtyFilesHolder, it) }
|
||||
removedFiles.forEach { lookupStorage.removeLookupsFrom(it) }
|
||||
|
||||
lookupStorage.addAll(lookupTracker.lookups.entrySet())
|
||||
lookupStorage.addAll(lookupTracker.lookups.entrySet(), lookupTracker.pathInterner.values)
|
||||
}
|
||||
|
||||
// if null is returned, nothing was done
|
||||
|
||||
@@ -17,6 +17,7 @@
|
||||
package org.jetbrains.kotlin.jps.build
|
||||
|
||||
import com.intellij.openapi.util.io.FileUtil
|
||||
import com.intellij.util.containers.StringInterner
|
||||
import org.jetbrains.kotlin.incremental.components.LookupInfo
|
||||
import org.jetbrains.kotlin.incremental.components.LookupTracker
|
||||
import org.jetbrains.kotlin.incremental.components.Position
|
||||
@@ -119,12 +120,17 @@ abstract class AbstractLookupTrackerTest : AbstractIncrementalJpsTest(
|
||||
|
||||
class TestLookupTracker : LookupTracker {
|
||||
val lookups = arrayListOf<LookupInfo>()
|
||||
private val interner = StringInterner()
|
||||
|
||||
override val requiresPosition: Boolean
|
||||
get() = true
|
||||
|
||||
override fun record(filePath: String, position: Position, scopeFqName: String, scopeKind: ScopeKind, name: String) {
|
||||
lookups.add(LookupInfo(filePath, position, scopeFqName, scopeKind, name))
|
||||
val internedFilePath = interner.intern(filePath)
|
||||
val internedScopeFqName = interner.intern(scopeFqName)
|
||||
val internedName = interner.intern(name)
|
||||
|
||||
lookups.add(LookupInfo(internedFilePath, position, internedScopeFqName, scopeKind, internedName))
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user