summaryrefslogtreecommitdiff
path: root/lib/sqlalchemy/orm/query.py
diff options
context:
space:
mode:
authorMike Bayer <mike_mp@zzzcomputing.com>2020-05-22 00:06:06 -0400
committerMike Bayer <mike_mp@zzzcomputing.com>2020-05-23 00:05:13 -0400
commitfcbd03e48af50e301e0dcbade75765a4d3e4999f (patch)
tree8a30c4b9811bb217430c6bafea040753729c80ae /lib/sqlalchemy/orm/query.py
parentd45657a2f5b880dc22dda2d1eb1687af5234a470 (diff)
downloadsqlalchemy-fcbd03e48af50e301e0dcbade75765a4d3e4999f.tar.gz
Add immutabledict C code
Start trying to convert fundamental objects to C as we now rely on a fairly small core of things, and 1.4 is having problems with complexity added being slower than the performance gains we are trying to build in. immutabledict here does seem to bench as twice as fast as the Python one, see below. However, it does not appear to be used prominently enough to make any dent in the performance tests. at the very least it may provide us some more lift-and-copy code for more C extensions. import timeit from sqlalchemy.util._collections import not_immutabledict, immutabledict def run(dict_cls): for i in range(1000000): d1 = dict_cls({"x": 5, "y": 4}) d2 = d1.union({"x": 17, "new key": "some other value"}, None) assert list(d2) == ["x", "y", "new key"] print( timeit.timeit( "run(d)", "from __main__ import run, not_immutabledict as d", number=1 ) ) print( timeit.timeit( "run(d)", "from __main__ import run, immutabledict as d", number=1 ) ) output: python: 1.8799766399897635 C code: 0.8880784640205093 Change-Id: I29e7104dc21dcc7cdf895bf274003af2e219bf6d
Diffstat (limited to 'lib/sqlalchemy/orm/query.py')
-rw-r--r--lib/sqlalchemy/orm/query.py8
1 files changed, 4 insertions, 4 deletions
diff --git a/lib/sqlalchemy/orm/query.py b/lib/sqlalchemy/orm/query.py
index 70b8a71e3..7f910afed 100644
--- a/lib/sqlalchemy/orm/query.py
+++ b/lib/sqlalchemy/orm/query.py
@@ -1551,7 +1551,7 @@ class Query(Generative):
def _options(self, conditional, *args):
# most MapperOptions write to the '_attributes' dictionary,
# so copy that as well
- self._attributes = self._attributes.copy()
+ self._attributes = dict(self._attributes)
if "_unbound_load_dedupes" not in self._attributes:
self._attributes["_unbound_load_dedupes"] = set()
opts = tuple(util.flatten_iterator(args))
@@ -1720,7 +1720,7 @@ class Query(Generative):
"params() takes zero or one positional argument, "
"which is a dictionary."
)
- self._params = self._params.copy()
+ self._params = dict(self._params)
self._params.update(kwargs)
@_generative
@@ -2277,7 +2277,7 @@ class Query(Generative):
# dict, so that no existing dict in the path is mutated
while "prev" in jp:
f, prev = jp["prev"]
- prev = prev.copy()
+ prev = dict(prev)
prev[f] = jp.copy()
jp["prev"] = (f, prev)
jp = prev
@@ -4831,7 +4831,7 @@ class QueryContext(object):
self.propagate_options = set(
o for o in query._with_options if o.propagate_to_loaders
)
- self.attributes = query._attributes.copy()
+ self.attributes = dict(query._attributes)
if self.refresh_state is not None:
self.identity_token = query._refresh_identity_token
else: