Re: [sqlalchemy] Slow entities pickling for caching purposes

2019-10-11 Thread Alexander Egorov
I've considered manual queries and building classes by myself. This option is good in terms of performance, but it requires a lot of code duplication and kills code reuse. So I want to use the same mapper classes for both read and modify operations. Also, I want to have the same query

Re: [sqlalchemy] Slow entities pickling for caching purposes

2019-10-11 Thread Mike Bayer
On Fri, Oct 11, 2019, at 5:23 AM, Александр Егоров wrote: > Thank you very much for your answers! > > Some more questions > 1) I see you use sa.inspect(self).dict in __getstate__. Is it safe to replace > it with self.__dict__? I didn't find any difference in the result, but > __dict__ works

Re: [sqlalchemy] Slow entities pickling for caching purposes

2019-10-11 Thread Александр Егоров
Thank you very much for your answers! Some more questions 1) I see you use sa.inspect(self).dict in __getstate__. Is it safe to replace it with self.__dict__? I didn't find any difference in the result, but __dict__ works 30 times faster. 2) I'm going to implement __getstate__ and __setstate__

Re: [sqlalchemy] Slow entities pickling for caching purposes

2019-10-10 Thread Mike Bayer
On Thu, Oct 10, 2019, at 2:48 AM, Александр Егоров wrote: > Hello! > > I want to cache query results in a distributed cache (Redis), so I need to > serialize/deserialize fetched entities very fast. > However, it turned that SQLAlchemy entities are very heavy for pickle to > dump/load. Regular