diff options
author | Mike Bayer <mike_mp@zzzcomputing.com> | 2022-03-16 12:37:20 -0400 |
---|---|---|
committer | Mike Bayer <mike_mp@zzzcomputing.com> | 2022-03-17 10:11:24 -0400 |
commit | 58666d32742dc050c2e48c48ab8f946561636e8b (patch) | |
tree | 3355054bc17aa3651aa3d50f7222b9d1f11ddcfe /lib/sqlalchemy | |
parent | 6acf5d2fca4a988a77481b82662174e8015a6b37 (diff) | |
download | sqlalchemy-58666d32742dc050c2e48c48ab8f946561636e8b.tar.gz |
remove intermediary _is_clone_of entries when cloning
Improvements in memory usage by the ORM, removing a significant set of
intermediary expression objects that are typically stored when a copy of an
expression object is created. These clones have been greatly reduced,
reducing the number of total expression objects stored in memory by
ORM mappings by about 30%.
note this change causes the tests to have a bit of a harder time with
GC, which we would assume is because mappings now have a lot more
garbage to clean up after mappers are configured. it remains
to be seen what the long term effects of this are.
Fixes: #7823
Change-Id: If8729747ffb9bf27e8974f069a994b5a823ee095
Diffstat (limited to 'lib/sqlalchemy')
-rw-r--r-- | lib/sqlalchemy/sql/elements.py | 3 | ||||
-rw-r--r-- | lib/sqlalchemy/sql/selectable.py | 3 |
2 files changed, 4 insertions, 2 deletions
diff --git a/lib/sqlalchemy/sql/elements.py b/lib/sqlalchemy/sql/elements.py index fdb3fc8bb..346a84ddf 100644 --- a/lib/sqlalchemy/sql/elements.py +++ b/lib/sqlalchemy/sql/elements.py @@ -357,7 +357,8 @@ class ClauseElement( # process leaves around a lot of remnants of the previous clause # typically in the form of column expressions still attached to the # old table. - c._is_clone_of = self + cc = self._is_clone_of + c._is_clone_of = cc if cc is not None else self return c diff --git a/lib/sqlalchemy/sql/selectable.py b/lib/sqlalchemy/sql/selectable.py index 0692483e9..e143d1476 100644 --- a/lib/sqlalchemy/sql/selectable.py +++ b/lib/sqlalchemy/sql/selectable.py @@ -4135,7 +4135,8 @@ class _MemoizedSelectEntities( def _clone(self, **kw): c = self.__class__.__new__(self.__class__) c.__dict__ = {k: v for k, v in self.__dict__.items()} - c._is_clone_of = self + + c._is_clone_of = self.__dict__.get("_is_clone_of", self) return c @classmethod |