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/elements.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/elements.py')
-rw-r--r-- | lib/sqlalchemy/sql/elements.py | 47 |
1 files changed, 37 insertions, 10 deletions
diff --git a/lib/sqlalchemy/sql/elements.py b/lib/sqlalchemy/sql/elements.py index eda31dc61..da7568330 100644 --- a/lib/sqlalchemy/sql/elements.py +++ b/lib/sqlalchemy/sql/elements.py @@ -198,12 +198,7 @@ class ClauseElement( _order_by_label_element = None - @property - def _cache_key_traversal(self): - try: - return self._traverse_internals - except AttributeError: - return NO_CACHE + _cache_key_traversal = None def _clone(self): """Create a shallow copy of this ClauseElement. @@ -1344,16 +1339,21 @@ class BindParameter(roles.InElementRole, ColumnElement): return c def _gen_cache_key(self, anon_map, bindparams): - if self in anon_map: - return (anon_map[self], self.__class__) + idself = id(self) + if idself in anon_map: + return (anon_map[idself], self.__class__) + else: + # inline of + # id_ = anon_map[idself] + anon_map[idself] = id_ = str(anon_map.index) + anon_map.index += 1 - id_ = anon_map[self] bindparams.append(self) return ( id_, self.__class__, - self.type._gen_cache_key, + self.type._static_cache_key, traversals._resolve_name_for_compare(self, self.key, anon_map), ) @@ -3239,6 +3239,33 @@ class BinaryExpression(ColumnElement): """ + def _gen_cache_key(self, anon_map, bindparams): + # inlined for performance + + idself = id(self) + + if idself in anon_map: + return (anon_map[idself], self.__class__) + else: + # inline of + # id_ = anon_map[idself] + anon_map[idself] = id_ = str(anon_map.index) + anon_map.index += 1 + + if self._cache_key_traversal is NO_CACHE: + anon_map[NO_CACHE] = True + return None + + result = (id_, self.__class__) + + return result + ( + ("left", self.left._gen_cache_key(anon_map, bindparams)), + ("right", self.right._gen_cache_key(anon_map, bindparams)), + ("operator", self.operator), + ("negate", self.negate), + ("modifiers", self.modifiers), + ) + def __init__( self, left, right, operator, type_=None, negate=None, modifiers=None ): |