You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
so for each item in the context, prefix_expansions is iterated twice and then grows.
This makes combining contexts very expensive - 124s for 24 calls (5.2s/call) in the linkml tests. 5.2s/call makes it not great for runtime use :(
Here's a very lazy fix that isn't great but it works - check for duplication only once when adding. it's not pretty bc i didn't want to disrupt the nested if/else in add_prefix, but would be simplified if that was flattened.
@dataclassclassContext:
_prefixes: Optional[List[str]] =None_prefixes_lower: Optional[List[str]] =None_namespaces: Optional[List[str]] =None_namespaces_lower: Optional[List[str]] =Nonedefadd_prefix(
self,
prefix: PREFIX,
namespace: NAMESPACE,
status: StatusType=StatusType.canonical,
preferred: bool=False,
):
# ...prefixes=self.prefixes(lower=True)
namespaces=self.namespaces(lower=True)
ifprefix.lower() inprefixes:
ifnamespace.lower() innamespaces:
return# status = StatusType.multi_aliaselse:
status=StatusType.prefix_aliasself._namespaces.append(namespace)
self._namespaces_lower.append(namespace.lower())
else:
self._prefixes.append(prefix)
self._prefixes_lower.append(prefix.lower())
ifnamespace.lower() innamespaces:
status=StatusType.namespace_aliaselse:
self._namespaces.append(namespace)
self._namespaces_lower.append(namespace.lower())
self.prefix_expansions.append(
PrefixExpansion(
context=self.name,
prefix=prefix,
namespace=namespace,
status=status,
)
)
defprefixes(self, lower=False) ->List[str]:
""" All unique prefixes in all prefix expansions. :param lower: if True, the prefix is normalized to lowercase. :return: """iflower:
ifself._prefixes_lowerisNone:
self._prefixes_lower=list({pe.prefix.lower() forpeinself.prefix_expansions})
returnself._prefixes_lowerelse:
ifself._prefixesisNone:
self._prefixes=list({pe.prefixforpeinself.prefix_expansions})
returnself._prefixesdefnamespaces(self, lower=False) ->List[str]:
""" All unique namespaces in all prefix expansions :param lower: if True, the namespace is normalized to lowercase. :return: """iflower:
ifself._namespaces_lowerisNone:
self._namespaces_lower=list({pe.namespace.lower() forpeinself.prefix_expansions})
returnself._namespaces_lowerelse:
ifself._namespacesisNone:
self._namespaces=list({pe.namespaceforpeinself.prefix_expansions})
returnself._namespaces
After changes no longer appears in profiling results bc takes no time.
The text was updated successfully, but these errors were encountered:
One last little perf thing before i quit for the night.
combine
callsadd_prefix
in a loop:prefixmaps/src/prefixmaps/datamodel/context.py
Line 158 in 82bfdbc
add_prefix
callsprefixes
andnamespaces
prefixmaps/src/prefixmaps/datamodel/context.py
Lines 195 to 197 in 82bfdbc
prefixes
andnamespaces
iterate overprefix_expansions
prefixmaps/src/prefixmaps/datamodel/context.py
Line 241 in 82bfdbc
add_prefix
appends toprefix_expansions
prefixmaps/src/prefixmaps/datamodel/context.py
Line 207 in 82bfdbc
so for each item in the context,
prefix_expansions
is iterated twice and then grows.This makes combining contexts very expensive - 124s for 24 calls (5.2s/call) in the linkml tests. 5.2s/call makes it not great for runtime use :(
Here's a very lazy fix that isn't great but it works - check for duplication only once when adding. it's not pretty bc i didn't want to disrupt the nested if/else in
add_prefix
, but would be simplified if that was flattened.After changes no longer appears in profiling results bc takes no time.
The text was updated successfully, but these errors were encountered: