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"}
|
context.log{"### deserialized Kotlin Type index=$index, text=$text:\t$realType"}
|
||||||
return realType
|
return realType
|
||||||
}
|
}
|
||||||
fun deserializeLocalDeclaration(proto: KonanLinkData.Descriptor): DeclarationDescriptor {
|
fun deserializeLocalDeclaration(irProto: KonanIr.KotlinDescriptor, proto: KonanLinkData.Descriptor): DeclarationDescriptor {
|
||||||
when {
|
when {
|
||||||
proto.hasFunction() -> {
|
proto.hasFunction() -> {
|
||||||
val functionProto = proto.function
|
val functionProto = proto.function
|
||||||
val index = functionProto.functionIndex
|
val index = irProto.index
|
||||||
val descriptor = localDeserializer.deserializeFunction(functionProto)
|
val descriptor = localDeserializer.deserializeFunction(functionProto)
|
||||||
descriptorIndex.put(index, descriptor)
|
descriptorIndex.put(index, descriptor)
|
||||||
return descriptor
|
return descriptor
|
||||||
@@ -91,7 +91,7 @@ internal class IrDescriptorDeserializer(val context: Context,
|
|||||||
|
|
||||||
proto.hasProperty() -> {
|
proto.hasProperty() -> {
|
||||||
val propertyProto = proto.property
|
val propertyProto = proto.property
|
||||||
val index = propertyProto.propertyIndex
|
val index = irProto.index
|
||||||
val descriptor = localDeserializer.deserializeProperty(propertyProto)
|
val descriptor = localDeserializer.deserializeProperty(propertyProto)
|
||||||
descriptorIndex.put(index, descriptor)
|
descriptorIndex.put(index, descriptor)
|
||||||
return descriptor
|
return descriptor
|
||||||
@@ -136,7 +136,7 @@ internal class IrDescriptorDeserializer(val context: Context,
|
|||||||
|
|
||||||
val descriptor = if (proto.hasIrLocalDeclaration()) {
|
val descriptor = if (proto.hasIrLocalDeclaration()) {
|
||||||
val realDescriptor = proto.irLocalDeclaration.descriptor
|
val realDescriptor = proto.irLocalDeclaration.descriptor
|
||||||
deserializeLocalDeclaration(realDescriptor)
|
deserializeLocalDeclaration(proto, realDescriptor)
|
||||||
} else
|
} else
|
||||||
deserializeKnownDescriptor(proto)
|
deserializeKnownDescriptor(proto)
|
||||||
|
|
||||||
@@ -345,8 +345,7 @@ internal class IrDescriptorDeserializer(val context: Context,
|
|||||||
|
|
||||||
val originalIndex = descriptorProto.originalIndex
|
val originalIndex = descriptorProto.originalIndex
|
||||||
val match = functions.singleOrNull() {
|
val match = functions.singleOrNull() {
|
||||||
val proto = (it as DeserializedSimpleFunctionDescriptor).proto
|
it.uniqId == originalIndex
|
||||||
proto.functionIndex == originalIndex
|
|
||||||
} as? DeserializedSimpleFunctionDescriptor
|
} as? DeserializedSimpleFunctionDescriptor
|
||||||
if (match != null) return match
|
if (match != null) return match
|
||||||
|
|
||||||
@@ -370,8 +369,7 @@ internal class IrDescriptorDeserializer(val context: Context,
|
|||||||
|
|
||||||
val originalIndex = descriptorProto.originalIndex
|
val originalIndex = descriptorProto.originalIndex
|
||||||
return constructors.single {
|
return constructors.single {
|
||||||
val proto = (it as DeserializedClassConstructorDescriptor).proto
|
it.uniqId == originalIndex
|
||||||
proto.constructorIndex == originalIndex
|
|
||||||
} as DeserializedClassConstructorDescriptor
|
} as DeserializedClassConstructorDescriptor
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -389,7 +387,7 @@ internal class IrDescriptorDeserializer(val context: Context,
|
|||||||
val originalIndex = proto.originalIndex
|
val originalIndex = proto.originalIndex
|
||||||
return functions.single {
|
return functions.single {
|
||||||
val property = (it as PropertyAccessorDescriptor).correspondingProperty as DeserializedPropertyDescriptor
|
val property = (it as PropertyAccessorDescriptor).correspondingProperty as DeserializedPropertyDescriptor
|
||||||
property.proto.propertyIndex == originalIndex
|
property.uniqId == originalIndex
|
||||||
} as PropertyAccessorDescriptor
|
} as PropertyAccessorDescriptor
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+4
@@ -37,6 +37,10 @@ message KotlinDescriptor {
|
|||||||
optional LocalDeclaration ir_local_declaration = 12;
|
optional LocalDeclaration ir_local_declaration = 12;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
message UniqId {
|
||||||
|
required int64 index = 1;
|
||||||
|
}
|
||||||
|
|
||||||
message LocalDeclaration {
|
message LocalDeclaration {
|
||||||
// This is Descriptor message from KonanLinkData
|
// This is Descriptor message from KonanLinkData
|
||||||
required Descriptor descriptor = 1;
|
required Descriptor descriptor = 1;
|
||||||
|
|||||||
-10
@@ -15,35 +15,27 @@ option optimize_for = LITE_RUNTIME;
|
|||||||
|
|
||||||
// Konan extensions to the "descriptors" protobuf.
|
// Konan extensions to the "descriptors" protobuf.
|
||||||
|
|
||||||
message UniqId {
|
|
||||||
required int64 index = 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
extend Package {
|
extend Package {
|
||||||
optional int32 package_fq_name = 171;
|
optional int32 package_fq_name = 171;
|
||||||
}
|
}
|
||||||
|
|
||||||
extend Class {
|
extend Class {
|
||||||
repeated Annotation class_annotation = 170;
|
repeated Annotation class_annotation = 170;
|
||||||
optional UniqId class_index = 171;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
extend Constructor {
|
extend Constructor {
|
||||||
repeated Annotation constructor_annotation = 170;
|
repeated Annotation constructor_annotation = 170;
|
||||||
optional UniqId constructor_index = 171;
|
|
||||||
optional int32 constructor_parent = 172;
|
optional int32 constructor_parent = 172;
|
||||||
}
|
}
|
||||||
|
|
||||||
extend Function {
|
extend Function {
|
||||||
repeated Annotation function_annotation = 170;
|
repeated Annotation function_annotation = 170;
|
||||||
optional UniqId function_index = 171;
|
|
||||||
optional int32 function_parent = 172;
|
optional int32 function_parent = 172;
|
||||||
optional InlineIrBody inline_ir_body = 174;
|
optional InlineIrBody inline_ir_body = 174;
|
||||||
}
|
}
|
||||||
|
|
||||||
extend Property {
|
extend Property {
|
||||||
repeated Annotation property_annotation = 170;
|
repeated Annotation property_annotation = 170;
|
||||||
optional UniqId property_index = 171;
|
|
||||||
optional int32 property_parent = 172;
|
optional int32 property_parent = 172;
|
||||||
optional bool used_as_variable = 173;
|
optional bool used_as_variable = 173;
|
||||||
optional Annotation.Argument.Value compile_time_value = 174;
|
optional Annotation.Argument.Value compile_time_value = 174;
|
||||||
@@ -53,7 +45,6 @@ extend Property {
|
|||||||
|
|
||||||
extend EnumEntry {
|
extend EnumEntry {
|
||||||
repeated Annotation enum_entry_annotation = 170;
|
repeated Annotation enum_entry_annotation = 170;
|
||||||
optional UniqId enum_entry_index = 171;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
extend ValueParameter {
|
extend ValueParameter {
|
||||||
@@ -62,7 +53,6 @@ extend ValueParameter {
|
|||||||
|
|
||||||
extend Type {
|
extend Type {
|
||||||
repeated Annotation type_annotation = 170;
|
repeated Annotation type_annotation = 170;
|
||||||
optional UniqId type_index = 171;
|
|
||||||
optional string type_text = 172; // TODO: remove me
|
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) {
|
override fun serializeConstructor(descriptor: ConstructorDescriptor, proto: ProtoBuf.Constructor.Builder) {
|
||||||
|
|
||||||
proto.setConstructorIndex(
|
|
||||||
inlineDescriptorTable.indexByValue(descriptor))
|
|
||||||
val parentIndex = descriptor.parentFqNameIndex()
|
val parentIndex = descriptor.parentFqNameIndex()
|
||||||
if (parentIndex != null) proto.setExtension(KonanLinkData.constructorParent, parentIndex)
|
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) {
|
override fun serializeClass(descriptor: ClassDescriptor, proto: ProtoBuf.Class.Builder) {
|
||||||
|
|
||||||
proto.setClassIndex(
|
|
||||||
inlineDescriptorTable.indexByValue(descriptor))
|
|
||||||
super.serializeClass(descriptor, proto)
|
super.serializeClass(descriptor, proto)
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun serializeFunction(descriptor: FunctionDescriptor, proto: ProtoBuf.Function.Builder) {
|
override fun serializeFunction(descriptor: FunctionDescriptor, proto: ProtoBuf.Function.Builder) {
|
||||||
|
|
||||||
proto.setFunctionIndex(
|
|
||||||
inlineDescriptorTable.indexByValue(descriptor))
|
|
||||||
val parentIndex = descriptor.parentFqNameIndex()
|
val parentIndex = descriptor.parentFqNameIndex()
|
||||||
if (parentIndex != null) proto.setExtension(KonanLinkData.functionParent, parentIndex)
|
if (parentIndex != null) proto.setExtension(KonanLinkData.functionParent, parentIndex)
|
||||||
super.serializeFunction(descriptor, proto)
|
super.serializeFunction(descriptor, proto)
|
||||||
@@ -102,12 +96,6 @@ internal class KonanSerializerExtension(val context: Context, val util: KonanSer
|
|||||||
val variable = originalVariables[descriptor]
|
val variable = originalVariables[descriptor]
|
||||||
if (variable != null) {
|
if (variable != null) {
|
||||||
proto.setExtension(KonanLinkData.usedAsVariable, true)
|
proto.setExtension(KonanLinkData.usedAsVariable, true)
|
||||||
proto.setPropertyIndex(
|
|
||||||
inlineDescriptorTable.indexByValue(variable))
|
|
||||||
|
|
||||||
} else {
|
|
||||||
proto.setPropertyIndex(
|
|
||||||
inlineDescriptorTable.indexByValue(descriptor))
|
|
||||||
}
|
}
|
||||||
|
|
||||||
super.serializeProperty(descriptor, proto)
|
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.serialization.ProtoBuf
|
||||||
import org.jetbrains.kotlin.protobuf.GeneratedMessageLite
|
import org.jetbrains.kotlin.protobuf.GeneratedMessageLite
|
||||||
|
|
||||||
fun newUniqId(index: Long): KonanLinkData.UniqId =
|
fun newUniqId(index: Long): KonanIr.UniqId =
|
||||||
KonanLinkData.UniqId.newBuilder().setIndex(index).build()
|
KonanIr.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))
|
|
||||||
|
|
||||||
// -----------------------------------------------------------
|
// -----------------------------------------------------------
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user