-
-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Peformance on attribute access #4462
Copy link
Copy link
Closed
Labels
ormperformancewhere performance can be improved. add "bug" only if it's a performance degradationwhere performance can be improved. add "bug" only if it's a performance degradationquestionissue where a "fix" on the SQLAlchemy side is unlikely, hence more of a usage questionissue where a "fix" on the SQLAlchemy side is unlikely, hence more of a usage questionwontfix / out of scopesomething we decided we aren't doing, for whatever reasonsomething we decided we aren't doing, for whatever reason
Metadata
Metadata
Assignees
Labels
ormperformancewhere performance can be improved. add "bug" only if it's a performance degradationwhere performance can be improved. add "bug" only if it's a performance degradationquestionissue where a "fix" on the SQLAlchemy side is unlikely, hence more of a usage questionissue where a "fix" on the SQLAlchemy side is unlikely, hence more of a usage questionwontfix / out of scopesomething we decided we aren't doing, for whatever reasonsomething we decided we aren't doing, for whatever reason
Type
Fields
Give feedbackNo fields configured for issues without a type.
I have found that accessing object attributes on SQLAlchemy is very slow. For example
%timeit a1.id298 ns ± 5.14 ns per loop (mean ± std. dev. of 7 runs, 1000000 loops each)
%timeit b1.id31.1 ns ± 0.477 ns per loop (mean ± std. dev. of 7 runs, 10000000 loops each)
approx 10 times slower to lookup the value of an attribute. The difference is much less if I do this:
%timeit a1.__dict__['id']72.3 ns ± 15.8 ns per loop (mean ± std. dev. of 7 runs, 10000000 loops each)
In my actual code I'm getting an object from the db then making it transient to perform some intensive computations but this attribute access is really slowing everything down. Should I be doing something else to remove the object from sqlalchemy whilst I do these computations?
Thx