Optimize deserialized scope members computation for non-existing names
Do not use memoized function if member with given name is not contained in the scope There are a lot of queries with names of non-existent functions, that leads to many effectively redundant Map nodes in MemoizedFunction and also cause additional computation that is worth to compute at once Also drop unused 'location' parameter
This commit is contained in:
+7
-7
@@ -251,19 +251,19 @@ class DeserializedClassDescriptor(
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun getNonDeclaredFunctionNames(location: LookupLocation): Set<Name> {
|
override fun getNonDeclaredFunctionNames(): Set<Name> {
|
||||||
return classDescriptor.typeConstructor.supertypes.flatMapTo(LinkedHashSet()) {
|
return classDescriptor.typeConstructor.supertypes.flatMapTo(LinkedHashSet()) {
|
||||||
it.memberScope.getContributedDescriptors().filterIsInstance<SimpleFunctionDescriptor>().map { it.name }
|
it.memberScope.getFunctionNames()
|
||||||
} + c.components.additionalClassPartsProvider.getFunctionsNames(this@DeserializedClassDescriptor)
|
}.apply { addAll(c.components.additionalClassPartsProvider.getFunctionsNames(this@DeserializedClassDescriptor)) }
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun getNonDeclaredVariableNames(location: LookupLocation): Set<Name> {
|
override fun getNonDeclaredVariableNames(): Set<Name> {
|
||||||
return classDescriptor.typeConstructor.supertypes.flatMapTo(LinkedHashSet()) {
|
return classDescriptor.typeConstructor.supertypes.flatMapTo(LinkedHashSet()) {
|
||||||
it.memberScope.getContributedDescriptors().filterIsInstance<PropertyDescriptor>().map { it.name }
|
it.memberScope.getVariableNames()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun getNonDeclaredTypeAliasNames(location: LookupLocation): Set<Name> {
|
override fun getNonDeclaredTypeAliasNames(): Set<Name> {
|
||||||
return classDescriptor.typeConstructor.supertypes.flatMapTo(LinkedHashSet()) {
|
return classDescriptor.typeConstructor.supertypes.flatMapTo(LinkedHashSet()) {
|
||||||
it.memberScope.getContributedDescriptors().filterIsInstance<TypeAliasDescriptor>().map { it.name }
|
it.memberScope.getContributedDescriptors().filterIsInstance<TypeAliasDescriptor>().map { it.name }
|
||||||
}
|
}
|
||||||
@@ -339,7 +339,7 @@ class DeserializedClassDescriptor(
|
|||||||
|
|
||||||
fun findEnumEntry(name: Name): ClassDescriptor? = enumEntryByName(name)
|
fun findEnumEntry(name: Name): ClassDescriptor? = enumEntryByName(name)
|
||||||
|
|
||||||
private fun computeEnumMemberNames(): Collection<Name> {
|
private fun computeEnumMemberNames(): Set<Name> {
|
||||||
// NOTE: order of enum entry members should be irrelevant
|
// NOTE: order of enum entry members should be irrelevant
|
||||||
// because enum entries are effectively invisible to user (as classes)
|
// because enum entries are effectively invisible to user (as classes)
|
||||||
val result = HashSet<Name>()
|
val result = HashSet<Name>()
|
||||||
|
|||||||
+28
-8
@@ -64,6 +64,17 @@ abstract class DeserializedMemberScope protected constructor(
|
|||||||
private val typeAliases =
|
private val typeAliases =
|
||||||
c.storageManager.createMemoizedFunction<Name, Collection<TypeAliasDescriptor>> { computeTypeAliases(it) }
|
c.storageManager.createMemoizedFunction<Name, Collection<TypeAliasDescriptor>> { computeTypeAliases(it) }
|
||||||
|
|
||||||
|
private val functionNamesLazy by c.storageManager.createLazyValue {
|
||||||
|
functionProtos.keys + getNonDeclaredFunctionNames()
|
||||||
|
}
|
||||||
|
|
||||||
|
private val variableNamesLazy by c.storageManager.createLazyValue {
|
||||||
|
propertyProtos.keys + getNonDeclaredVariableNames()
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun getFunctionNames() = functionNamesLazy
|
||||||
|
override fun getVariableNames() = variableNamesLazy
|
||||||
|
|
||||||
private inline fun <M : MessageLite> Collection<M>.groupByName(
|
private inline fun <M : MessageLite> Collection<M>.groupByName(
|
||||||
getNameIndex: (M) -> Int
|
getNameIndex: (M) -> Int
|
||||||
) = groupBy { c.nameResolver.getName(getNameIndex(it)) }
|
) = groupBy { c.nameResolver.getName(getNameIndex(it)) }
|
||||||
@@ -93,7 +104,10 @@ abstract class DeserializedMemberScope protected constructor(
|
|||||||
protected open fun computeNonDeclaredFunctions(name: Name, functions: MutableCollection<SimpleFunctionDescriptor>) {
|
protected open fun computeNonDeclaredFunctions(name: Name, functions: MutableCollection<SimpleFunctionDescriptor>) {
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun getContributedFunctions(name: Name, location: LookupLocation): Collection<SimpleFunctionDescriptor> = functions(name)
|
override fun getContributedFunctions(name: Name, location: LookupLocation): Collection<SimpleFunctionDescriptor> {
|
||||||
|
if (name !in getFunctionNames()) return emptyList()
|
||||||
|
return functions(name)
|
||||||
|
}
|
||||||
|
|
||||||
private fun computeProperties(name: Name) =
|
private fun computeProperties(name: Name) =
|
||||||
computeDescriptors(
|
computeDescriptors(
|
||||||
@@ -113,9 +127,15 @@ abstract class DeserializedMemberScope protected constructor(
|
|||||||
{ c.memberDeserializer.loadTypeAlias(it) },
|
{ c.memberDeserializer.loadTypeAlias(it) },
|
||||||
{ })
|
{ })
|
||||||
|
|
||||||
override fun getContributedVariables(name: Name, location: LookupLocation): Collection<PropertyDescriptor> = properties(name)
|
override fun getContributedVariables(name: Name, location: LookupLocation): Collection<PropertyDescriptor> {
|
||||||
|
if (name !in getVariableNames()) return emptyList()
|
||||||
|
return properties(name)
|
||||||
|
}
|
||||||
|
|
||||||
protected fun getContributedTypeAliases(name: Name): Collection<TypeAliasDescriptor> = typeAliases(name)
|
protected fun getContributedTypeAliases(name: Name): Collection<TypeAliasDescriptor> {
|
||||||
|
if (name !in typeAliasNames) return emptyList()
|
||||||
|
return typeAliases(name)
|
||||||
|
}
|
||||||
|
|
||||||
protected abstract fun addClassifierDescriptors(result: MutableCollection<DeclarationDescriptor>, nameFilter: (Name) -> Boolean)
|
protected abstract fun addClassifierDescriptors(result: MutableCollection<DeclarationDescriptor>, nameFilter: (Name) -> Boolean)
|
||||||
|
|
||||||
@@ -184,13 +204,13 @@ abstract class DeserializedMemberScope protected constructor(
|
|||||||
}
|
}
|
||||||
|
|
||||||
protected fun addNonDeclaredDescriptors(result: MutableCollection<DeclarationDescriptor>, location: LookupLocation) {
|
protected fun addNonDeclaredDescriptors(result: MutableCollection<DeclarationDescriptor>, location: LookupLocation) {
|
||||||
result.addAll(getNonDeclaredFunctionNames(location).flatMap { getContributedFunctions(it, location) })
|
result.addAll(getNonDeclaredFunctionNames().flatMap { getContributedFunctions(it, location) })
|
||||||
result.addAll(getNonDeclaredVariableNames(location).flatMap { getContributedVariables(it, location) })
|
result.addAll(getNonDeclaredVariableNames().flatMap { getContributedVariables(it, location) })
|
||||||
}
|
}
|
||||||
|
|
||||||
protected abstract fun getNonDeclaredFunctionNames(location: LookupLocation): Set<Name>
|
protected abstract fun getNonDeclaredFunctionNames(): Set<Name>
|
||||||
protected abstract fun getNonDeclaredVariableNames(location: LookupLocation): Set<Name>
|
protected abstract fun getNonDeclaredVariableNames(): Set<Name>
|
||||||
protected abstract fun getNonDeclaredTypeAliasNames(location: LookupLocation): Set<Name>
|
protected abstract fun getNonDeclaredTypeAliasNames(): Set<Name>
|
||||||
|
|
||||||
protected abstract fun addEnumEntryDescriptors(result: MutableCollection<DeclarationDescriptor>, nameFilter: (Name) -> Boolean)
|
protected abstract fun addEnumEntryDescriptors(result: MutableCollection<DeclarationDescriptor>, nameFilter: (Name) -> Boolean)
|
||||||
|
|
||||||
|
|||||||
+3
-3
@@ -72,9 +72,9 @@ open class DeserializedPackageMemberScope(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun getNonDeclaredFunctionNames(location: LookupLocation): Set<Name> = emptySet()
|
override fun getNonDeclaredFunctionNames(): Set<Name> = emptySet()
|
||||||
override fun getNonDeclaredVariableNames(location: LookupLocation): Set<Name> = emptySet()
|
override fun getNonDeclaredVariableNames(): Set<Name> = emptySet()
|
||||||
override fun getNonDeclaredTypeAliasNames(location: LookupLocation): Set<Name> = emptySet()
|
override fun getNonDeclaredTypeAliasNames(): Set<Name> = emptySet()
|
||||||
|
|
||||||
override fun addEnumEntryDescriptors(result: MutableCollection<DeclarationDescriptor>, nameFilter: (Name) -> Boolean) {
|
override fun addEnumEntryDescriptors(result: MutableCollection<DeclarationDescriptor>, nameFilter: (Name) -> Boolean) {
|
||||||
// Do nothing
|
// Do nothing
|
||||||
|
|||||||
Reference in New Issue
Block a user