]> git.ipfire.org Git - thirdparty/sqlalchemy/sqlalchemy.git/commit
Add immutabledict C code
authorMike Bayer <mike_mp@zzzcomputing.com>
Fri, 22 May 2020 04:06:06 +0000 (00:06 -0400)
committerMike Bayer <mike_mp@zzzcomputing.com>
Sat, 23 May 2020 04:05:13 +0000 (00:05 -0400)
commitfcbd03e48af50e301e0dcbade75765a4d3e4999f
tree8a30c4b9811bb217430c6bafea040753729c80ae
parentd45657a2f5b880dc22dda2d1eb1687af5234a470
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
15 files changed:
lib/sqlalchemy/cextension/immutabledict.c [new file with mode: 0644]
lib/sqlalchemy/cextension/resultproxy.c
lib/sqlalchemy/cextension/utils.c
lib/sqlalchemy/dialects/mssql/base.py
lib/sqlalchemy/dialects/postgresql/psycopg2.py
lib/sqlalchemy/orm/query.py
lib/sqlalchemy/sql/schema.py
lib/sqlalchemy/util/__init__.py
lib/sqlalchemy/util/_collections.py
setup.py
test/base/test_utils.py
test/engine/test_execute.py
test/orm/test_options.py
test/orm/test_update_delete.py
test/sql/test_metadata.py