Several performance tunings.

This commit is contained in:
Alexander Gorshenev
2019-01-26 05:40:37 +03:00
committed by alexander-gorshenev
parent e2ad488f28
commit 6b2161b5ec
3 changed files with 23 additions and 27 deletions
@@ -202,7 +202,10 @@ private val implicitInlineClasses =
KonanFqNames.nativePtr +
InteropFqNames.cPointer).toSet()
private fun IrClass.getAllSuperClassifiers(): List<IrClass> = listOf(this) + this.superTypes.flatMap { (it.classifierOrFail.owner as IrClass).getAllSuperClassifiers() }
private val superQualifierTable = mutableMapOf<IrClass, List<IrClass>>()
private fun IrClass.getAllSuperClassifiers(): List<IrClass> = superQualifierTable.getOrPut(this) {
listOf(this) + this.superTypes.flatMap { (it.classifierOrFail.owner as IrClass).getAllSuperClassifiers() }
}
internal object KotlinTypeInlineClassesSupport : InlineClassesSupport<ClassDescriptor, KotlinType>() {
@@ -6,17 +6,10 @@ import org.jetbrains.kotlin.ir.declarations.*
import org.jetbrains.kotlin.ir.declarations.impl.IrAnonymousInitializerImpl
import org.jetbrains.kotlin.ir.descriptors.IrBuiltIns
fun <K, V> MutableMap<K, V>.putOnce(k:K, v: V): Unit {
assert(!this.containsKey(k) || this[k] == v) {
"adding $v for $k, but it is already ${this[k]} for $k"
}
this.put(k, v)
}
class DescriptorTable {
private val descriptors = mutableMapOf<DeclarationDescriptor, Long>()
fun put(descriptor: DeclarationDescriptor, uniqId: UniqId) {
descriptors.putOnce(descriptor, uniqId.index)
descriptors.getOrPut(descriptor) { uniqId.index }
}
fun get(descriptor: DeclarationDescriptor) = descriptors[descriptor]
}
@@ -35,29 +28,29 @@ class DeclarationTable(val builtIns: IrBuiltIns, val descriptorTable: Descriptor
}
}
fun uniqIdByDeclaration(value: IrDeclaration): UniqId {
val index = table.getOrPut(value) {
fun uniqIdByDeclaration(value: IrDeclaration): UniqId = table.getOrPut(value) {
val index = if (value.origin == IrDeclarationOrigin.FAKE_OVERRIDE ||
!value.isExported()
|| value is IrVariable
|| value is IrTypeParameter
|| value is IrValueParameter
|| value is IrAnonymousInitializerImpl
) {
if (value.origin == IrDeclarationOrigin.FAKE_OVERRIDE ||
!value.isExported()
|| value is IrVariable
|| value is IrTypeParameter
|| value is IrValueParameter
|| value is IrAnonymousInitializerImpl
) {
UniqId(currentIndex++, true)
} else {
UniqId(value.uniqIdIndex, false)
}
UniqId(currentIndex++, true)
} else {
UniqId(value.uniqIdIndex, false)
}
debugIndex.put(index, "${if (index.isLocal) "" else value.uniqSymbolName()} descriptor = ${value.descriptor}")
// It can grow as large as 1/3 of ir/* size.
// debugIndex.put(index) {
// "${if (index.isLocal) "" else value.uniqSymbolName()} descriptor = ${value.descriptor}"
//}.also {it == null}
return index
index
}
}
// This is what we pre-populate tables with
val IrBuiltIns.knownBuiltins
get() = irBuiltInsExternalPackageFragment.declarations
get() = irBuiltInsExternalPackageFragment.declarations
+1 -1
View File
@@ -22,7 +22,7 @@ buildscript {
}
ext.konanHome = distDir.absolutePath
ext.jvmArgs = project.findProperty("platformLibsJvmArgs") ?: "-Xmx4G"
ext.jvmArgs = project.findProperty("platformLibsJvmArgs") ?: "-Xmx6G"
ext.setProperty("konan.home", konanHome)
ext.setProperty("konan.jvmArgs", jvmArgs)
}