Removed indices from the descriptor serializations.
The reason they have been introduced initially was because those indices were calcuated irrelative to the descriptros themselves. The current scheme with hashing the mangled name allows to calcuate the indices for the descriptors, rather than storing them. The measurements didn't reveal any slowdowns because of hash recalculations, rather there may be even a minor improvement because of a 2% smaller volume of module protobuf.
This commit is contained in:
committed by
alexander-gorshenev
parent
31c490e14e
commit
2c1fa5e965
+7
-9
@@ -79,11 +79,11 @@ internal class IrDescriptorDeserializer(val context: Context,
|
||||
context.log{"### deserialized Kotlin Type index=$index, text=$text:\t$realType"}
|
||||
return realType
|
||||
}
|
||||
fun deserializeLocalDeclaration(proto: KonanLinkData.Descriptor): DeclarationDescriptor {
|
||||
fun deserializeLocalDeclaration(irProto: KonanIr.KotlinDescriptor, proto: KonanLinkData.Descriptor): DeclarationDescriptor {
|
||||
when {
|
||||
proto.hasFunction() -> {
|
||||
val functionProto = proto.function
|
||||
val index = functionProto.functionIndex
|
||||
val index = irProto.index
|
||||
val descriptor = localDeserializer.deserializeFunction(functionProto)
|
||||
descriptorIndex.put(index, descriptor)
|
||||
return descriptor
|
||||
@@ -91,7 +91,7 @@ internal class IrDescriptorDeserializer(val context: Context,
|
||||
|
||||
proto.hasProperty() -> {
|
||||
val propertyProto = proto.property
|
||||
val index = propertyProto.propertyIndex
|
||||
val index = irProto.index
|
||||
val descriptor = localDeserializer.deserializeProperty(propertyProto)
|
||||
descriptorIndex.put(index, descriptor)
|
||||
return descriptor
|
||||
@@ -136,7 +136,7 @@ internal class IrDescriptorDeserializer(val context: Context,
|
||||
|
||||
val descriptor = if (proto.hasIrLocalDeclaration()) {
|
||||
val realDescriptor = proto.irLocalDeclaration.descriptor
|
||||
deserializeLocalDeclaration(realDescriptor)
|
||||
deserializeLocalDeclaration(proto, realDescriptor)
|
||||
} else
|
||||
deserializeKnownDescriptor(proto)
|
||||
|
||||
@@ -345,8 +345,7 @@ internal class IrDescriptorDeserializer(val context: Context,
|
||||
|
||||
val originalIndex = descriptorProto.originalIndex
|
||||
val match = functions.singleOrNull() {
|
||||
val proto = (it as DeserializedSimpleFunctionDescriptor).proto
|
||||
proto.functionIndex == originalIndex
|
||||
it.uniqId == originalIndex
|
||||
} as? DeserializedSimpleFunctionDescriptor
|
||||
if (match != null) return match
|
||||
|
||||
@@ -370,8 +369,7 @@ internal class IrDescriptorDeserializer(val context: Context,
|
||||
|
||||
val originalIndex = descriptorProto.originalIndex
|
||||
return constructors.single {
|
||||
val proto = (it as DeserializedClassConstructorDescriptor).proto
|
||||
proto.constructorIndex == originalIndex
|
||||
it.uniqId == originalIndex
|
||||
} as DeserializedClassConstructorDescriptor
|
||||
}
|
||||
|
||||
@@ -389,7 +387,7 @@ internal class IrDescriptorDeserializer(val context: Context,
|
||||
val originalIndex = proto.originalIndex
|
||||
return functions.single {
|
||||
val property = (it as PropertyAccessorDescriptor).correspondingProperty as DeserializedPropertyDescriptor
|
||||
property.proto.propertyIndex == originalIndex
|
||||
property.uniqId == originalIndex
|
||||
} as PropertyAccessorDescriptor
|
||||
}
|
||||
|
||||
|
||||
+4
@@ -37,6 +37,10 @@ message KotlinDescriptor {
|
||||
optional LocalDeclaration ir_local_declaration = 12;
|
||||
}
|
||||
|
||||
message UniqId {
|
||||
required int64 index = 1;
|
||||
}
|
||||
|
||||
message LocalDeclaration {
|
||||
// This is Descriptor message from KonanLinkData
|
||||
required Descriptor descriptor = 1;
|
||||
|
||||
-10
@@ -15,35 +15,27 @@ option optimize_for = LITE_RUNTIME;
|
||||
|
||||
// Konan extensions to the "descriptors" protobuf.
|
||||
|
||||
message UniqId {
|
||||
required int64 index = 1;
|
||||
}
|
||||
|
||||
extend Package {
|
||||
optional int32 package_fq_name = 171;
|
||||
}
|
||||
|
||||
extend Class {
|
||||
repeated Annotation class_annotation = 170;
|
||||
optional UniqId class_index = 171;
|
||||
}
|
||||
|
||||
extend Constructor {
|
||||
repeated Annotation constructor_annotation = 170;
|
||||
optional UniqId constructor_index = 171;
|
||||
optional int32 constructor_parent = 172;
|
||||
}
|
||||
|
||||
extend Function {
|
||||
repeated Annotation function_annotation = 170;
|
||||
optional UniqId function_index = 171;
|
||||
optional int32 function_parent = 172;
|
||||
optional InlineIrBody inline_ir_body = 174;
|
||||
}
|
||||
|
||||
extend Property {
|
||||
repeated Annotation property_annotation = 170;
|
||||
optional UniqId property_index = 171;
|
||||
optional int32 property_parent = 172;
|
||||
optional bool used_as_variable = 173;
|
||||
optional Annotation.Argument.Value compile_time_value = 174;
|
||||
@@ -53,7 +45,6 @@ extend Property {
|
||||
|
||||
extend EnumEntry {
|
||||
repeated Annotation enum_entry_annotation = 170;
|
||||
optional UniqId enum_entry_index = 171;
|
||||
}
|
||||
|
||||
extend ValueParameter {
|
||||
@@ -62,7 +53,6 @@ extend ValueParameter {
|
||||
|
||||
extend Type {
|
||||
repeated Annotation type_annotation = 170;
|
||||
optional UniqId type_index = 171;
|
||||
optional string type_text = 172; // TODO: remove me
|
||||
}
|
||||
|
||||
|
||||
-12
@@ -66,8 +66,6 @@ internal class KonanSerializerExtension(val context: Context, val util: KonanSer
|
||||
|
||||
override fun serializeConstructor(descriptor: ConstructorDescriptor, proto: ProtoBuf.Constructor.Builder) {
|
||||
|
||||
proto.setConstructorIndex(
|
||||
inlineDescriptorTable.indexByValue(descriptor))
|
||||
val parentIndex = descriptor.parentFqNameIndex()
|
||||
if (parentIndex != null) proto.setExtension(KonanLinkData.constructorParent, parentIndex)
|
||||
|
||||
@@ -76,15 +74,11 @@ internal class KonanSerializerExtension(val context: Context, val util: KonanSer
|
||||
|
||||
override fun serializeClass(descriptor: ClassDescriptor, proto: ProtoBuf.Class.Builder) {
|
||||
|
||||
proto.setClassIndex(
|
||||
inlineDescriptorTable.indexByValue(descriptor))
|
||||
super.serializeClass(descriptor, proto)
|
||||
}
|
||||
|
||||
override fun serializeFunction(descriptor: FunctionDescriptor, proto: ProtoBuf.Function.Builder) {
|
||||
|
||||
proto.setFunctionIndex(
|
||||
inlineDescriptorTable.indexByValue(descriptor))
|
||||
val parentIndex = descriptor.parentFqNameIndex()
|
||||
if (parentIndex != null) proto.setExtension(KonanLinkData.functionParent, parentIndex)
|
||||
super.serializeFunction(descriptor, proto)
|
||||
@@ -102,12 +96,6 @@ internal class KonanSerializerExtension(val context: Context, val util: KonanSer
|
||||
val variable = originalVariables[descriptor]
|
||||
if (variable != null) {
|
||||
proto.setExtension(KonanLinkData.usedAsVariable, true)
|
||||
proto.setPropertyIndex(
|
||||
inlineDescriptorTable.indexByValue(variable))
|
||||
|
||||
} else {
|
||||
proto.setPropertyIndex(
|
||||
inlineDescriptorTable.indexByValue(descriptor))
|
||||
}
|
||||
|
||||
super.serializeProperty(descriptor, proto)
|
||||
|
||||
+2
-24
@@ -6,30 +6,8 @@ import org.jetbrains.kotlin.serialization.KonanLinkData.*
|
||||
import org.jetbrains.kotlin.serialization.ProtoBuf
|
||||
import org.jetbrains.kotlin.protobuf.GeneratedMessageLite
|
||||
|
||||
fun newUniqId(index: Long): KonanLinkData.UniqId =
|
||||
KonanLinkData.UniqId.newBuilder().setIndex(index).build()
|
||||
|
||||
val ProtoBuf.Function.functionIndex: Long
|
||||
get() = this.getExtension(KonanLinkData.functionIndex).index
|
||||
|
||||
val ProtoBuf.Constructor.constructorIndex: Long
|
||||
get() = this.getExtension(KonanLinkData.constructorIndex).index
|
||||
|
||||
val ProtoBuf.Property.propertyIndex: Long
|
||||
get() = this.getExtension(KonanLinkData.propertyIndex).index
|
||||
|
||||
|
||||
fun ProtoBuf.Function.Builder.setFunctionIndex(index: Long)
|
||||
= this.setExtension(KonanLinkData.functionIndex, newUniqId(index))
|
||||
|
||||
fun ProtoBuf.Constructor.Builder.setConstructorIndex(index: Long)
|
||||
= this.setExtension(KonanLinkData.constructorIndex, newUniqId(index))
|
||||
|
||||
fun ProtoBuf.Property.Builder.setPropertyIndex(index: Long)
|
||||
= this.setExtension(KonanLinkData.propertyIndex, newUniqId(index))
|
||||
|
||||
fun ProtoBuf.Class.Builder.setClassIndex(index: Long)
|
||||
= this.setExtension(KonanLinkData.classIndex, newUniqId(index))
|
||||
fun newUniqId(index: Long): KonanIr.UniqId =
|
||||
KonanIr.UniqId.newBuilder().setIndex(index).build()
|
||||
|
||||
// -----------------------------------------------------------
|
||||
|
||||
|
||||
Reference in New Issue
Block a user