python-gino / gino

GINO Is Not ORM - a Python asyncio ORM on SQLAlchemy core.
https://python-gino.org/
Other
2.67k stars 150 forks source link

Optimize columns loading: lazy create row locator #797

Open Reskov opened 2 years ago

Reskov commented 2 years ago

Locator instance builds unnecessary query for each row when the model is loaded from a database, to my mind, it is better to create an instance of the locator/UpdateRequest lazily (only if some values are passed to the model)

Here are the results of the benchmarks for loading 20000 rows, from my previous PR

https://github.com/python-gino/gino/pull/786#issuecomment-865472758

before

CPU time: 0.55 s, Real time: 0.56 s

Single column loader
CPU time: 0.33 s, Real time: 0.33 s

Partial loader
CPU time: 0.45 s, Real time: 0.45 s

after

CPU time: 0.20 s, Real time: 0.20 s
Single column loader
CPU time: 0.04 s, Real time: 0.04 s
Partial loader
CPU time: 0.15 s, Real time: 0.15 s