13 ms·
Interestingly, the native Python Postgres driver “Asyncpg” is faster than psycopg which is writhe in C.
by andrewstuart 3y ago
Interestingly, the native Python Postgres driver “Asyncpg” is faster than psycopg which is writhe in C.
- Chiron1991 3y agoThat's because psycopg adheres to the DBAPI standard (think of JDBC of the Python world). asyncpg deliberately ignores this standard for huge performance boosts.
- FreakLegion 3y agoAsyncpg isn't pure Python, if that's what you mean by native. It's a heavy user of Python's C API, which is why PyPy can't run it. But yes, Asyncpg does tend to be quite a bit faster than Psycopg2 in most cases.
- andrewstuart 3y agoOK I was wrong and stand corrected, asyncpg is not pure Python. asyncpg has these two C files and also uses Cython as far as I can see. https://github.com/MagicStack/asyncpg/blob/master/asyncpg/protocol/record/recordobj.c https://github.com/MagicStack/asyncpg/blob/master/asyncpg/pr... https://github.com/MagicStack/asyncpg/blob/master/asyncpg/protocol/record/recordobj.h https://github.com/MagicStack/asyncpg/blob/master/asyncpg/pr... If you are interested here is a post by the psycopg author about psycopg2 and 3 and performance versus asyncpg. https://www.varrazzo.com/blog/2020/05/19/a-trip-into-optimisation/ https://www.varrazzo.com/blog/2020/05/19/a-trip-into-optimis...
- mjoin 3y agowhat do you mean by 'native'? or, in other words, what makes psycopg non-native?