From 6b2161b5ec86394e36a0ddfe2acdda925c4de985 Mon Sep 17 00:00:00 2001 From: Alexander Gorshenev Date: Sat, 26 Jan 2019 05:40:37 +0300 Subject: [PATCH] Several performance tunings. --- .../kotlin/backend/konan/InlineClasses.kt | 5 ++- .../konan/serialization/DeclarationTable.kt | 43 ++++++++----------- platformLibs/build.gradle | 2 +- 3 files changed, 23 insertions(+), 27 deletions(-) diff --git a/backend.native/compiler/ir/backend.native/src/org/jetbrains/kotlin/backend/konan/InlineClasses.kt b/backend.native/compiler/ir/backend.native/src/org/jetbrains/kotlin/backend/konan/InlineClasses.kt index 8b0f51f02f9..ed3aafeae4c 100644 --- a/backend.native/compiler/ir/backend.native/src/org/jetbrains/kotlin/backend/konan/InlineClasses.kt +++ b/backend.native/compiler/ir/backend.native/src/org/jetbrains/kotlin/backend/konan/InlineClasses.kt @@ -202,7 +202,10 @@ private val implicitInlineClasses = KonanFqNames.nativePtr + InteropFqNames.cPointer).toSet() -private fun IrClass.getAllSuperClassifiers(): List = listOf(this) + this.superTypes.flatMap { (it.classifierOrFail.owner as IrClass).getAllSuperClassifiers() } +private val superQualifierTable = mutableMapOf>() +private fun IrClass.getAllSuperClassifiers(): List = superQualifierTable.getOrPut(this) { + listOf(this) + this.superTypes.flatMap { (it.classifierOrFail.owner as IrClass).getAllSuperClassifiers() } +} internal object KotlinTypeInlineClassesSupport : InlineClassesSupport() { diff --git a/backend.native/compiler/ir/backend.native/src/org/jetbrains/kotlin/backend/konan/serialization/DeclarationTable.kt b/backend.native/compiler/ir/backend.native/src/org/jetbrains/kotlin/backend/konan/serialization/DeclarationTable.kt index 8b922206754..38f79e2b5c8 100644 --- a/backend.native/compiler/ir/backend.native/src/org/jetbrains/kotlin/backend/konan/serialization/DeclarationTable.kt +++ b/backend.native/compiler/ir/backend.native/src/org/jetbrains/kotlin/backend/konan/serialization/DeclarationTable.kt @@ -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 MutableMap.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() 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 \ No newline at end of file + get() = irBuiltInsExternalPackageFragment.declarations diff --git a/platformLibs/build.gradle b/platformLibs/build.gradle index b9ec9fd967e..3fc1ddeb100 100644 --- a/platformLibs/build.gradle +++ b/platformLibs/build.gradle @@ -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) }