diff options
author | Mike Bayer <mike_mp@zzzcomputing.com> | 2019-12-14 11:39:06 -0500 |
---|---|---|
committer | Mike Bayer <mike_mp@zzzcomputing.com> | 2019-12-14 14:28:01 -0500 |
commit | 89bf6d80a999eb31ee4a69b229b887fbfb2ed12a (patch) | |
tree | 745ee0e0b913642b7e2cff2025727825efde7f5a /lib/sqlalchemy/sql/annotation.py | |
parent | b63bf945fbb5eb1cc299fe9a5e0d92754626abd4 (diff) | |
download | sqlalchemy-89bf6d80a999eb31ee4a69b229b887fbfb2ed12a.tar.gz |
Traversal and clause generation performance improvements
Added one traversal test, callcounts have been brought from 29754 to
5173 so far.
Change-Id: I164e9831600709ee214c1379bb215fdad73b39aa
Diffstat (limited to 'lib/sqlalchemy/sql/annotation.py')
-rw-r--r-- | lib/sqlalchemy/sql/annotation.py | 37 |
1 files changed, 20 insertions, 17 deletions
diff --git a/lib/sqlalchemy/sql/annotation.py b/lib/sqlalchemy/sql/annotation.py index 0d995ec8a..9853cef2a 100644 --- a/lib/sqlalchemy/sql/annotation.py +++ b/lib/sqlalchemy/sql/annotation.py @@ -19,23 +19,26 @@ from .. import util class SupportsAnnotations(object): @util.memoized_property - def _annotation_traversals(self): - return [ - ( - key, - InternalTraversal.dp_has_cache_key - if isinstance(value, HasCacheKey) - else InternalTraversal.dp_plain_obj, - ) - for key, value in self._annotations.items() - ] + def _annotations_cache_key(self): + return ( + "_annotations", + tuple( + ( + key, + value._gen_cache_key(None, []) + if isinstance(value, HasCacheKey) + else value, + ) + for key, value in self._annotations.items() + ), + ) class SupportsCloneAnnotations(SupportsAnnotations): _annotations = util.immutabledict() _traverse_internals = [ - ("_annotations", InternalTraversal.dp_annotations_state) + ("_annotations_cache_key", InternalTraversal.dp_plain_obj) ] def _annotate(self, values): @@ -45,7 +48,7 @@ class SupportsCloneAnnotations(SupportsAnnotations): """ new = self._clone() new._annotations = new._annotations.union(values) - new.__dict__.pop("_annotation_traversals", None) + new.__dict__.pop("_annotations_cache_key", None) return new def _with_annotations(self, values): @@ -55,7 +58,7 @@ class SupportsCloneAnnotations(SupportsAnnotations): """ new = self._clone() new._annotations = util.immutabledict(values) - new.__dict__.pop("_annotation_traversals", None) + new.__dict__.pop("_annotations_cache_key", None) return new def _deannotate(self, values=None, clone=False): @@ -71,7 +74,7 @@ class SupportsCloneAnnotations(SupportsAnnotations): # the expression for a deep deannotation new = self._clone() new._annotations = {} - new.__dict__.pop("_annotation_traversals", None) + new.__dict__.pop("_annotations_cache_key", None) return new else: return self @@ -146,7 +149,7 @@ class Annotated(object): def __init__(self, element, values): self.__dict__ = element.__dict__.copy() - self.__dict__.pop("_annotation_traversals", None) + self.__dict__.pop("_annotations_cache_key", None) self.__element = element self._annotations = values self._hash = hash(element) @@ -159,7 +162,7 @@ class Annotated(object): def _with_annotations(self, values): clone = self.__class__.__new__(self.__class__) clone.__dict__ = self.__dict__.copy() - clone.__dict__.pop("_annotation_traversals", None) + clone.__dict__.pop("_annotations_cache_key", None) clone._annotations = values return clone @@ -305,7 +308,7 @@ def _new_annotation_type(cls, base_cls): if "_traverse_internals" in cls.__dict__: anno_cls._traverse_internals = list(cls._traverse_internals) + [ - ("_annotations", InternalTraversal.dp_annotations_state) + ("_annotations_cache_key", InternalTraversal.dp_plain_obj) ] return anno_cls |